准备3台服务器
10.0.0.201 node201
10.0.0.202 node202
10.0.0.203 node203
操作系统:centos 7.x 64
mysql: 5.7.20
采用编译源码安装以及systemctl管理
http://blog.csdn.net/chenhaifeng2016/article/details/77689270
配置node201
修改配置文件/etc/my.cnf
# # Replication configuration parameters # server_id=201 gtid_mode=ON enforce_gtid_consistency=ON master_info_repository=TABLE relay_log_info_repository=TABLE binlog_checksum=NONE log_slave_updates=ON log_bin=binlog binlog_format=ROW # # Group Replication configuration # transaction_write_set_extraction=XXHASH64 loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" loose-group_replication_start_on_boot=off loose-group_replication_local_address= "10.0.0.201:33060" loose-group_replication_group_seeds= "10.0.0.201:33060,10.0.0.202:33060,10.0.0.203:33060" loose-group_replication_bootstrap_group= off
执行以下命令
SET SQL_LOG_BIN=0; CREATE USER rpl_user@'%' IDENTIFIED BY 'password'; GRANT REPLICATION SLAVE,replication client ON *.* TO rpl_user@'%'; FLUSH PRIVILEGES; SET SQL_LOG_BIN=1; CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='password' 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; 查看状态 SELECT * FROM performance_schema.replication_group_members;
配置node202
修改配置文件/etc/my.cnf
# # Replication configuration parameters # server_id=202 gtid_mode=ON enforce_gtid_consistency=ON master_info_repository=TABLE relay_log_info_repository=TABLE binlog_checksum=NONE log_slave_updates=ON log_bin=binlog binlog_format=ROW # # Group Replication configuration # transaction_write_set_extraction=XXHASH64 loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" loose-group_replication_start_on_boot=off loose-group_replication_local_address= "10.0.0.202:33060" loose-group_replication_group_seeds= "10.0.0.201:33060,10.0.0.202:33060,10.0.0.203:33060" loose-group_replication_bootstrap_group= off
执行以下命令
SET SQL_LOG_BIN=0; CREATE USER rpl_user@'%'; GRANT REPLICATION SLAVE,replication client ON *.* TO rpl_user@'%' IDENTIFIED BY 'password'; SET SQL_LOG_BIN=1; CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='password' 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;
配置node203
修改配置文件/etc/my.cnf
# # Replication configuration parameters # server_id=203 gtid_mode=ON enforce_gtid_consistency=ON master_info_repository=TABLE relay_log_info_repository=TABLE binlog_checksum=NONE log_slave_updates=ON log_bin=binlog binlog_format=ROW # # Group Replication configuration # transaction_write_set_extraction=XXHASH64 loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" loose-group_replication_start_on_boot=off loose-group_replication_local_address= "10.0.0.203:33060" loose-group_replication_group_seeds= "10.0.0.201:33060,10.0.0.202:33060,10.0.0.203:33060" loose-group_replication_bootstrap_group= off
执行以下命令
SET SQL_LOG_BIN=0; CREATE USER rpl_user@'%'; GRANT REPLICATION SLAVE,replication client ON *.* TO rpl_user@'%' IDENTIFIED BY 'password'; FLUSH PRIVILEGES; SET SQL_LOG_BIN=1; CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='password' 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;
组复制部署已完成,输出结果显示node201为主节点可以读写,node202和node203只能读数据。