mysql galera HA

MariaDB+gelera  HA

环境信息

centos 7.2.1511

版本信息

MariaDB 10.1.19-client

MariaDB 10.1.19-common

MariaDB 10.1.19-server

安装mariadb

yum install MariaDB-serverMariaDB-client

测试mysql是否正常

Service mysql start

Service mysql stop

创建mysql数据存放目录并授权

mkdir -p  /data

chown -R mysql.mysql /data

删除存在的数据库文件

rm -rf /var/lib/mysql/*

修改/etc/my.cnf

[mysqld]

binlog_format=ROW

bind-address = 172.16.16.1

collation-server = utf8_general_ci

character-set-server = utf8

default_storage_engine=innodb

datadir = /data

max_connections = 4096

pid-file = /data/mysql/mysql.pid

query_cache_size=0

socket = /tmp/mysql.sock

#*Innodb setting

#

innodb_file_per_table

innodb_autoinc_lock_mode=2

innodb_flush_log_at_trx_commit=0

innodb_buffer_pool_size=256M

初始化数据库

mysql_install_db

重新启动数据库

service mysql start

创建链接文件

ln -s /tmp/mysql.sock /var/lib/mysql/

安全安装

mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THISSCRIPT IS RECOMMENDED FOR ALL MariaDB

SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB tosecure it, we‘ll need the current

password for the root user.  If you‘ve just installed MariaDB, and

you haven‘t set the root passwordyet, the password will be blank,

so you should just press enterhere.

Enter current password for root(enter for none):

OK, successfully used password,moving on...

Setting the root password ensuresthat nobody can log into the MariaDB

root user without the properauthorisation.

Set root password? [Y/n] Y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

... Success!

By default, a MariaDB installationhas an anonymous user, allowing anyone

to log into MariaDB without havingto have a user account created for

them.  This is intended only for testing, and tomake the installation

go a bit smoother.  You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] Y

... Success!

Normally, root should only beallowed to connect from ‘localhost‘. This

ensures that someone cannot guess atthe root password from the network.

Disallow root login remotely?[Y/n] n

... skipping.

By default, MariaDB comes with adatabase named ‘test‘ that anyone can

access.  This is also intended only for testing, andshould be removed

before moving into a productionenvironment.

Remove test database and access toit? [Y/n] y

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!

Reloading the privilege tableswill ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n]y

... Success!

Cleaning up...

All done!  If you‘ve completed all of the above steps,your MariaDB

installation should now be secure.

Thanks for using MariaDB!

创建同步用户

grant all privileges on *.* to ‘wsrep_user‘@‘controller2‘ identified by‘wsreppasswd‘;

flush privileges;

更新gelera下wsrep信息

编辑/etc/my.cnf.d/server.cnf

[galera]

wsrep_on=ON

wsrep_provider=/usr/lib64/galera/libgalera_smm.so

wsrep_cluster_address=gcomm://

wsrep_cluster_name=‘dbcluster‘

wsrep_node_address=‘172.16.16.1‘

wsrep_sst_method=rsync

#wsrep_sst_method=xtrabackup

wsrep_sst_auth=wsrep_user:wsreppasswd

wsrep_node_name=‘HA-1‘

wsrep_node_address=172.16.16.1

wsrep_provider_options="pc.recovery=TRUE;gcache.size=300M"

此时没有同步对象,所以wsrep_cluster_address=gcomm://留空

启动节点

sudo -u mysql mysqld --wsrep-cluster-address=‘gcomm://‘

首先配置节点2

使用1的配置文件直接复制后,修改信息

[mysqld]

bind-address = 172.16.16.2

[gelera]

wsrep_cluster_address=gcomm://172.16.16.1

wsrep_node_address=‘172.16.16.2‘

wsrep_node_name=‘HA-2‘

wsrep_node_address=172.16.16.2

此时数据同步方向为2同步1

启动节点2上的服务

同步完成后

关闭节点1服务

service mysql stop

修改同步对象wsrep_cluster_address=gcomm://172.16.16.2

重启服务后,双向同步完成,验证服务

MariaDB

[(none)]>show global status like ‘wsrep_cluster%‘;

从此处可以看出当有其他节点加入到集群中时,wsrep_cluster_size可以反映出当前集群节点数量,wsrep_cluster_status可以判定当前节点属于primary还是slave

GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ WITH GRANT OPTION;

GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘‘ WITH GRANT OPTION;

mysqladmin flush-hosts -h172.16.16.1 -P3306 -uroot -pdftcpass

mysql -uroot -h172.16.16.10 -P3307 -pdftcpass

时间: 2024-08-07 08:18:09

mysql galera HA的相关文章

关于Oracle的rac集群和mysql Galera Cluster的想法

到了新公司,公司用的是rac,我比较熟悉mysql第三方的集群方案Galera Cluster这类多主集群, 下面是我参考了他人对rac的介绍,然后和mysql方案进行的臆测级别的分析对比. rac和mysql Galera Cluster(mgc)的对比, 1.实施和运维,rac是商业方案系统化性当然强点,mgc大多使用各种开源高可用负载均衡器,部署起来对实施人员的要求rac比较低,废话...rmb都给了甲骨文了,如果是自行配制弄得不好性能2台还不如一台,其实运维方面来说体量大了都一样: 2.

部署MySQL Galera Cluster

部署MySQL Galera Cluster 0.功能简介 特性 基于行复制的完全并行同步复制 实时多主架构,任意节点可读写 无延迟复制,事务零丢失,可靠健壮的读写体验. 自动化节点关系控制:节点故障自动摘除,节点加入自动协调 接近原生的MySQL数据库连接的体验 原理简析当一个事务在当前写入的节点提交后,通过wsrep API(write set replication API)将这个事务变成写集(write set)广播到同集群的其他节点中,其他节点收到写集事务后,对这个事务进行可行性检查,

mysql的HA及openstack和k8s区别

数据库HA(Hight Availability) mysql自身支持主主/主备部署,多主(>2),一主多备 galera mariadb集群:多主相互备份 修改容器的启动配置 修改Docker容器启动配置参数 docker container update --restart=always 容器名字 修改配置文件 停止容器 找到配置文件路径 /var/lib/docker/containers/容器ID 在该目录下找到一个文件 hostconfig.json 修改配置 启动容器. galera

转 移动云基于MySQL Galera的PXC运维实战

https://mp.weixin.qq.com/s/YTwdVRh_Uhtf3bn2MO2H_Q 作者介绍 刘书浩,“移动云”DBA,负责“移动云”业务系统的数据库运维.标准化等工作:擅长MySQL技术领域,熟悉MySQL复制结构.Cluster架构及运维优化:具有自动化运维经验,负责“移动云”数据库管理平台的搭建. 前言 在众多的MySQL开源软件中,Galera是非常有特色的,它的特点及优势是具有良好的并发性和一致性.Galera Cluster的主要用途是为MySQL提供一致性的集群化解

基于NFS共享的Mysql之HA高可用集群实现

192.168.139.8 作为NFS-Server ,192.168.139.2和192.168.13.4用来安装mysql ___________________________________________________________________________________________以下操作在192.168.139.8上操作 [[email protected] ~]# fdisk -l //首先要准备一块磁盘进行分区,用来做lv,再将此lv格式化后挂载并      

MYSQL GALERA部署实录

[[email protected] ~]# yum install bison bison-devel check check-devel boost boost-devel scons socat perl-DBD-MySQL [[email protected] ~]# rpm -ivh libev-4.15-1.el6.rf.x86_64.rpm [[email protected] ~]# rpm -ivh percona-xtrabackup-24-2.4.9-1.el6.x86_6

HA集群之DRBD实现MySQL高可用

一.前言 本篇博文只是实现Corosync + Pacemaker + DRBD + MySQL,实现MySQL的高可用.更多的基础知识在前几篇博文中已有涉猎,故更多的理论细节将不再此篇中详述. 若想了解高可用基础知识,请参考:http://hoolee.blog.51cto.com/7934938/1406951 若想了解Corosync + Pacemaker,请参考:http://hoolee.blog.51cto.com/7934938/1409395 若想了解DRBD,请参考:http

配置galera+nginx 实现 mariadb、mysql数据库多主模式

需求 .解决问题点: 1:现有的mysql数据主从模式,数据同步延迟: 2:mysql主从进程经常崩溃,数据找平困难: 3:数据库主从或者主主模式数据查询.写入慢: 4:mariadb或者mysql数据库 节点性能需要指数级提升: 5:mariadb或者mysql数据库对数据安全性有较高的要求: 6:项目要求数据库有横向扩展的能力: 7 :等等...... 一.MariaDB Galera Cluster概要: 1.简述: MariaDB Galera Cluster 是一套在mysql inn

[转]MySQL Multi Master replication with Galera

Galera is a synchronous multi-master cluster for MySQL/InnoDB databases. Some features and benefits of Galera are: Synchronous replication. Multi master topology. Read/Write to any cluster node. Automatic membership control. Data consistency between