(十六)MySQL集群galera实现

Posted 你很棒

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了(十六)MySQL集群galera实现相关的知识,希望对你有一定的参考价值。

(1)环境介绍

galera官网:http://galeracluster.com/downloads/
# cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 

(2)以下配置三台服务器都相同

  • 关闭防火墙和selinux
systemctl disable firewalld 
systemctl stop firewalld
sed -ri \'/SELINUX=/cSELINUX=disabled\' /etc/selinux/config
setenforce 0
  • 配置yum源
cat >>/etc/yum.repos.d/galera.repo<<EOF
[galera1]
name=galera1
baseurl=http://releases.galeracluster.com/mysql-wsrep-5.7/centos/7/x86_64/
gpgcheck=0
[galera2]
name=galera2
baseurl=http://releases.galeracluster.com/galera-3/centos/7/x86_64/
gpgcheck=0
EOF
  • 安装mysql和galera插件
yum repolist
yum list | egrep "wsrep|galera"
yum -y install mysql-wsrep-server-5.7.x86_64  rsync galera-3.x86_64 -y
  • 启动mysqld
systemctl start mysqld
systemctl enable mysqld
newpass=$(grep "temporary password" /var/log/mysqld.log | awk \'{print $NF}\')
mysqladmin -uroot -p"$newpass" password \'Redhat@123\'
  • 创建用于数据同步的用户
mysql -uroot -pRedhat@123 -e "grant all on *.* to \'copy\'@\'192.168.1.%\' identified by \'Copy@123\'"
mysql -uroot -pRedhat@123 -e "flush privileges;"

(3)修改配置文件:三台不一样

  • node1:192.168.1.31
#vi /etc/my.cnf
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
wsrep_cluster_address="gcomm://"
wsrep_cluster_name="test"
wsrep_node_address="192.168.1.31"
wsrep_node_name="node1"
wsrep_sst_auth=copy:Copy@123
wsrep_sst_method=rsync
重启mysqld服务器:systemctl restart mysqld
验证端口状态:ss -anltup | egrep "3306|4567"

node1节点上查看状态

  • node2:192.168.1.32
#vi /etc/my.cnf
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.1.31,192.168.1.32,192.168.1.33"
wsrep_cluster_name="test"
wsrep_node_address="192.168.1.32"
wsrep_node_name="node2"
wsrep_sst_auth=copy:Copy@123
wsrep_sst_method=rsync
重启mysqld服务器:systemctl restart mysqld
验证端口状态:ss -anltup | egrep "3306|4567"
  • node3:192.168.1.33
#vi /etc/my.cnf
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.1.31,192.168.1.32,192.168.1.33"
wsrep_cluster_name="test"
wsrep_node_address="192.168.1.33"
wsrep_node_name="node3"
wsrep_sst_auth=copy:Copy@123
wsrep_sst_method=rsync
重启mysqld服务器:systemctl restart mysqld
验证端口状态:ss -anltup | egrep "3306|4567"


注意:node定义刚开始定义集群是wsrep_cluster_address="gcomm://",如果node1重启Mysql服务,
这个地址需要修改wsrep_cluster_address="gcomm://192.168.1.33,192.168.1.32,192.168.1.31"

  • 参数解释
    wsrep_incoming_addresses :表示集群主机ip
    wsrep_cluster_size :集群主机统计数量
    wsrep_connected :连接状态

以上是关于(十六)MySQL集群galera实现的主要内容,如果未能解决你的问题,请参考以下文章

mysql借助Galera Cluster构建多主集群

MySQL之galera集群部署

galera mariadb集群恢复策略

MySQL集群之Galera Cluster

mysql galera 集群

超详细,多图文使用galera cluster搭建mysql集群并介绍wsrep相关参数