mysql8.0.16 group replication(组复制)

关于mysql组复制从5.7.17就有了。本文主要是记录一下操作步骤,以及相应的坑点。

mysql 单主模式的组复制配置

三台机器 10.50.31.7,10.50.31.8,10.50.31.18

31.7上配置

my.cnf配置

server_id=1
log-bin=mysql-bin
log-bin-index=mysql-bin.index
relay-log=relay-log
#expire-logs-days=7
binlog_expire_logs_seconds=159200
port=3306
report-host='10.50.31.7'
binlog-format=row
gtid-mode=on
enforce_gtid_consistency=on
log_slave_updates=on
master_info_repository=table
relay_log_info_repository=table
binlog_checksum=none
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name='12345678-1234-1234-1234-1234567890ab'
loose-group_replication_start_on_boot=off
loose-group_replication_bootstrap_group=off
loose-group_replication_local_address='10.50.31.7:24901'

#slave-parallel-type='LOGICAL_CLOCK'
#slave-parallel-workers=3
#slave-preserve-commit-order=on
loose-group_replication_group_seeds='10.50.31.7:24901,10.50.31.8:24901,10.50.31.18:24901'
transaction_isolation = READ-COMMITTED
loose-group_replication_single_primary_mode = off
loose-group_replication_enforce_update_everywhere_checks = on

(注意在这里有一个坑,就是启动的24901端口,可能需要关闭防火墙,如果是demo执行 /usr/sbin/setenforce 0 即可)

重启mysql,并连接上mysql server,执行如下sql:

 set sql_log_bin=0;
 create user repl_user@'%' identified by 'NewRepl4!';
 grant replication slave on *.* to repl_user@'%' ;
 flush privileges;
 set sql_log_bin=1;
 install plugin group_replication soname 'group_replication.so';
 change master to master_user='repl_user',master_password='NewRepl4!' 
 for channel 'group_replication_recovery';

31.8上配置

my.cnf配置

server_id=2
log-bin=mysql-bin
log-bin-index=mysql-bin.index
log-slave-updates=on
relay-log=relay-log
#expire-logs-days=7
binlog_expire_logs_seconds=159200
port=3306
report-host='10.50.31.8'
gtid-mode=on
enforce-gtid-consistency=on
binlog-format=row
binlog-checksum=none
master-info-repository=table
relay-log-info-repository=table
transaction-write-set-extraction=MURMUR32
#slave-parallel-type='LOGICAL_CLOCK'
#slave-parallel-workers=3
#slave-preserve-commit-order=on
loose-group_replication_group_name='12345678-1234-1234-1234-1234567890ab'
loose-group_replication_local_address='10.50.31.8:24901'
loose-group_replication_group_seeds='10.50.31.7:24901,10.50.31.8:24901,10.50.31.18:24901'
loose-group_replication_bootstrap_group=off
loose-group_replication_start_on_boot=off

重启mysql,并连接上mysql server,执行如下sql:

 set sql_log_bin=0;
 create user repl_user@'%' identified by 'NewRepl4!';
 grant replication slave on *.* to repl_user@'%' ;
 flush privileges;
 set sql_log_bin=1;
 install plugin group_replication soname 'group_replication.so';
 
 change master to master_user='repl_user',master_password='NewRepl4!' 
 for channel 'group_replication_recovery';

31.15上配置(同31.8,注意修改ip端口号、server_id 等)

31.15也完成相应的配置,重启数据库,执行完相应的sql,我们以 31.7作为主库进行组引导初始化组复制。

再次回到31.7

接着执行如下sql

 SET GLOBAL group_replication_bootstrap_group=ON;
 start group_replication;
 set global group_replication_bootstrap_group=off;
 --查看组员情况
 select *From performance_schema.replication_group_members;

回到31.8

接着执行如下sql(注意与31.7的区别)

 start group_replication;
 如果有binlog错误,执行
 stop group_replication;
 reset master;(5.7版本可以执行set global group_replication_allow_local_disjoint_gtids_join=on;)
 start group_replication;

回到31.18

执行步骤与31.8一样;

你可能感兴趣的:(mysql,框架)