1. 程式人生 > >MGR 多主模式節點宕機重啟

MGR 多主模式節點宕機重啟

1,初始主節點宕機
當mysql服務程序還在:
執行如下命名 
mysql>  select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | efce3b94-e7ba-11e8-b99c-005056237187 | ndb01       |        3306 | ERROR        |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
發現叢集狀態已經為ERROR
停止同步服務程序執行
stop group_replication;
mysql>  select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | efce3b94-e7ba-11e8-b99c-005056237187 | ndb01       |        3306 | OFFLINE      |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
此時叢集狀態以為OFFLINE 
開啟同步程序 
start group_replication; 

mysql>  select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 3eae0abc-e7bb-11e8-8a21-0050562e92c0 | ndb02       |        3306 | ONLINE       |
| group_replication_applier | 46f558a2-e7bb-11e8-8ff9-0050563c8c87 | ndb03       |        3306 | ONLINE       |
| group_replication_applier | efce3b94-e7ba-11e8-b99c-005056237187 | ndb01       |        3306 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
所有節點均已上線
當mysql服務程序已死:
我們重啟mysql服務
[

[email protected] ~]# /etc/init.d/mysql.server start
mysql> select * from performance_schema.replication_group_members;
+---------------------------+-----------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+-----------+-------------+-------------+--------------+
| group_replication_applier |           |             |        NULL | OFFLINE      |
+---------------------------+-----------+-------------+-------------+--------------+
1 row in set (0.00 sec)
此時叢集狀態以為OFFLINE 
mysql> start group_replication;
Query OK, 0 rows affected (2.43 sec)

mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 3eae0abc-e7bb-11e8-8a21-0050562e92c0 | ndb02       |        3306 | ONLINE       |
| group_replication_applier | 46f558a2-e7bb-11e8-8ff9-0050563c8c87 | ndb03       |        3306 | ONLINE       |
| group_replication_applier | efce3b94-e7ba-11e8-b99c-005056237187 | ndb01       |        3306 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
3 rows in set (0.00 sec)
當所有節點重啟:
開始各個節點mysql服務
在各個節點執行
mysql> start group_replication;
^C^C -- query aborted
^C^C -- query aborted
^C^C -- query aborted
^C^C -- query aborted
^C^C -- query aborted
會卡主,日誌報
[ERROR] Plugin group_replication reported: '[GCS] The member was unable to join the group. Local port: 33061'

這任意節點執行:
mysql> SET GLOBAL group_replication_bootstrap_group = ON;  
Query OK, 0 rows affected (0.01 sec)

mysql> start group_replication;
Query OK, 0 rows affected (2.07 sec)

其餘節點:
mysql> start group_replication;
Query OK, 0 rows affected (2.07 sec)

mysql>  SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 3eae0abc-e7bb-11e8-8a21-0050562e92c0 | ndb02       |        3306 | ONLINE       |
| group_replication_applier | 46f558a2-e7bb-11e8-8ff9-0050563c8c87 | ndb03       |        3306 | ONLINE       |
| group_replication_applier | efce3b94-e7ba-11e8-b99c-005056237187 | ndb01       |        3306 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+

所有節點均已上線
2,初始從節點宕機
執行:
mysql> start group_replication;
Query OK, 0 rows affected (2.07 sec)
即可

總結:通過  SELECT * FROM performance_schema.replication_group_members;
查詢結果為OFFLINE  可以直接開啟服務
查詢結果為ERROR    停止叢集再開啟
所有節點都宕機需要 確定新的主節點引導叢集
SET GLOBAL group_replication_bootstrap_group = ON;
各節點start group_replication; 即可

 

如有問題探討,請加QQ群:695182221