环境
192.168.139.151 新增节点
192.168.139.148-150 集群节点
192.168.139.151 已经安装好PXC软件
计划:
选用192.168.139.150 节点先与192.168.139.151组成主从节点
再转成集群节点
构建主从环境
150 节点创建主从同步账号:
mysql>create user 'bak'@'192.168.139.%' identified by '123456';
mysql>grant replication slave on *.* to 'bak'@'192.168.139.%';
mysql>flush privileges;
150数据拷贝至151上
#mysqldump --single-transaction -uroot -p123456 -A --master-data=2 > all.sql
#scp all.sql [email protected]:/opt/
151上恢复数据
mysql>SET GLOBAL pxc_strict_mode=PERMISSIVE;
#mysql -u root -p123456 < all.sql
151配置主从同步
#####master_log 信息可在150 使用flsuh logs ; show master status查看
change master to master_host='192.168.139.150',master_user='bak',master_password='123456',master_log_file='pxc-bin.000001',master_log_pos=928;
151开启同步
start slave;
show slave status\G;
151配置集群
systemctl stop mysql
vim /etc/my.cnf ===>注意文件下面的include ,配置文件可能在指定路径中,my.cnf只是类似于软链
server-id=4 #与集群中其他的节点不一样
# Path to Galera library
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
#If no IP is found, this implies that a new cluster needs to be created,
#in order to do that you need to bootstrap this node
wsrep_cluster_address=gcomm://192.168.139.148,192.168.139.149,192.168.139.150,192.168.139.151
binlog_format=ROW
default_storage_engine=InnoDB
wsrep_slave_threads= 8
innodb_autoinc_lock_mode=2
wsrep_node_address=192.168.139.151
# Cluster name
wsrep_cluster_name=pxc-cluster
wsrep_node_name=pxc-cluster-node-4
pxc_strict_mode=ENFORCING
wsrep_sst_method=xtrabackup-v2
srep_sst_auth="sstuser:passw0rd"
150检查PXC需要同步位置
mysqlbinlog -v -v mysql-bin.000001 | grep Xid ===》找到position 对应的,没有 就在MySQL中的表随便插入什么东西,执行commit ,在查询
scp /var/lib/mysql/grastate.dat [email protected]:/var/lib/mysql/
151编辑文件
151查看测试结果: