MySQL Group Replication(MGR集群)增加节点和迁移节点

MySQL Group Replication 多主结构的3节点需要切到另外三个节点上,任务需要先加3个节点到集群中,再删掉原来的3个节点。

环境

修改host

- 修改6台主机的/etc/hosts
172.0.2.30  dba-mysql3309-230 dba-mysql3309-230.dboop.com
172.0.2.31  dba-mysql3309-231 dba-mysql3309-231.dboop.com
172.0.2.32  dba-mysql3309-232 dba-mysql3309-232.dboop.com
172.0.2.83  dba-mysql3309-83 dba-mysql3309-83.dboop.com
172.0.2.84  dba-mysql3309-84 dba-mysql3309-84.dboop.com
172.0.2.85  dba-mysql3309-85 dba-mysql3309-85.dboop.com

旧实例上增加seed

mysqlw -h 172.0.2.30 -P 3309 -e  "show global variables like 'group_replication_group_seeds'";
mysqlw -h 172.0.2.31 -P 3309 -e  "show global variables like 'group_replication_group_seeds'";
mysqlw -h 172.0.2.32 -P 3309 -e  "show global variables like 'group_replication_group_seeds'";
mysqlw -h 172.0.2.30 -P 3309 -e  " SELECT * FROM performance_schema.replication_group_members ";
mysqlw -h 172.0.2.31 -P 3309 -e  " SELECT * FROM performance_schema.replication_group_members ";
mysqlw -h 172.0.2.32 -P 3309 -e  " SELECT * FROM performance_schema.replication_group_members ";
mysqlw -h 172.0.2.30 -P 3309 -e "set global group_replication_group_seeds='172.0.2.30:33095,172.0.2.31:33095,172.0.2.32:33095,172.0.2.83:33095,172.0.2.84:33095,172.0.2.85:33095'"
mysqlw -h 172.0.2.31 -P 3309 -e "set global group_replication_group_seeds='172.0.2.30:33095,172.0.2.31:33095,172.0.2.32:33095,172.0.2.83:33095,172.0.2.84:33095,172.0.2.85:33095'"
mysqlw -h 172.0.2.32 -P 3309 -e "set global group_replication_group_seeds='172.0.2.30:33095,172.0.2.31:33095,172.0.2.32:33095,172.0.2.83:33095,172.0.2.84:33095,172.0.2.85:33095'"
mysqlw -h 172.0.2.30 -P 3309 -e  "show global variables like 'group_replication_group_seeds'";
mysqlw -h 172.0.2.31 -P 3309 -e  "show global variables like 'group_replication_group_seeds'";
mysqlw -h 172.0.2.32 -P 3309 -e  "show global variables like 'group_replication_group_seeds'";

加入新节点1(2.84)

安装插件

mysqlw -h 172.0.2.84 -P 3309 -e "show plugins" |grep "group_replication" #检查是否安装
mysqlw -h 172.0.2.84 -P 3309 -e "install plugin group_replication soname 'group_replication.so'";
mysqlw -h 172.0.2.84 -P 3309 -e "show plugins" |grep "group_replication" 

修改配置文件:

#add group replic
relay_log = relay
binlog_checksum = NONE
master_info_repository = table
relay_log_info_repository = table
slave_parallel_type = LOGICAL_CLOCK
slave_parallel_workers = 8
slave_preserve_commit_order = 1
transaction_write_set_extraction = XXHASH64
plugin_load_add = 'group_replication.so'
group_replication_unreachable_majority_timeout=10
group_replication_exit_state_action = offline_mode
loose-group_replication_group_name = "e0dbceb7-f505-11eb-91ee-e43d1a075b40"
loose-group_replication_start_on_boot = 0
loose-group_replication_local_address = "172.0.2.84:33095"
loose-group_replication_group_seeds = "172.0.2.30:33095,172.0.2.31:33095,172.0.2.32:33095,172.0.2.83:33095,172.0.2.84:33095,172.0.2.85:33095"
loose-group_replication_bootstrap_group = 0
#mutli master
loose-group_replication_single_primary_mode=0  
loose-group_replication_enforce_update_everywhere_checks=1  

停原主从复制

mysqlw -h 172.0.2.84 -P 3309 -e "show slave status \G"
mysqlw -h 172.0.2.84 -P 3309 -e "stop slave "
mysqlw -h 172.0.2.84 -P 3309 -e "reset slave all"
mysqlw -h 172.0.2.84 -P 3309 -e "show slave status \G"

重启实例

service mysqld3309 restart

新节点加入

mysqlw -h 172.0.2.84 -P 3309 -e "start GROUP_REPLICATION USER='repl2', PASSWORD='repl.dba6'"
mysqlw -h 172.0.2.84 -P 3309 -e " SELECT * FROM performance_schema.replication_group_members ";
mysqlw -h 172.0.2.84 -P 3309 -e  "SELECT * FROM performance_schema.replication_connection_status \G";
mysqlw -h 172.0.2.30 -P 3309 -e  " SELECT * FROM performance_schema.replication_group_members ";
mysqlw -h 172.0.2.31 -P 3309 -e  " SELECT * FROM performance_schema.replication_group_members ";
mysqlw -h 172.0.2.32 -P 3309 -e  " SELECT * FROM performance_schema.replication_group_members ";


mysqlw -h 172.0.2.30 -P 3309 -e "show processlist"
mysqlw -h 172.0.2.31 -P 3309 -e "show processlist"
mysqlw -h 172.0.2.32 -P 3309 -e "show processlist"

继续添加节点(如果不是立即切换和迁移,请保证集群中的节点数为奇数)

….

删除节点(2.32)

mysqlw -h 172.0.2.30 -P 3309 -e "set global group_replication_group_seeds='172.0.2.30:33095,172.0.2.31:33095,172.0.2.83:33095,172.0.2.84:33095,172.0.2.85:33095'"
mysqlw -h 172.0.2.31 -P 3309 -e "set global group_replication_group_seeds='172.0.2.30:33095,172.0.2.31:33095,172.0.2.83:33095,172.0.2.84:33095,172.0.2.85:33095'"
mysqlw -h 172.0.2.32 -P 3309 -e "set global group_replication_group_seeds='172.0.2.30:33095,172.0.2.31:33095,172.0.2.83:33095,172.0.2.84:33095,172.0.2.85:33095'"
mysqlw -h 172.0.2.83 -P 3309 -e "set global group_replication_group_seeds='172.0.2.30:33095,172.0.2.31:33095,172.0.2.83:33095,172.0.2.84:33095,172.0.2.85:33095'"
mysqlw -h 172.0.2.84 -P 3309 -e "set global group_replication_group_seeds='172.0.2.30:33095,172.0.2.31:33095,172.0.2.83:33095,172.0.2.84:33095,172.0.2.85:33095'"
mysqlw -h 172.0.2.85 -P 3309 -e "set global group_replication_group_seeds='172.0.2.30:33095,172.0.2.31:33095,172.0.2.83:33095,172.0.2.84:33095,172.0.2.85:33095'"
mysqlw -h 172.0.2.32 -P 3309 -e "stop GROUP_REPLICATION"

mysqlw -h 172.0.2.30 -P 3309 -e  " SELECT * FROM performance_schema.replication_group_members ";
mysqlw -h 172.0.2.31 -P 3309 -e  " SELECT * FROM performance_schema.replication_group_members ";
mysqlw -h 172.0.2.32 -P 3309 -e  " SELECT * FROM performance_schema.replication_group_members ";


mysqlw -h 172.0.2.30 -P 3309 -e "show processlist"
mysqlw -h 172.0.2.31 -P 3309 -e "show processlist"
mysqlw -h 172.0.2.32 -P 3309 -e "show processlist"
>> Home

51ak

2023/04/06

Categories: mysql mysql复制 高可用 proxy Tags: 原创

《数据库工作笔记》公众号
扫描上面的二维码,关注我的《数据库工作笔记》公众号