MGR中MySQL不同版本间的的通信协议介绍
MGR架构从MySQL5.7
就已经推出,在官方大力推广之下,到目前版本已经达到MySQL8.0.28
。这样就会存在数据库升级的情况。这次介绍的是关于在MGR架构中实例版本不一致存在着通信协议版本不同的问题
从MySQL 8.0.16
开始,MySQL增加了设置通信协议的功能,这个功能可以让不同版本的MySQL
在同一MGR
集群下运行,换言之,如果该参数设置不对可能导致不同版本的实例无法正常加入到集群当中。
通信协议版本
首先介绍如何查看版本,必须在MGR运行中查看
mysql> select group_replication_get_communication_protocol();
+------------------------------------------------+
| group_replication_get_communication_protocol() |
+------------------------------------------------+
| 8.0.16 |
+------------------------------------------------+
1 row in set (0.00 sec)
协议版本
目前有三个版本
-
5.7.14
从MySQL 5.7.14
开始该版本开始支持压缩功能 -
8.0.16 从 MySQL 8.0.16
该版本增加了支持信息碎片化 -
8.0.27 从 MySQL8.0.27
开始Single-primary 模式下且开启group_replication_paxos_single_leader = on
时,支持单节点作为learder 对外提供服务的功能呢
修改协议版本
使用 group_replication_set_communication_protocol()
函数,
mysql> select group_replication_set_communication_protocol('8.0.27');
+-----------------------------------------------------------------------------------+
| group_replication_set_communication_protocol('8.0.27') |
+-----------------------------------------------------------------------------------+
| The operation group_replication_set_communication_protocol completed successfully |
+-----------------------------------------------------------------------------------+
1 row in set (0.00 sec)
必须是在MGR正常运行且得到投票通过下可以修改,否则则会报错
mysql> select group_replication_set_communication_protocol('8.0.18');
ERROR 1123 (HY000): Can't initialize function 'group_replication_set_communication_protocol'; Member must be ONLINE and in the majority partition.
更多信息可以查看文档 18.8.1.2 Group Replication Communication Protocol Version[1]
不同版本集群组建原则
在一个集群中的所有成员必须使用一样的通信协议。在有通信协议管理功能后,可以实现一个集群中即使是不同版本的MySQL
也是可以在同一个集群中正常运行。
一个通信协议为X的节点,可以加入一个为ONLINE
状态的且组通信协议版本版本小于等于X的集群。当一个节点(A)加入时,A会检查组内的通信协议,如果A节点支持该版本协议,则它将加入该集群,并使用该协议,反之不支持则被驱逐出本群主(但是binlog 会发送过来且完成应用)
关于加入集群的例子:
-
一个 MySQL 8.0.16
实例可以加入到使用MySQL 5.7.24
协议的集群 -
一个 MySQL 5.7.24
实例不可以加入使用MySQL 8.0.16
协议的集群 -
两个 MySQL 8.0.16
实例不能同时加入使用MySQL 5.7.24
协议的集群 -
两个 MySQL 8.0.16
实例可以同时加入使用MySQL 8.0.16
协议的集群
( 不建议同时加入多个实例,容易出现操作争抢,导致超时,操作失败,即使是进程状态为运行中)
详情可查看文档 18.5.1.4 Setting a Group's Communication Protocol Version[2]
实践
角色 | 数据库版本 | IP:PORT | 默认通信协议版本 |
---|---|---|---|
Primary | 8.0.27 | 10.0.2.33:3307 | 8.0.27 |
Secondary | 8.0.27 | 10.0.2.32:3307 | 8.0.27 |
Secondary | 8.0.13 | 10.0.2.31:3308 | 5.7.14 |
注:协议版本划分有三个数据库版本节点 5.7.14
,8.0.16
,8.0.27
,对应三个版本
这次用例中使用8.0.27
搭建起了集群后,添加8.0.13
版本,按照上面说的规则是失败的,这里请注意一点 数据会同步过去的
1. primary节点信息
mysql> \s
--------------
/usr/local/mysql_8/bin/mysql Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)
.....
Server version: 8.0.27 MySQL Community Server - GPL
.......
UNIX socket: /data/mysql_mgr/3307/mysql.sock
mysql> select group_replication_get_communication_protocol();
+------------------------------------------------+
| group_replication_get_communication_protocol() |
+------------------------------------------------+
| 8.0.27 |
+------------------------------------------------+
1 row in set (0.00 sec)
mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+----------------------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+----------------------------+
| group_replication_applier | 57010c66-a103-11ec-9564-080027cdfa8a | mgr2 | 3307 | ONLINE | PRIMARY | 8.0.27 | XCom |
| group_replication_applier | a6c2031d-a103-11ec-879e-080027eef429 | mgr3 | 3307 | ONLINE | SECONDARY | 8.0.27 | XCom |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+----------------------------+
2 rows in set (0.00 sec)
2. 添加低版本实例
-
数据库状态
mysql> \s
--------------
/usr/local/mysql_8/bin/mysql Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)
....
Server version: 8.0.13 MySQL Community Server - GPL
........
Threads: 2 Questions: 9 Slow queries: 0 Opens: 127 Flush tables: 2 Open tables: 104 Queries per second avg: 0.180
--------------
mysql> select * from performance_schema.replication_group_members;
+---------------------------+-----------+-------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+-----------+-------------+-------------+--------------+-------------+----------------+
| group_replication_applier | | | NULL | OFFLINE | | |
+---------------------------+-----------+-------------+-------------+--------------+-------------+----------------+
1 row in set (0.00 sec)
-
加入前在 Prinary
插入一条数据
mysql> show master status;
+-----------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------+----------+--------------+------------------+------------------------------------------+
| mybinlog.000002 | 1795 | | | aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1:1-7 |
+-----------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)
mysql> insert into tb.t select 1;
Query OK, 1 row affected (0.01 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> show master status;
+-----------------+----------+--------------+------------------+-------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------+----------+--------------+------------------+-------------------------------------------+
| mybinlog.000002 | 2861 | | | aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1:1-10 |
+-----------------+----------+--------------+------------------+-------------------------------------------+
1 row in set (0.00 sec)
-
节点加入
mysql> show tables;
+--------------+
| Tables_in_tb |
+--------------+
| t |
+--------------+
1 row in set (0.00 sec)
mysql> select * from t;
Empty set (0.01 sec)
mysql> show master status;
+-----------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------+----------+--------------+------------------+------------------------------------------+
| mybinlog.000002 | 191 | | | aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1:1-7 |
+-----------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)
mysql> start group_replication;
Query OK, 0 rows affected (12.10 sec)
mysql> show master status;
+-----------------+----------+--------------+------------------+-------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------+----------+--------------+------------------+-------------------------------------------+
| mybinlog.000002 | 1252 | | | aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1:1-10 |
+-----------------+----------+--------------+------------------+-------------------------------------------+
1 row in set (0.00 sec)
mysql> select * from t;
+----+
| id |
+----+
| 1 |
+----+
1 row in set (0.00 sec)
mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
| group_replication_applier | d78a1230-a4e1-11ec-8bfc-080027d56d22 | mgr1 | 3308 | ERROR | | 8.0.13 |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
1 row in set (0.00 sec)
可以看到id=1
的数据是传过来的
再来看看日志:
显示MGR
初始化是成功的
2022-03-17T10:44:46.795361+08:00 8 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] Added automatically IP ranges 10.0.2.31/24,127.0.0.1/8 to the whitelist'
2022-03-17T10:44:46.795528+08:00 8 [Warning] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] Automatically adding IPv4 localhost address to the whitelist. It is mandatory that it is added.'
2022-03-17T10:44:46.795644+08:00 8 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] SSL was not enabled'
2022-03-17T10:44:46.795692+08:00 8 [Note] [MY-011694] [Repl] Plugin group_replication reported: 'Initialized group communication with configuration: group_replication_group_name: 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1'; group_replication_local_address: '10.0.2.31:33081'; group_replication_group_seeds: '10.0.2.31:33081,10.0.2.32:33071,10.0.2.33:33071'; group_replication_bootstrap_group: 'false'; group_replication_poll_spin_loops: 0; group_replication_compression_threshold: 1000000; group_replication_ip_whitelist: 'AUTOMATIC'; group_replication_communication_debug_options: 'GCS_DEBUG_NONE'; group_replication_member_expel_timeout: '0''
2022-03-17T10:44:46.795760+08:00 8 [Note] [MY-011643] [Repl] Plugin group_replication reported: 'Member configuration: member_id: 313308; member_uuid: "d78a1230-a4e1-11ec-8bfc-080027d56d22"; single-primary mode: "true"; group_replication_auto_increment_increment: 7; '
2022-03-17T10:44:46.796447+08:00 50 [System] [MY-010597] [Repl] 'CHANGE MASTER TO FOR CHANNEL 'group_replication_applier' executed'. Previous state master_host='<NULL>', master_port= 0, 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=''.
2022-03-17T10:44:46.808714+08:00 53 [Note] [MY-010581] [Repl] Slave SQL thread for channel 'group_replication_applier' initialized, starting replication in log 'FIRST' at position 0, relay log './mgr1-relay-bin-group_replication_applier.000003' position: 4
2022-03-17T10:44:46.808729+08:00 8 [Note] [MY-011670] [Repl] Plugin group_replication reported: 'Group Replication applier module successfully initialized!'
2022-03-17T10:44:46.809147+08:00 0 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] XCom protocol version: 5'
2022-03-17T10:44:46.809259+08:00 0 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] XCom initialized and ready to accept incoming connections on port 33081'
看下最后的报错信息
2022-03-17T10:44:58.943557+08:00 60 [Note] [MY-010581] [Repl] Slave SQL thread for channel 'group_replication_recovery' initialized, starting replication in log 'FIRST' at position 0, relay log './mgr1-relay-bin-group_replication_recovery.000001' position: 4
2022-03-17T10:44:58.982228+08:00 58 [Note] [MY-011585] [Repl] Plugin group_replication reported: 'Terminating existing group replication donor connection and purging the corresponding logs.'
2022-03-17T10:44:58.986682+08:00 60 [Note] [MY-010587] [Repl] Slave SQL thread for channel 'group_replication_recovery' exiting, replication stopped in log 'mybinlog.000002' at position 3480
2022-03-17T10:44:58.990491+08:00 59 [Note] [MY-011026] [Repl] Slave I/O thread killed while reading event for channel 'group_replication_recovery'.
2022-03-17T10:44:58.990577+08:00 59 [Note] [MY-010570] [Repl] Slave I/O thread exiting for channel 'group_replication_recovery', read up to log 'mybinlog.000002', position 3480
2022-03-17T10:44:59.029938+08:00 58 [System] [MY-010597] [Repl] 'CHANGE MASTER TO FOR CHANNEL 'group_replication_recovery' executed'. Previous state master_host='mgr3', master_port= 3307, 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=''.
2022-03-17T10:45:11.749695+08:00 0 [ERROR] [MY-011505] [Repl] Plugin group_replication reported: 'Member was expelled from the group due to network failures, changing member status to ERROR.'
2022-03-17T10:45:11.750399+08:00 0 [Note] [MY-011647] [Repl] Plugin group_replication reported: 'Going to wait for view modification'
大意是网络问题导致报错,然后等待集群更改集群信息视图(节点成员信息)
3. 解决办法
集群通信协议为8.0.27
,加入节点数据库版本为MySQL 8.0.13
协议版本为5.7.14
。这样就简单了,修改现有集群协议版本即可;
3.1 修改集群协议版本
mysql> select group_replication_set_communication_protocol('5.7.14');
+-----------------------------------------------------------------------------------+
| group_replication_set_communication_protocol('5.7.14') |
+-----------------------------------------------------------------------------------+
| The operation group_replication_set_communication_protocol completed successfully |
+-----------------------------------------------------------------------------------+
1 row in set (0.01 sec)
mysql> select group_replication_get_communication_protocol();
+------------------------------------------------+
| group_replication_get_communication_protocol() |
+------------------------------------------------+
| 5.7.14 |
+------------------------------------------------+
1 row in set (0.00 sec)
mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
| group_replication_applier | d78a1230-a4e1-11ec-8bfc-080027d56d22 | mgr1 | 3308 | ERROR | | 8.0.13 |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
1 row in set (0.00 sec)
mysql> stop group_replication;
Query OK, 0 rows affected (1.01 sec)
mysql> start group_replication;
Query OK, 0 rows affected (5.45 sec)
mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
| group_replication_applier | 57010c66-a103-11ec-9564-080027cdfa8a | mgr2 | 3307 | ONLINE | PRIMARY | 8.0.27 |
| group_replication_applier | a6c2031d-a103-11ec-879e-080027eef429 | mgr3 | 3307 | ONLINE | SECONDARY | 8.0.27 |
| group_replication_applier | d78a1230-a4e1-11ec-8bfc-080027d56d22 | mgr1 | 3308 | ONLINE | SECONDARY | 8.0.13 |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
3 rows in set (0.00 sec)
参考文章
mgr未同步 mysql_MGR优雅升级到MySQL8.0.16[3]
References
[1]
18.8.1.2 Group Replication Communication Protocol Version: https://dev.mysql.com/doc/refman/8.0/en/group-replication-compatibility-communication.html[2]
18.5.1.4 Setting a Group's Communication Protocol Version: https://dev.mysql.com/doc/refman/8.0/en/group-replication-communication-protocol.html[3]
mgr未同步 mysql_MGR优雅升级到MySQL8.0.16: https://blog.csdn.net/weixin_34060773/article/details/112150647