MySQL MGR 单组模式转换为多组模式

在之前的博客已经介绍了MGR单主模式的部署准备以及如何部署,这节内容为如何部署多主模式

MGR默认部署完后是单主模式,我们需要做些更改来切换到多主模式,切换需要重启引导组复制

我们假设已经搭建好了单主模式

 

检查当前模式


任意服务器 

mysql>  select * from performance_schema.replication_group_members;

+---------------------------+--------------------------------------+-------------+-------------+--------------+

| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |

+---------------------------+--------------------------------------+-------------+-------------+--------------+

| group_replication_applier | 18f5da07-a096-11ea-8c70-000c290e1abf | db01        |        3306 | ONLINE       |

| group_replication_applier | 7d3e894a-a0a9-11ea-82f8-000c29a7fff7 | db03        |        3306 | ONLINE       |

| group_replication_applier | dfe895a8-a0df-11ea-bb7d-000c296190c1 | db02        |        3306 | ONLINE       |

+---------------------------+--------------------------------------+-------------+-------------+--------------+

 

所有节点停止组复制 


在所有的节点执行,将组复制停止

mysql>  stop  group_replication;

 

Db01(单主模式里面的可读可写的引导组)


#将单组模式置为off状态,在数据库重启之后该参数失效,如果不想让其失效写到配置文件里面
mysql> show variables like '%group_replication_single_primary_mode%';
+---------------------------------------+-------+
| Variable_name                         | Value |
+---------------------------------------+-------+
| group_replication_single_primary_mode | ON    |
+---------------------------------------+-------+
set global group_replication_single_primary_mode=off;

#检查冲突,因为多主模式可能会产生冲突,比如在多个节点修改同一条记录,单组模式下是off状态,因为在多个节点进行写入操作可能会造成冲突
mysql> show variables like '%group_replication_enforce_update_everywhere_checks%';
+----------------------------------------------------+-------+
| Variable_name                                      | Value |
+----------------------------------------------------+-------+
| group_replication_enforce_update_everywhere_checks | OFF   |
+----------------------------------------------------+-------+
set global group_replication_enforce_update_everywhere_checks=ON;


#引导多主模式组
#设置为启动组,启动组复制,然后将其关闭,单组模式下也会执行该步骤,所以主要是设置上面两个参数
SET GLOBAL group_replication_bootstrap_group=ON;
START GROUP_REPLICATION;
SET GLOBAL group_replication_bootstrap_group=OFF;

mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 18f5da07-a096-11ea-8c70-000c290e1abf | db01        |        3306 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+

 

Db02  比上面少了启动引导组


set global group_replication_single_primary_mode=off;
set global group_replication_enforce_update_everywhere_checks=ON;
start group_replication;

select * from performance_schema.replication_group_members;

mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 18f5da07-a096-11ea-8c70-000c290e1abf | db01        |        3306 | ONLINE       |
| group_replication_applier | dfe895a8-a0df-11ea-bb7d-000c296190c1 | db02        |        3306 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+

 

Db03 照葫芦画瓢Db02


set global group_replication_single_primary_mode=off;

set global group_replication_enforce_update_everywhere_checks=ON;

start group_replication;



select * from performance_schema.replication_group_members;

mysql> select * from performance_schema.replication_group_members;

+---------------------------+--------------------------------------+-------------+-------------+--------------+

| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |

+---------------------------+--------------------------------------+-------------+-------------+--------------+

| group_replication_applier | 18f5da07-a096-11ea-8c70-000c290e1abf | db01        |        3306 | ONLINE       |

| group_replication_applier | 7d3e894a-a0a9-11ea-82f8-000c29a7fff7 | db03        |        3306 | ONLINE       |

| group_replication_applier | dfe895a8-a0df-11ea-bb7d-000c296190c1 | db02        |        3306 | ONLINE       |

+---------------------------+--------------------------------------+-------------+-------------+--------------+

 

测试


db01、db02、db03节点上:

create database db;

use db;

create table tbs01(id int primary key,name varchar(20));

insert into tbs01 values(1, 't1'); --db01节点执行

insert into tbs01 values(2, 't2'); --db02节点执行

insert into tbs01 values(3, 't3'); --db03节点执行

当环境搭建完三个节点是可以进行插入的,多主模式下所有节点可以进行写入

mysql> show variables like '%read_only%';  所有节点执行,可以看到相同结果

+-----------------------+-------+

| Variable_name         | Value |

+-----------------------+-------+

| innodb_read_only      | OFF   |

| read_only             | OFF   |

| super_read_only       | OFF   |

| transaction_read_only | OFF   |

| tx_read_only          | OFF   |

+-----------------------+-------+



可以看到在单组模式下通过修改两个参数就可以变为多组模式

 

 

你可能感兴趣的:(Mysql,mysql)