MySQL高可用方案MGR单主模式

一 MGR简介

官方文档 https://dev.mysql.com/doc/refman/5.7/en/group-replication.html

MGR是MySQL的一个插件,MGR可以做为MySQL高可用,可扩展,容错的拓扑结构。Group Replication (组复制)是MySQL内置的插件,是在5.7.17版本后才支持的。一个组内至少有3个实例,最多有9个实例,允许故障的实例数为如下表

Group Size

Majority

Instant Failures Tolerated

1

1

0

2

2

0

3

2

1

4

3

1

5

3

2

6

4

2

7

4

3

模式 :

单主模式 ,只有一个实例可以接受更新

多主模式 :所有的实例节点都可以接受更新

二 部署环境说明

主机IP 主机host 版本 权重
10.96.1.114 test-mysql001 5.7.21 50
10.96.1.115 test-mysql003 5.7.21 40
10.96.1.116 test-mysql002 5.7.21 30

部署要求

1 innodb存储引擎

2 表必须有主键或者非空的唯一索引

3 只支持IPV4网络

4 对网络性能有要求 要关闭防火墙

数据库参数配置要求

1 必须开启binlog 

组复制的一些限制或者不支持

三 MGR部署

1 在三台数据库服务器上设置 

 vi /etc/hosts

10.96.1.114 test-mysql001
10.96.1.115 test-mysql003
10.96.1.116 test-mysql002

2 三台服务器上部署MySQL,可以通过脚本部署

配置文件需要设置的参数

#114
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
log_bin=binlog
binlog_format=ROW
log_slave_updates=ON
binlog_checksum=NONE
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="7c160b7a-fc0f-11ea-9e8c-00163e08fe16"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "10.96.1.114:33061"
loose-group_replication_group_seeds= "10.96.1.114:33061,10.96.1.115:33061,10.96.1.116:33061"
loose-group_replication_bootstrap_group=off
loose-group_replication_member_weight=50

#115
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
log_bin=binlog
binlog_format=ROW
log_slave_updates=ON
binlog_checksum=NONE
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="7c160b7a-fc0f-11ea-9e8c-00163e08fe16"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "10.96.1.115:33061"
loose-group_replication_group_seeds= "10.96.1.114:33061,10.96.1.115:33061,10.96.1.116:33061"
loose-group_replication_bootstrap_group=off
loose-group_replication_member_weight=40

#116
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
log_bin=binlog
binlog_format=ROW
log_slave_updates=ON
binlog_checksum=NONE
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="7c160b7a-fc0f-11ea-9e8c-00163e08fe16"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "10.96.1.116:33061"
loose-group_replication_group_seeds= "10.96.1.114:33061,10.96.1.115:33061,10.96.1.116:33061"
loose-group_replication_bootstrap_group=off
loose-group_replication_member_weight=30

 配置文件注意点

1 需要注意修改server-id,各节点的值不能重复

2 这里的端口和数据库本身的3306端口值是不一样的。

3 group_replication_group_name必须是有效的UUID。使用select uuid()来生成UUID。不同的实例的配置文件中该参数相同

4 group_replication_start_on_boot=off表示在启动时服务器时不自动启动组复制。这在设置组复制时很重要,因为它确保您可以在手动启动插件之前配置服务器。配置成员后,可以将group_replication_start_on_boot设置为on,以便组复制在服务器启动时自动启动。

5  修改完后重启数据库

创建复制账号 启动复制

GRANT REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY 'repl';
CHANGE MASTER TO MASTER_USER='repl', MASTER_PASSWORD='repl' FOR CHANNEL 'group_replication_recovery';

安装插件

INSTALL PLUGIN group_replication SONAME 'group_replication.so';
#查看是否安装成功
show plugins;

 主节点启动

SET GLOBAL group_replication_bootstrap_group=ON;
START GROUP_REPLICATION;
SET GLOBAL group_replication_bootstrap_group=OFF;

# 停止组复制的命令
 stop group_replication;

验证

SELECT * FROM performance_schema.replication_group_members;

日志如下:

2020-09-21T21:47:17.800705+08:00 277 [Note] Plugin group_replication reported: 'Group communication SSL configuration: group_replication_ssl_mode: "DISABLED"'
2020-09-21T21:47:17.800815+08:00 277 [Note] Plugin group_replication reported: '[GCS] Added automatically IP ranges 10.96.1.114/24,127.0.0.1/8 to the whitelist'
2020-09-21T21:47:17.800933+08:00 277 [Warning] Plugin group_replication reported: '[GCS] Automatically adding IPv4 localhost address to the whitelist. It is mandatory that it is added.'
2020-09-21T21:47:17.801012+08:00 277 [Note] Plugin group_replication reported: '[GCS] SSL was not enabled'
2020-09-21T21:47:17.801031+08:00 277 [Note] Plugin group_replication reported: 'Initialized group communication with configuration: group_replication_group_name: "7c160b7a-fc0f-11ea-9e8c-00163e08fe16"; group_replication_local_address: "10.96.1.114:33061"; group_replication_group_seeds: "10.96.1.114:33061,10.96.1.115:33061,10.96.1.116:33061"; group_replication_bootstrap_group: true; group_replication_poll_spin_loops: 0; group_replication_compression_threshold: 1000000; group_replication_ip_whitelist: "AUTOMATIC"'
2020-09-21T21:47:17.801078+08:00 277 [Note] Plugin group_replication reported: 'Member configuration: member_id: 1114; member_uuid: "7f66e8c1-f1ad-11ea-bd28-00163e08fe16"; single-primary mode: "true"; group_replication_auto_increment_increment: 7; '
2020-09-21T21:47:17.820402+08:00 311 [Note] 'CHANGE MASTER TO FOR CHANNEL 'group_replication_applier' executed'. Previous state master_host='', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''. New state master_host='<NULL>', master_port= 0, master_log_file='', master_log_pos= 4, master_bind=''.
2020-09-21T21:47:17.849836+08:00 314 [Note] Slave SQL thread for channel 'group_replication_applier' initialized, starting replication in log 'FIRST' at position 0, relay log './test-mysql001-relay-bin-group_replication_applier.000001' position: 4
2020-09-21T21:47:17.850118+08:00 277 [Note] Plugin group_replication reported: 'Group Replication applier module successfully initialized!'
2020-09-21T21:47:17.850138+08:00 277 [Note] Plugin group_replication reported: 'auto_increment_increment is set to 7'
2020-09-21T21:47:17.850142+08:00 277 [Note] Plugin group_replication reported: 'auto_increment_offset is set to 1114'
2020-09-21T21:47:17.850269+08:00 0 [Note] Plugin group_replication reported: 'state 0 action xa_init'
2020-09-21T21:47:17.871995+08:00 0 [Note] Plugin group_replication reported: 'Successfully bound to 0.0.0.0:33061 (socket=49).'
2020-09-21T21:47:17.872037+08:00 0 [Note] Plugin group_replication reported: 'Successfully set listen backlog to 32 (socket=49)!'
2020-09-21T21:47:17.872043+08:00 0 [Note] Plugin group_replication reported: 'Successfully unblocked socket (socket=49)!'
2020-09-21T21:47:17.872083+08:00 0 [Note] Plugin group_replication reported: 'Ready to accept incoming connections on 0.0.0.0:33061 (socket=49)!'
2020-09-21T21:47:17.872124+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.114 33061'
2020-09-21T21:47:17.872265+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.114 33061 fd 51'
2020-09-21T21:47:17.872578+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.114 33061'
2020-09-21T21:47:17.872647+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.114 33061 fd 53'
2020-09-21T21:47:17.872785+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.114 33061'
2020-09-21T21:47:17.872814+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.114 33061 fd 55'
2020-09-21T21:47:17.872906+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.114 33061'
2020-09-21T21:47:17.872935+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.114 33061 fd 57'
2020-09-21T21:47:17.873216+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.114 33061'
2020-09-21T21:47:17.873279+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.114 33061 fd 59'
2020-09-21T21:47:17.873521+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.114 33061'
2020-09-21T21:47:17.873591+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.114 33061 fd 61'
2020-09-21T21:47:17.873857+08:00 0 [Note] Plugin group_replication reported: 'state 4338 action xa_net_boot'
2020-09-21T21:47:17.873874+08:00 0 [Note] Plugin group_replication reported: 'getstart group_id aa8999f8'
2020-09-21T21:47:17.874158+08:00 0 [Note] Plugin group_replication reported: 'new state x_run'
2020-09-21T21:47:17.874222+08:00 0 [Note] Plugin group_replication reported: 'state 4411 action xa_net_boot'
2020-09-21T21:47:17.874229+08:00 0 [Note] Plugin group_replication reported: 'new state x_run'
2020-09-21T21:47:17.874242+08:00 0 [Note] Plugin group_replication reported: 'getstart group_id aa8999f8'
2020-09-21T21:47:18.874319+08:00 319 [Note] Plugin group_replication reported: 'Only one server alive. Declaring this server as online within the replication group'
2020-09-21T21:47:18.874428+08:00 0 [Note] Plugin group_replication reported: 'Group membership changed to test-mysql001:3306 on view 16006960388739482:1.'
2020-09-21T21:47:18.877801+08:00 0 [Note] Plugin group_replication reported: 'This server was declared online within the replication group'
2020-09-21T21:47:18.877917+08:00 0 [Note] Plugin group_replication reported: 'A new primary with address test-mysql001:3306 was elected, enabling conflict detection until the new primary applies all relay logs.'
2020-09-21T21:47:18.877973+08:00 321 [Note] Plugin group_replication reported: 'This server is working as primary member.'
2020-09-21T21:50:23.869575+08:00 0 [Note] Plugin group_replication reported: 'getstart group_id aa8999f8'
2020-09-21T21:50:29.136563+08:00 0 [Note] Plugin group_replication reported: 'Members joined the group: test-mysql003:3306'
2020-09-21T21:50:29.136708+08:00 0 [Note] Plugin group_replication reported: 'Group membership changed to test-mysql001:3306, test-mysql003:3306 on view 16006960388739482:2.'
2020-09-21T21:50:29.137064+08:00 0 [Note] Plugin group_replication reported: 'getstart group_id aa8999f8'
2020-09-21T21:50:29.891113+08:00 0 [Warning] Plugin group_replication reported: 'Members removed from the group: test-mysql003:3306'
2020-09-21T21:50:29.891294+08:00 0 [Note] Plugin group_replication reported: 'Group membership changed to test-mysql001:3306 on view 16006960388739482:3.'
2020-09-21T21:56:53.408339+08:00 0 [Note] Plugin group_replication reported: 'getstart group_id aa8999f8'
2020-09-21T21:56:57.293503+08:00 0 [Note] Plugin group_replication reported: 'Members joined the group: test-mysql003:3306'
2020-09-21T21:56:57.293680+08:00 0 [Note] Plugin group_replication reported: 'Group membership changed to test-mysql001:3306, test-mysql003:3306 on view 16006960388739482:4.'
2020-09-21T21:56:57.343628+08:00 866 [Note] Start binlog_dump to master_thread_id(866) slave_server(1115), pos(, 4)
2020-09-21T21:56:57.400534+08:00 0 [Note] Plugin group_replication reported: 'The member with address test-mysql003:3306 was declared online within the replication group'
2020-09-21T21:57:57.344004+08:00 866 [Note] Aborted connection 866 to db: 'unconnected' user: 'repl' host: '10.96.1.115' (failed on flush_net())
2020-09-21T22:00:52.281243+08:00 0 [Note] Plugin group_replication reported: 'getstart group_id aa8999f8'
2020-09-21T22:00:54.376765+08:00 0 [Note] Plugin group_replication reported: 'Members joined the group: test-mysql002:3306'
2020-09-21T22:00:54.376962+08:00 0 [Note] Plugin group_replication reported: 'Group membership changed to test-mysql002:3306, test-mysql001:3306, test-mysql003:3306 on view 16006960388739482:5.'
2020-09-21T22:00:54.377440+08:00 0 [Note] Plugin group_replication reported: 'getstart group_id aa8999f8'
2020-09-21T22:00:54.890952+08:00 0 [Warning] Plugin group_replication reported: 'Members removed from the group: test-mysql002:3306'
2020-09-21T22:00:54.891081+08:00 0 [Note] Plugin group_replication reported: 'Group membership changed to test-mysql001:3306, test-mysql003:3306 on view 16006960388739482:6.'
2020-09-21T22:04:28.400105+08:00 0 [Note] Plugin group_replication reported: 'getstart group_id aa8999f8'
2020-09-21T22:04:30.482608+08:00 0 [Note] Plugin group_replication reported: 'Members joined the group: test-mysql002:3306'
2020-09-21T22:04:30.482800+08:00 0 [Note] Plugin group_replication reported: 'Group membership changed to test-mysql002:3306, test-mysql001:3306, test-mysql003:3306 on view 16006960388739482:7.'
2020-09-21T22:04:30.640506+08:00 0 [Note] Plugin group_replication reported: 'The member with address test-mysql002:3306 was declared online within the replication group'

115节点加入 

GRANT REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY 'repl';
CHANGE MASTER TO MASTER_USER='repl', MASTER_PASSWORD='repl' FOR CHANNEL 'group_replication_recovery';

安装插件

INSTALL PLUGIN group_replication SONAME 'group_replication.so';

#相应的卸载插件命令

UNINSTALL PLUGIN group_replication;
#查看是否安装成功
show plugins;

start group_replication;

报错如下

2020-09-21T21:50:29.136762+08:00 0 [ERROR] Plugin group_replication reported: 'This member has more executed transactions than those present in the group. Local transactions: c12c0dad-f1af-11ea-87b8-00163e030025:1 > Group transactions: 7c160b7a-fc0f-11ea-9e8c-00163e08fe16:1,
7f66e8c1-f1ad-11ea-bd28-00163e08fe16:1'
2020-09-21T21:50:29.136811+08:00 0 [ERROR] Plugin group_replication reported: 'The member contains transactions not present in the group. The member will now exit the group.'

原因:数据不一致导致

解决: 从主节点上备份一份数据恢复至另外两个节点上

日志如下

2020-09-21T21:56:53.362793+08:00 2 [Note] Plugin group_replication reported: 'Group communication SSL configuration: group_replication_ssl_mode: "DISABLED"'
2020-09-21T21:56:53.362880+08:00 2 [Note] Plugin group_replication reported: '[GCS] Added automatically IP ranges 10.96.1.115/24,127.0.0.1/8 to the whitelist'
2020-09-21T21:56:53.362942+08:00 2 [Warning] Plugin group_replication reported: '[GCS] Automatically adding IPv4 localhost address to the whitelist. It is mandatory that it is added.'
2020-09-21T21:56:53.362980+08:00 2 [Note] Plugin group_replication reported: '[GCS] SSL was not enabled'
2020-09-21T21:56:53.362993+08:00 2 [Note] Plugin group_replication reported: 'Initialized group communication with configuration: group_replication_group_name: "7c160b7a-fc0f-11ea-9e8c-00163e08fe16"; group_replication_local_address: "10.96.1.115:33061"; group_replication_group_seeds: "10.96.1.114:33061,10.96.1.115:33061,10.96.1.116:33061"; group_replication_bootstrap_group: false; group_replication_poll_spin_loops: 0; group_replication_compression_threshold: 1000000; group_replication_ip_whitelist: "AUTOMATIC"'
2020-09-21T21:56:53.363020+08:00 2 [Note] Plugin group_replication reported: 'Member configuration: member_id: 1115; member_uuid: "c12c0dad-f1af-11ea-87b8-00163e030025"; single-primary mode: "true"; group_replication_auto_increment_increment: 7; '
2020-09-21T21:56:53.363113+08:00 13 [Note] Plugin group_replication reported: 'Detected previous RESET MASTER invocation or an issue exists in the group replication applier relay log. Purging existing applier logs.'
2020-09-21T21:56:53.383336+08:00 13 [Note] 'CHANGE MASTER TO FOR CHANNEL 'group_replication_applier' executed'. Previous state master_host='', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''. New state master_host='<NULL>', master_port= 0, master_log_file='', master_log_pos= 4, master_bind=''.
2020-09-21T21:56:53.406405+08:00 2 [Note] Plugin group_replication reported: 'Group Replication applier module successfully initialized!'
2020-09-21T21:56:53.406408+08:00 16 [Note] Slave SQL thread for channel 'group_replication_applier' initialized, starting replication in log 'FIRST' at position 0, relay log './test-mysql003-relay-bin-group_replication_applier.000001' position: 4
2020-09-21T21:56:53.406442+08:00 2 [Note] Plugin group_replication reported: 'auto_increment_increment is set to 7'
2020-09-21T21:56:53.406463+08:00 2 [Note] Plugin group_replication reported: 'auto_increment_offset is set to 1115'
2020-09-21T21:56:53.406553+08:00 0 [Note] Plugin group_replication reported: 'state 4338 action xa_init'
2020-09-21T21:56:53.406585+08:00 0 [Note] Plugin group_replication reported: 'Successfully bound to 0.0.0.0:33061 (socket=39).'
2020-09-21T21:56:53.406598+08:00 0 [Note] Plugin group_replication reported: 'Successfully set listen backlog to 32 (socket=39)!'
2020-09-21T21:56:53.406603+08:00 0 [Note] Plugin group_replication reported: 'Successfully unblocked socket (socket=39)!'
2020-09-21T21:56:53.406634+08:00 0 [Note] Plugin group_replication reported: 'Ready to accept incoming connections on 0.0.0.0:33061 (socket=39)!'
2020-09-21T21:56:53.406637+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.115 33061'
2020-09-21T21:56:53.406727+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.115 33061 fd 46'
2020-09-21T21:56:53.406888+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.115 33061'
2020-09-21T21:56:53.406932+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.115 33061 fd 49'
2020-09-21T21:56:53.407064+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.115 33061'
2020-09-21T21:56:53.407097+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.115 33061 fd 51'
2020-09-21T21:56:53.407211+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.115 33061'
2020-09-21T21:56:53.407239+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.115 33061 fd 53'
2020-09-21T21:56:53.407413+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.115 33061'
2020-09-21T21:56:53.407475+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.115 33061 fd 55'
2020-09-21T21:56:53.407614+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.115 33061'
2020-09-21T21:56:53.407652+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.115 33061 fd 57'
2020-09-21T21:56:53.407789+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.114 33061'
2020-09-21T21:56:53.408069+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.114 33061 fd 59'
2020-09-21T21:56:53.966651+08:00 0 [Note] Plugin group_replication reported: 'state 4338 action xa_snapshot'
2020-09-21T21:56:53.966841+08:00 0 [Note] Plugin group_replication reported: 'new state x_recover'
2020-09-21T21:56:53.966850+08:00 0 [Note] Plugin group_replication reported: 'state 4358 action xa_complete'
2020-09-21T21:56:53.966993+08:00 0 [Note] Plugin group_replication reported: 'new state x_run'
2020-09-21T21:56:57.293780+08:00 2 [Note] Plugin group_replication reported: 'This server is working as secondary member with primary member address test-mysql001:3306.'
2020-09-21T21:56:57.294047+08:00 19 [Note] Plugin group_replication reported: 'Establishing group recovery connection with a possible donor. Attempt 1/10'
2020-09-21T21:56:57.294109+08:00 0 [Note] Plugin group_replication reported: 'Group membership changed to test-mysql001:3306, test-mysql003:3306 on view 16006960388739482:4.'
2020-09-21T21:56:57.319335+08:00 19 [Note] 'CHANGE MASTER TO FOR CHANNEL 'group_replication_recovery' executed'. Previous state master_host='', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''. New state master_host='test-mysql001', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''.
2020-09-21T21:56:57.339127+08:00 19 [Note] Plugin group_replication reported: 'Establishing connection to a group replication recovery donor 7f66e8c1-f1ad-11ea-bd28-00163e08fe16 at test-mysql001 port: 3306.'
2020-09-21T21:56:57.339385+08:00 21 [Warning] Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
2020-09-21T21:56:57.340326+08:00 21 [Note] Slave I/O thread for channel 'group_replication_recovery': connected to master 'repl@test-mysql001:3306',replication started in log 'FIRST' at position 4
2020-09-21T21:56:57.342017+08:00 22 [Note] Slave SQL thread for channel 'group_replication_recovery' initialized, starting replication in log 'FIRST' at position 0, relay log './test-mysql003-relay-bin-group_replication_recovery.000001' position: 4
2020-09-21T21:56:57.357127+08:00 19 [Note] Plugin group_replication reported: 'Terminating existing group replication donor connection and purging the corresponding logs.'
2020-09-21T21:56:57.359064+08:00 22 [Note] Slave SQL thread for channel 'group_replication_recovery' exiting, replication stopped in log 'binlog.000001' at position 1477
2020-09-21T21:56:57.360968+08:00 21 [Note] Slave I/O thread killed while reading event for channel 'group_replication_recovery'
2020-09-21T21:56:57.360981+08:00 21 [Note] Slave I/O thread exiting for channel 'group_replication_recovery', read up to log 'binlog.000001', position 1477
2020-09-21T21:56:57.380990+08:00 19 [Note] 'CHANGE MASTER TO FOR CHANNEL 'group_replication_recovery' executed'. Previous state master_host='test-mysql001', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''. New state master_host='<NULL>', master_port= 0, master_log_file='', master_log_pos= 4, master_bind=''.
2020-09-21T21:56:57.400683+08:00 0 [Note] Plugin group_replication reported: 'This server was declared online within the replication group'

115添加上之后查询集群状态 

116 节点加入集群

GRANT REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY 'repl';
CHANGE MASTER TO MASTER_USER='repl', MASTER_PASSWORD='repl' FOR CHANNEL 'group_replication_recovery';

安装插件

INSTALL PLUGIN group_replication SONAME 'group_replication.so';

#相应的卸载插件命令

UNINSTALL PLUGIN group_replication;
#查看是否安装成功
show plugins;

start group_replication;

日志如下

2020-09-21T22:04:11.768568+08:00 11 [Note] 'CHANGE MASTER TO FOR CHANNEL 'group_replication_recovery' executed'. Previous state master_host='', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''. New state master_host='', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''.
2020-09-21T22:04:28.341497+08:00 11 [Note] Plugin group_replication reported: 'Group communication SSL configuration: group_replication_ssl_mode: "DISABLED"'
2020-09-21T22:04:28.341622+08:00 11 [Note] Plugin group_replication reported: '[GCS] Added automatically IP ranges 10.96.1.116/24,127.0.0.1/8 to the whitelist'
2020-09-21T22:04:28.341713+08:00 11 [Warning] Plugin group_replication reported: '[GCS] Automatically adding IPv4 localhost address to the whitelist. It is mandatory that it is added.'
2020-09-21T22:04:28.341790+08:00 11 [Note] Plugin group_replication reported: '[GCS] SSL was not enabled'
2020-09-21T22:04:28.341811+08:00 11 [Note] Plugin group_replication reported: 'Initialized group communication with configuration: group_replication_group_name: "7c160b7a-fc0f-11ea-9e8c-00163e08fe16"; group_replication_local_address: "10.96.1.116:33061"; group_replication_group_seeds: "10.96.1.114:33061,10.96.1.115:33061,10.96.1.116:33061"; group_replication_bootstrap_group: false; group_replication_poll_spin_loops: 0; group_replication_compression_threshold: 1000000; group_replication_ip_whitelist: "AUTOMATIC"'
2020-09-21T22:04:28.341850+08:00 11 [Note] Plugin group_replication reported: 'Member configuration: member_id: 1116; member_uuid: "6175e697-f3de-11ea-a7df-00163e0872d3"; single-primary mode: "true"; group_replication_auto_increment_increment: 7; '
2020-09-21T22:04:28.341999+08:00 13 [Note] Plugin group_replication reported: 'Detected previous RESET MASTER invocation or an issue exists in the group replication applier relay log. Purging existing applier logs.'
2020-09-21T22:04:28.363487+08:00 13 [Note] 'CHANGE MASTER TO FOR CHANNEL 'group_replication_applier' executed'. Previous state master_host='', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''. New state master_host='<NULL>', master_port= 0, master_log_file='', master_log_pos= 4, master_bind=''.
2020-09-21T22:04:28.397215+08:00 16 [Note] Slave SQL thread for channel 'group_replication_applier' initialized, starting replication in log 'FIRST' at position 0, relay log './test-mysql002-relay-bin-group_replication_applier.000001' position: 4
2020-09-21T22:04:28.397393+08:00 11 [Note] Plugin group_replication reported: 'Group Replication applier module successfully initialized!'
2020-09-21T22:04:28.397415+08:00 11 [Note] Plugin group_replication reported: 'auto_increment_increment is set to 7'
2020-09-21T22:04:28.397419+08:00 11 [Note] Plugin group_replication reported: 'auto_increment_offset is set to 1116'
2020-09-21T22:04:28.397507+08:00 0 [Note] Plugin group_replication reported: 'state 4338 action xa_init'
2020-09-21T22:04:28.397555+08:00 0 [Note] Plugin group_replication reported: 'Successfully bound to 0.0.0.0:33061 (socket=42).'
2020-09-21T22:04:28.397575+08:00 0 [Note] Plugin group_replication reported: 'Successfully set listen backlog to 32 (socket=42)!'
2020-09-21T22:04:28.397582+08:00 0 [Note] Plugin group_replication reported: 'Successfully unblocked socket (socket=42)!'
2020-09-21T22:04:28.397607+08:00 0 [Note] Plugin group_replication reported: 'Ready to accept incoming connections on 0.0.0.0:33061 (socket=42)!'
2020-09-21T22:04:28.397635+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.116 33061'
2020-09-21T22:04:28.397773+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.116 33061 fd 44'
2020-09-21T22:04:28.397935+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.116 33061'
2020-09-21T22:04:28.397980+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.116 33061 fd 49'
2020-09-21T22:04:28.398196+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.116 33061'
2020-09-21T22:04:28.398230+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.116 33061 fd 51'
2020-09-21T22:04:28.398371+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.116 33061'
2020-09-21T22:04:28.398423+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.116 33061 fd 53'
2020-09-21T22:04:28.398507+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.116 33061'
2020-09-21T22:04:28.398537+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.116 33061 fd 55'
2020-09-21T22:04:28.398691+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.116 33061'
2020-09-21T22:04:28.398722+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.116 33061 fd 57'
2020-09-21T22:04:28.398843+08:00 0 [Note] Plugin group_replication reported: 'connecting to 10.96.1.114 33061'
2020-09-21T22:04:28.399167+08:00 0 [Note] Plugin group_replication reported: 'client connected to 10.96.1.114 33061 fd 59'
2020-09-21T22:04:29.382055+08:00 0 [Note] Plugin group_replication reported: 'state 4338 action xa_snapshot'
2020-09-21T22:04:29.382315+08:00 0 [Note] Plugin group_replication reported: 'new state x_recover'
2020-09-21T22:04:29.382329+08:00 0 [Note] Plugin group_replication reported: 'state 4358 action xa_complete'
2020-09-21T22:04:29.382511+08:00 0 [Note] Plugin group_replication reported: 'new state x_run'
2020-09-21T22:04:30.482523+08:00 11 [Note] Plugin group_replication reported: 'This server is working as secondary member with primary member address test-mysql001:3306.'
2020-09-21T22:04:30.482822+08:00 19 [Note] Plugin group_replication reported: 'Establishing group recovery connection with a possible donor. Attempt 1/10'
2020-09-21T22:04:30.482948+08:00 0 [Note] Plugin group_replication reported: 'Group membership changed to test-mysql002:3306, test-mysql001:3306, test-mysql003:3306 on view 16006960388739482:7.'
2020-09-21T22:04:30.517626+08:00 19 [Note] 'CHANGE MASTER TO FOR CHANNEL 'group_replication_recovery' executed'. Previous state master_host='', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''. New state master_host='test-mysql003', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''.
2020-09-21T22:04:30.546002+08:00 19 [Note] Plugin group_replication reported: 'Establishing connection to a group replication recovery donor c12c0dad-f1af-11ea-87b8-00163e030025 at test-mysql003 port: 3306.'
2020-09-21T22:04:30.546404+08:00 21 [Warning] Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
2020-09-21T22:04:30.547404+08:00 21 [Note] Slave I/O thread for channel 'group_replication_recovery': connected to master 'repl@test-mysql003:3306',replication started in log 'FIRST' at position 4
2020-09-21T22:04:30.549126+08:00 22 [Note] Slave SQL thread for channel 'group_replication_recovery' initialized, starting replication in log 'FIRST' at position 0, relay log './test-mysql002-relay-bin-group_replication_recovery.000001' position: 4
2020-09-21T22:04:30.572532+08:00 19 [Note] Plugin group_replication reported: 'Terminating existing group replication donor connection and purging the corresponding logs.'
2020-09-21T22:04:30.574519+08:00 22 [Note] Slave SQL thread for channel 'group_replication_recovery' exiting, replication stopped in log 'binlog.000001' at position 1242
2020-09-21T22:04:30.577072+08:00 21 [Note] Slave I/O thread killed while reading event for channel 'group_replication_recovery'
2020-09-21T22:04:30.577101+08:00 21 [Note] Slave I/O thread exiting for channel 'group_replication_recovery', read up to log 'binlog.000001', position 1242
2020-09-21T22:04:30.614683+08:00 19 [Note] 'CHANGE MASTER TO FOR CHANNEL 'group_replication_recovery' executed'. Previous state master_host='test-mysql003', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''. New state master_host='<NULL>', master_port= 0, master_log_file='', master_log_pos= 4, master_bind=''.
2020-09-21T22:04:30.640180+08:00 0 [Note] Plugin group_replication reported: 'This server was declared online within the replication group'

验证如下 

报错截图 

 

2020-09-18T21:05:14.158480+08:00 4 [ERROR] Plugin group_replication reported: 'Timeout on wait for view after joining group'
2020-09-18T21:05:14.158686+08:00 4 [Note] Plugin group_replication reported: 'Requesting to leave the group despite of not being a member'
2020-09-18T21:05:14.158772+08:00 4 [ERROR] Plugin group_replication reported: '[GCS] The member is leaving a group without being on one.'
2020-09-18T21:05:14.159154+08:00 4 [Note] Plugin group_replication reported: 'auto_increment_increment is reset to 1'
2020-09-18T21:05:14.159222+08:00 4 [Note] Plugin group_replication reported: 'auto_increment_offset is reset to 1'
2020-09-18T21:05:14.159739+08:00 9 [Note] Error reading relay log event for channel 'group_replication_applier': slave SQL thread was killed
2020-09-18T21:05:14.161640+08:00 6 [Note] Plugin group_replication reported: 'The group replication applier thread was killed'

 参考博客:https://blog.csdn.net/weixin_30666753/article/details/99999641

https://cloud.tencent.com/developer/article/1438724

骏马金龙的博客 https://www.cnblogs.com/f-ck-need-u/p/7586194.html#auto_id_3

https://sq.163yun.com/blog/article/223220453915172864

猜你喜欢

转载自blog.csdn.net/weixin_48154829/article/details/108672557