(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 :连接状态