开启replication配置:
server-id=1 #标识服务器唯一
log-bin=mysql-bin #二进制日志开启
enforce_gtid_consistency = ON #GTID模式是组复制的基础技术
binlog-format=row #必须是ROW模式
gtid-mode=ON #GTID保证事物编号全局唯一 (Global Transaction ID)
master-info-repository=TABLE
relay-log-info-repository=TABLE #记录同步的信息,便于管理和恢复
log-slave-update = ON #需要记录事务的binlog,用作以后的恢复用,哪怕不是写入点,也需要
binlog-checksum=NONE #MGR本身不支持binlog的checksum校验
开启组配置:
transaction_write_set_extraction = XXHASH64 #哈希算法 loose-group_replication_group_name = "00e575aa-0cc0-11e8-9186-0050569341db" # 组名,格式 loose-group_replication_start_on_boot = off # 在mysqld启动时不自动启动组复制 loose-group_replication_local_address = "10.103.16.31:24901" #本机的IP地址及端口 loose-group_replication_group_seeds = "10.103.16.34:24901,10.103.16.35:24901,10.103.16.31:24901" #其他机器的IP及端口,形成一个组 loose-group_replication_bootstrap_group = off
主执行:
CHANGE MASTER TO MASTER_USER=‘stemp‘, MASTER_PASSWORD=‘123456‘ 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;
其他主执行:
INSTALL PLUGIN group_replication SONAME ‘group_replication.so‘; START GROUP_REPLICATION;
查看节点信息:
select * from performance_schema.replication_group_members;
在线修改节点信息:
set global group_replication_group_seeds=‘‘;
设置多主模式:
SERVER2,SERVER3:
STOP GROUP_REPLICATION; SET GLOBAL group_replication_single_primary_mode=FALSE; SET GLOBAL group_replication_enforce_update_everywhere_checks=TRUE;
SERVER1:
STOP GROUP_REPLICATION; SET GLOBAL group_replication_single_primary_mode=FALSE; SET GLOBAL group_replication_enforce_update_everywhere_checks=TRUE; SET GLOBAL group_replication_bootstrap_group=on; START GROUP_REPLICATION; SET GLOBAL group_replication_bootstrap_group=off;
然后SERVER2,SERVER3:
SET GLOBAL group_replication_bootstrap_group=on; START GROUP_REPLICATION; SET GLOBAL group_replication_bootstrap_group=off;