## 1.概述 **MySQL 8.0.22 開始**,支持非同步連接故障切換機制,在現有主從複製連接失敗後,自動建立到新主的非同步複製連接。 **MySQL 8.0.23 開始**,非同步連接故障切換機制還支持組複製拓撲,通過自動監視組成員身份的更改並區分主節點和從節點,在組複製主節點故障選出新主節點後 ...
1.概述
MySQL 8.0.22 開始,支持非同步連接故障切換機制,在現有主從複製連接失敗後,自動建立到新主的非同步複製連接。
MySQL 8.0.23 開始,非同步連接故障切換機制還支持組複製拓撲,通過自動監視組成員身份的更改並區分主節點和從節點,在組複製主節點故障選出新主節點後,自動建立到新主的非同步複製連接。
MySQL 8.0.26 開始,組複製可以設置組成員在特定情況下採取的操作,比如成員操作 mysql_disable_super_read_only_if_primary
當選擇一個新的primary時,使處於單主模式的組保持超級只讀模式,這樣該組只接受複製的事務,不接受來自客戶端的任何直接寫操作。
MySQL 8.0.27 開始,非同步連接故障切換機制還允許組複製作為副本,組的主節點發生故障時,新的主節點自動重新連接到源端。新增成員操作mysql_start_failover_channels_if_primary
,預設情況下,此成員操作是啟用的,當啟用此成員動作時,在"CHANGE replication SOURCE TO"
語句中為複製通道設置SOURCE_CONNECTION_AUTO_FAILOVER=1
時,組複製主節點複製通道上的非同步連接故障轉移將激活。
2.架構
MGR B 作為 MGR A 的備份
本次測試通過搭建2套MGR作為主備集群,進行非同步連接故障切換測試:
(1)當主集群MGR A 的主節點發生故障時,備集群MGR B的主節點能夠實現非同步故障轉移,自動連接MGR A 的新主節點,主備集群同步不斷開,實現數據正常同步。
(2)當備集群MGR B 的主節點發生故障時,MGR B 的新主節點能夠自動啟動複製通道,自動連接MGR A 主節點,主備集群同步不斷開,實現數據正常同步。
(3)設置MGR B成員行為,使處於單主模式的組 MGR B 保持超級只讀模式,這樣該組只接受複製的事務,不接受來自客戶端的任何直接寫。
3.測試
本次測試基於 MySQL 8.0.31,搭建2套MGR集群(單主模式)
3.1 搭建MGR集群
MGR A:
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 | 44921323-bd95-11ed-8db5-00163e01f842 | 172.17.140.201 | 6002 | ONLINE | SECONDARY | 8.0.31 | XCom |
| group_replication_applier | 6f904c5c-bd95-11ed-bc79-00163e01f842 | 172.17.140.201 | 6003 | ONLINE | SECONDARY | 8.0.31 | XCom |
| group_replication_applier | c9e254d3-bd94-11ed-8ae9-00163e01f842 | 172.17.140.201 | 6001 | ONLINE | PRIMARY | 8.0.31 | XCom |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+
3 rows in set (0.01 sec)
MGR B:
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 | 190f4674-be4a-11ed-9452-00163ea5c598 | 172.17.140.252 | 6005 | ONLINE | PRIMARY | 8.0.31 | XCom |
| group_replication_applier | 3fa9e064-be4a-11ed-92c7-00163ea5c598 | 172.17.140.252 | 6006 | ONLINE | SECONDARY | 8.0.31 | XCom |
| group_replication_applier | 6a9691c6-be4a-11ed-8a32-00163ea5c598 | 172.17.140.252 | 6007 | ONLINE | SECONDARY | 8.0.31 | XCom |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+
3 rows in set (0.00 sec)
3.2 創建複製用戶
在MGR A 的主節點創建用於複製的用戶 repl_user
create user repl_user@'%' identified with mysql_native_password by 'abc123';
grant replication slave on *.* to repl_user@'%';
grant select on performance_schema.* to repl_user@'%';
註意:這裡複製用戶需要有 performance_schema
庫的select許可權,主要用於獲取MGR A集群成員的狀態,如果沒有這個許可權,將不能進行非同步連接故障轉移。
3.3停止MGR B的組複製
在MGR B的所有節點停止組複製,可先停止從節點,避免發生節點切換
mysql> stop group_replication;
註意:這裡停止組複製是為了下一步創建非同步複製通道,如果不停止複製通道,在運行正常的MGR B 的主節點執行創建複製通道的語句,會導致從節點退出組,報如下錯誤:
2023-03-09T14:38:51.933981+08:00 17887 [ERROR] [MY-013786] [Repl] Unable to set SOURCE_CONNECTION_AUTO_FAILOVER on a non-existent or misconfigured replication channel 'mgra_to_mgrb', please create the channel and rejoin the server to the group.
2023-03-09T14:38:51.934259+08:00 17887 [ERROR] [MY-013487] [Repl] Plugin group_replication reported: 'A message sent through the Group Replication message deliver service was not delivered successfully. The server will now leave the group. Try to add the server back to the group and check if the problem persists, or check previous messages in the log for hints of what could be the problem.'
2023-03-09T14:38:51.934704+08:00 17887 [ERROR] [MY-011712] [Repl] Plugin group_replication reported: 'The server was automatically set into read only mode after an error was detected.'
2023-03-09T14:38:55.166405+08:00 0 [System] [MY-011504] [Repl] Plugin group_replication reported: 'Group membership changed: This member has left the group.'
3.4創建非同步複製通道
在MGR B的所有節點創建非同步複製通道
change replication source to source_host='172.17.140.201',source_port=6001,source_user='repl_user',source_password='abc123',source_auto_position=1,source_connection_auto_failover=1,source_connect_retry=10,source_retry_count=3 for channel 'mgra_to_mgrb';
source_host
:MGR A 主節點的IPsource_port
:MGR A 主節點的埠source_connection_auto_failover=1
:表示開啟自動故障轉移功能。source_connect_retry
:指定複製副本在與源端的連接超時後重新連接嘗試之間的間隔(秒)。source_retry_count
:設置複製副本在連接到源超時後進行的最大重新連接嘗試次數。
3.5配置複製源
在MGR B 的主節點配置複製源
select asynchronous_connection_failover_add_managed('mgra_to_mgrb','GroupReplication','bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb','172.17.140.201',6001,'',90,50);
+-------------------------------------------------------------------------------------------------------------------------------------------------------+
| asynchronous_connection_failover_add_managed('mgra_to_mgrb','GroupReplication','bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb','172.17.140.201',6001,'',90,50) |
+-------------------------------------------------------------------------------------------------------------------------------------------------------+
| The UDF asynchronous_connection_failover_add_managed() executed successfully. |
+-------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.02 sec)
語法:
asynchronous_connection_failover_add_managed(channel, managed_type, managed_name, host, port, network_namespace, primary_weight, secondary_weight)
參數:
channel
:上面創建的複製通道名稱;managed_type
:管理服務的類型,當前可傳入的值必須是GroupReplication;managed_name
:管理組的識別符,即group_replication_group_name參數的值;host
:源端主機名;port
:源端埠號;network_namespace
:預留為將來使用,置空;primary_weight
:MGR主伺服器的權重,值為1到100,值越大,優先順序越高;secondary_weight
:MGR從伺服器的權重,值為1到100,值越大,優先順序越高;
3.6查看配置的用於非同步連接切換的複製源
mysql> select * from performance_schema.replication_asynchronous_connection_failover;
+--------------+----------------+------+-------------------+--------+--------------------------------------+
| CHANNEL_NAME | HOST | PORT | NETWORK_NAMESPACE | WEIGHT | MANAGED_NAME |
+--------------+----------------+------+-------------------+--------+--------------------------------------+
| mgra_to_mgrb | 172.17.140.201 | 6001 | | 50 | bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb |
+--------------+----------------+------+-------------------+--------+--------------------------------------+
1 row in set (0.00 sec)
這裡只顯示剛纔配置的一個節點,啟動非同步複製通道後就能看到MGR A所有節點。
3.7啟動 MGR B 組複製
在MGR B 的主節點重新引導啟動組複製
# 選一個節點作為引導節點
set global group_replication_bootstrap_group=ON;
start group_replication;
set global group_replication_bootstrap_group=OFF;
# 其餘節點啟動組複製
start group_replication;
# 查看MGR B集群狀態
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+
| group_replication_applier | 190f4674-be4a-11ed-9452-00163ea5c598 | 172.17.140.252 | 6005 | ONLINE | PRIMARY | 8.0.31 | XCom |
| group_replication_applier | 3fa9e064-be4a-11ed-92c7-00163ea5c598 | 172.17.140.252 | 6006 | ONLINE | SECONDARY | 8.0.31 | XCom |
| group_replication_applier | 6a9691c6-be4a-11ed-8a32-00163ea5c598 | 172.17.140.252 | 6007 | ONLINE | SECONDARY | 8.0.31 | XCom |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+
3 rows in set (0.00 sec)
3.8啟動非同步複製通道
在MGR B的主節點啟動
mysql> start replica for channel 'mgra_to_mgrb';
mysql> show replica status\G
*************************** 1. row ***************************
Replica_IO_State: Waiting for source to send event
Source_Host: 172.17.140.201
Source_User: repl_user
Source_Port: 6001
Connect_Retry: 10
Source_Log_File: binlog.000001
Read_Source_Log_Pos: 2614
Relay_Log_File: relaylog-mgra_to_mgrb.000002
Relay_Log_Pos: 2816
Relay_Source_Log_File: binlog.000001
Replica_IO_Running: Yes
Replica_SQL_Running: Yes
Replicate_Do_DB:
非同步複製通道運行正常,至此MGR A 與 MGR B已建立主備關係,MGR A主節點與 MGR B 主節點建立非同步複製通道。
3.9查看配置的用於非同步連接切換的複製源
mysql> select * from performance_schema.replication_asynchronous_connection_failover;
+--------------+----------------+------+-------------------+--------+--------------------------------------+
| CHANNEL_NAME | HOST | PORT | NETWORK_NAMESPACE | WEIGHT | MANAGED_NAME |
+--------------+----------------+------+-------------------+--------+--------------------------------------+
| mgra_to_mgrb | 172.17.140.201 | 6001 | | 90 | bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb |
| mgra_to_mgrb | 172.17.140.201 | 6002 | | 50 | bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb |
| mgra_to_mgrb | 172.17.140.201 | 6003 | | 50 | bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb |
+--------------+----------------+------+-------------------+--------+--------------------------------------+
3 rows in set (0.01 sec)
可以看到這裡顯示了 MGR A的所有節點信息,weight 最高的為主節點
3.10故障模擬:主集群MGR A 的主節點發生故障
(1)查看當前MGR A 信息
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 | 44921323-bd95-11ed-8db5-00163e01f842 | 172.17.140.201 | 6002 | ONLINE | SECONDARY | 8.0.31 | XCom |
| group_replication_applier | 6f904c5c-bd95-11ed-bc79-00163e01f842 | 172.17.140.201 | 6003 | ONLINE | SECONDARY | 8.0.31 | XCom |
| group_replication_applier | c9e254d3-bd94-11ed-8ae9-00163e01f842 | 172.17.140.201 | 6001 | ONLINE | PRIMARY | 8.0.31 | XCom |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+
3 rows in set (0.00 sec)
當前MGR A 主節點為 6001
(2)查看非同步複製信息
登錄MGR B 主節點查看
mysql> show replica status\G
*************************** 1. row ***************************
Replica_IO_State: Waiting for source to send event
Source_Host: 172.17.140.201
Source_User: repl_user
Source_Port: 6001
Connect_Retry: 10
Source_Log_File: binlog.000001
Read_Source_Log_Pos: 2614
Relay_Log_File: relaylog-mgra_to_mgrb.000002
Relay_Log_Pos: 2816
Relay_Source_Log_File: binlog.000001
Replica_IO_Running: Yes
Replica_SQL_Running: Yes
Replicate_Do_DB:
當前MGR B主節點 連接的是 MGR A的主節點 6001
(3)模擬MGR A故障
在MGR A主節點執行切主命令,模擬MGR A主節點故障,將6002設置為新主節點
mysql> select group_replication_set_as_primary('44921323-bd95-11ed-8db5-00163e01f842');
+--------------------------------------------------------------------------+
| group_replication_set_as_primary('44921323-bd95-11ed-8db5-00163e01f842') |
+--------------------------------------------------------------------------+
| Primary server switched to: 44921323-bd95-11ed-8db5-00163e01f842 |
+--------------------------------------------------------------------------+
1 row in set (0.04 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 | 44921323-bd95-11ed-8db5-00163e01f842 | 172.17.140.201 | 6002 | ONLINE | PRIMARY | 8.0.31 | XCom |
| group_replication_applier | 6f904c5c-bd95-11ed-bc79-00163e01f842 | 172.17.140.201 | 6003 | ONLINE | SECONDARY | 8.0.31 | XCom |
| group_replication_applier | c9e254d3-bd94-11ed-8ae9-00163e01f842 | 172.17.140.201 | 6001 | ONLINE | SECONDARY | 8.0.31 | XCom |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+
3 rows in set (0.00 sec)
(4)查看非同步複製信息
登錄MGR B 主節點查看
mysql> show replica status\G
*************************** 1. row ***************************
Replica_IO_State: Waiting for source to send event
Source_Host: 172.17.140.201
Source_User: repl_user
Source_Port: 6002
Connect_Retry: 10
Source_Log_File: binlog.000001
Read_Source_Log_Pos: 3343
Relay_Log_File: relaylog-mgra_to_mgrb.000003
Relay_Log_Pos: 435
Relay_Source_Log_File: binlog.000001
Replica_IO_Running: Yes
Replica_SQL_Running: Yes
Replicate_Do_DB:
可以看到MGR B主節點已經自動進行非同步連接故障轉移,與MGR A新主節點6002建立連接並且連接正常,在此過程中並不需要人為去操作。
3.11故障模擬:備集群MGR B 的主節點發生故障
(1)查看當前MGR B信息
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 | 190f4674-be4a-11ed-9452-00163ea5c598 | 172.17.140.252 | 6005 | ONLINE | PRIMARY | 8.0.31 | XCom |
| group_replication_applier | 3fa9e064-be4a-11ed-92c7-00163ea5c598 | 172.17.140.252 | 6006 | ONLINE | SECONDARY | 8.0.31 | XCom |
| group_replication_applier | 6a9691c6-be4a-11ed-8a32-00163ea5c598 | 172.17.140.252 | 6007 | ONLINE | SECONDARY | 8.0.31 | XCom |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+
3 rows in set (0.03 sec)
(2)查看非同步複製信息
- 登錄MGR B主節點6005
mysql> show replica status\G
*************************** 1. row ***************************
Replica_IO_State: Waiting for source to send event
Source_Host: 172.17.140.201
Source_User: repl_user
Source_Port: 6002
Connect_Retry: 10
Source_Log_File: binlog.000001
Read_Source_Log_Pos: 3343
Relay_Log_File: relaylog-mgra_to_mgrb.000003
Relay_Log_Pos: 435
Relay_Source_Log_File: binlog.000001
Replica_IO_Running: Yes
Replica_SQL_Running: Yes
Replicate_Do_DB:
當前MGR B主節點與MGR A新主節點6002 非同步複製連接正常
- 登錄MGR B從節點6006
mysql> show replica status\G
*************************** 1. row ***************************
Replica_IO_State:
Source_Host: 172.17.140.201
Source_User: repl_user
Source_Port: 6001
Connect_Retry: 10
Source_Log_File:
Read_Source_Log_Pos: 4
Relay_Log_File: relaylog-mgra_to_mgrb.000001
Relay_Log_Pos: 4
Relay_Source_Log_File:
Replica_IO_Running: No
Replica_SQL_Running: No
Replicate_Do_DB:
(3)模擬MGR B主節點故障
這裡不能通過對MGR B執行切主命令模擬故障,會報如下錯誤:
mysql> select group_replication_set_as_primary('3fa9e064-be4a-11ed-92c7-00163ea5c598');
ERROR 3910 (HY000): The function 'group_replication_set_as_primary' failed. There is a slave channel running in the group's current primary member.
我們通過停止組複製讓MGR B主節點6005主動退出組,模擬故障
mysql> stop group_replication;
Query OK, 0 rows affected (11.67 sec)
(4)查看當前MGR B信息
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 | 3fa9e064-be4a-11ed-92c7-00163ea5c598 | 172.17.140.252 | 6006 | ONLINE | PRIMARY | 8.0.31 | XCom |
| group_replication_applier | 6a9691c6-be4a-11ed-8a32-00163ea5c598 | 172.17.140.252 | 6007 | ONLINE | SECONDARY | 8.0.31 | XCom |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+
2 rows in set (0.00 sec)
當前MGR B發生切主,新主節點為6006
(5)查看非同步複製信息
登錄MGR B新主節點6006
mysql> show replica status\G
*************************** 1. row ***************************
Replica_IO_State: Waiting for source to send event
Source_Host: 172.17.140.201
Source_User: repl_user
Source_Port: 6002
Connect_Retry: 10
Source_Log_File: binlog.000001
Read_Source_Log_Pos: 3343
Relay_Log_File: relaylog-mgra_to_mgrb.000002
Relay_Log_Pos: 395
Relay_Source_Log_File: binlog.000001
Replica_IO_Running: Yes
Replica_SQL_Running: Yes
Replicate_Do_DB:
可以看到MGR B新主節點已經自動進行非同步連接故障轉移,與MGR A主節點6002建立連接並且連接正常,在此過程中並不需要人為去操作。
3.12 設置備集群MGR B為超級只讀模式
配置MGR B集群所有節點為超級只讀模式,避免執行誤操作。預設情況下,MGR單主模式下主節點為讀寫模式,從節點為超級只讀模式。
當一個組只是作為另一個組的備份的時候,只需要執行複製事物就可以了,不需要登錄執行其他客戶端事物,避免造成數據不一致的問題。因此我們可以通過 group_replication_disable_member_action()
函數設置成員操作,將備集群所有節點設置為超級只讀模式,即使切主後選出新的主節點也要保持超級只讀模式。
(1)查看MGR B當前成員操作
mysql> select * from replication_group_member_actions;
+------------------------------------------+------------------------+---------+----------+----------+----------------+
| name | event | enabled | type | priority | error_handling |
+------------------------------------------+------------------------+---------+----------+----------+----------------+
| mysql_disable_super_read_only_if_primary | AFTER_PRIMARY_ELECTION | 1 | INTERNAL | 1 | IGNORE |
| mysql_start_failover_channels_if_primary | AFTER_PRIMARY_ELECTION | 1 | INTERNAL | 10 | CRITICAL |
+------------------------------------------+------------------------+---------+----------+----------+----------------+
2 rows in set (0.02 sec)
(2)設置MGR B為超級只讀模式
mysql> SELECT group_replication_disable_member_action("mysql_disable_super_read_only_if_primary", "AFTER_PRIMARY_ELECTION");
+---------------------------------------------------------------------------------------------------------------+
| group_replication_disable_member_action("mysql_disable_super_read_only_if_primary", "AFTER_PRIMARY_ELECTION") |
+---------------------------------------------------------------------------------------------------------------+
| OK |
+---------------------------------------------------------------------------------------------------------------+
1 row in set (0.04 sec)
註意:這裡執行完此函數後,不會對當前主節點產生影響,當發生切主選擇出新主節點後,會將新主節點設置為超級只讀模式。
(3)停止MGR B主節點
mysql> stop group_replication;
Query OK, 0 rows affected (28.54 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 | 190f4674-be4a-11ed-9452-00163ea5c598 | 172.17.140.252 | 6005 | ONLINE | PRIMARY | 8.0.31 | XCom |
| group_replication_applier | 6a9691c6-be4a-11ed-8a32-00163ea5c598 | 172.17.140.252 | 6007 | ONLINE | SECONDARY | 8.0.31 | XCom |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+
2 rows in set (0.01 sec)
MGR B新主節點為 6005
(4)查看MGR B新主節點是否進入超級只讀模式
mysql> show variables like 'super_read_only';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| super_read_only | ON |
+-----------------+-------+
1 row in set (0.05 sec)
mysql> create database tt;
ERROR 1290 (HY000): The MySQL server is running with the --super-read-only option so it cannot execute this statement
此時新主節點處於超級只讀模式,不允許用戶執行操作。
4.總結
通過非同步連接故障切換機制,當複製連接出現問題時,不需要人工介入手動去重新建立複製連接,副本會自動進行非同步故障轉移與新的節點建立連接。
非同步複製通道的建立只能在2個MGR集群的主節點上。
5.參考文檔
-
https://dev.mysql.com/doc/refman/8.0/en/replication-asynchronous-connection-failover.html
-
https://dev.mysql.com/doc/refman/8.0/en/replication-asynchronous-connection-failover-replica.html
Enjoy GreatSQL