架构
主:172.17.100.101
从①:172.17.100.103
从②:172.17.100.104
MySQL版本:5.7.22
MGR配置
修改每个节点下对应的配置文件my.cnf,增加如下配置
#MGR
server-id = 1 #主节点设置为1,从节点从2-9,此次实验为1主2从
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="3db33b36-0e51-409f-a61d-c99756e90155" #这个name必须是一个uuid的格式
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "172.17.100.101:23306" #每个节点此处为本机的IP及端口
loose-group_replication_group_seeds= "172.17.100.101:23306,172.17.100.103:23306,172.17.100.104:23306" #MGR组的所有IP及端口
loose-group_replication_bootstrap_group= off
loose-group_replication_single_primary_mode=true #单主模式必须设置
loose-group_replication_enforce_update_everywhere_checks=false #单主模式必须设置
第一节点(主节点)
SET SQL_LOG_BIN=0;
grant replication slave on *.* to rpl@'172.17.100.%' identified by 'beacon';
SET SQL_LOG_BIN=1;
change master to master_user='rpl',master_password='beacon' for channel 'group_replication_recovery';
install plugin group_replication soname 'group_replication.so';
set global group_replication_bootstrap_group=on;
start group_replication;
set global group_replication_bootstrap_group=off;
第二节点
SET SQL_LOG_BIN=0;
grant replication slave on *.* to rpl@'172.17.100.%' identified by 'beacon';
SET SQL_LOG_BIN=1;
change master to master_user='rpl',master_password='beacon' for channel 'group_replication_recovery';
install plugin group_replication soname 'group_replication.so';
set global group_replication_allow_local_disjoint_gtids_join=ON;
start group_replication;
第三节点
SET SQL_LOG_BIN=0;
grant replication slave on *.* to rpl@'172.17.100.%' identified by 'beacon';
SET SQL_LOG_BIN=1;
change master to master_user='rpl',master_password='beacon' for channel 'group_replication_recovery';
install plugin group_replication soname 'group_replication.so';
set global group_replication_allow_local_disjoint_gtids_join=ON;
start group_replication;
MGR相关信息检测
#查询组成员
select * from performance_schema.replication_group_members;
#查询主节点
select variable_value from performance_schema.global_status where variable_name='group_replication_primary_member';
搭建中遇到的报错
1.[ERROR] Plugin group_replication reported: '[GCS] Error on opening a connection to 172.17.100.103:23306 on local port: 23306.'
这个报错是主节点执行start group_replication时发生的
重新执行set global group_replication_bootstrap_group=on;
之后再次start可以正常启动
实际上之前我已经执行过set global group_replication_bootstrap_group=on这个语句了,为什么会出现这个报错,有点懵比,总之重新执行后解决该问题。
2.[ERROR] Plugin group_replication reported: 'This member has more executed transactions than those present in the group. Local transactions: ce088f8c-8e5b-11e8-9c42-005056ba04d1:1-2 > Group transactions: 3db33b36-0e51-409f-a61d-c99756e90155:1-2,
这个报错是在第二节点执行start的时候产生的,根本原因是因为第二节点没有执行join语句
执行set global group_replication_allow_local_disjoint_gtids_join=ON;
完成上述语句的执行之后,再次start,即可成功执行
3.主从库皆可执行写操作,下列语句执行后,结果为空
select variable_value from performance_schema.global_status where variable_name='group_replication_primary_member';
检查参数中的下列2行是否配置正确
在配置相反的情况下,搭建的MGR为多主
MGR切换测试
主节点执行关闭数据库
从节点执行相关检测
重新启动之前的主节点,并执行start GR,将主节点加入到MGR组内,可以发现主节点已经变更为之前的从节点