架構(gòu)
主:172.17.100.101
從①:172.17.100.103
從②:172.17.100.104
MySQL版本:5.7.22
MGR配置
修改每個(gè)節(jié)點(diǎn)下對(duì)應(yīng)的配置文件my.cnf,增加如下配置
#MGR
server-id = 1? #主節(jié)點(diǎn)設(shè)置為1忆谓,從節(jié)點(diǎn)從2-9,此次實(shí)驗(yàn)為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"? #這個(gè)name必須是一個(gè)uuid的格式
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "172.17.100.101:23306"? #每個(gè)節(jié)點(diǎn)此處為本機(jī)的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? #單主模式必須設(shè)置
loose-group_replication_enforce_update_everywhere_checks=false? #單主模式必須設(shè)置
第一節(jié)點(diǎn)(主節(jié)點(diǎn))
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;
第二節(jié)點(diǎn)
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;
第三節(jié)點(diǎn)
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相關(guān)信息檢測(cè)
#查詢組成員
select * from performance_schema.replication_group_members;
#查詢主節(jié)點(diǎn)
select variable_value from performance_schema.global_status where variable_name='group_replication_primary_member';
搭建中遇到的報(bào)錯(cuò)
1.[ERROR] Plugin group_replication reported: '[GCS] Error on opening a connection to 172.17.100.103:23306 on local port: 23306.'
這個(gè)報(bào)錯(cuò)是主節(jié)點(diǎn)執(zhí)行start group_replication時(shí)發(fā)生的
重新執(zhí)行set global group_replication_bootstrap_group=on;
之后再次start可以正常啟動(dòng)
實(shí)際上之前我已經(jīng)執(zhí)行過(guò)set global group_replication_bootstrap_group=on這個(gè)語(yǔ)句了,為什么會(huì)出現(xiàn)這個(gè)報(bào)錯(cuò),有點(diǎn)懵比次舌,總之重新執(zhí)行后解決該問(wèn)題帅涂。
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,
這個(gè)報(bào)錯(cuò)是在第二節(jié)點(diǎn)執(zhí)行start的時(shí)候產(chǎn)生的,根本原因是因?yàn)榈诙?jié)點(diǎn)沒(méi)有執(zhí)行join語(yǔ)句
執(zhí)行set global group_replication_allow_local_disjoint_gtids_join=ON;
完成上述語(yǔ)句的執(zhí)行之后罐孝,再次start,即可成功執(zhí)行
3.主從庫(kù)皆可執(zhí)行寫操作肥缔,下列語(yǔ)句執(zhí)行后莲兢,結(jié)果為空
select variable_value from performance_schema.global_status where variable_name='group_replication_primary_member';
檢查參數(shù)中的下列2行是否配置正確
在配置相反的情況下,搭建的MGR為多主
MGR切換測(cè)試
主節(jié)點(diǎn)執(zhí)行關(guān)閉數(shù)據(jù)庫(kù)
從節(jié)點(diǎn)執(zhí)行相關(guān)檢測(cè)
重新啟動(dòng)之前的主節(jié)點(diǎn)续膳,并執(zhí)行start GR改艇,將主節(jié)點(diǎn)加入到MGR組內(nèi),可以發(fā)現(xiàn)主節(jié)點(diǎn)已經(jīng)變更為之前的從節(jié)點(diǎn)