你好,游客 登录 注册 搜索
背景:
阅读新闻

MySQL 5.7.17 Group Relication(组复制)搭建手册

[日期:2017-03-30] 来源:Linux社区  作者:Fantasy life [字体: ]

本文介绍了Group Replication的两种工作模式的架构介绍。
并详细介绍了
Single-Master Mode的部署过程,以及如何切换到Multi-Master Mode
当然,文末给出了Group Replication的配置要求和一些限制。


〇 结构介绍

在2016年12月发布的5.7.17版本的MySQL,甲骨文宣布Group Replication已经GA。

Group Replication(下简称GR)有两个工作模式,分别为S
ingle-Master Mode与Multi-Master Mode:


Single-Master Modefailover图:

只有primary成员可读写,而其他的节点为只读,在primary成员发生故障时,将会有其他成员顶替成primary。


Multi-Master Mode的failover图:



所有的成员均可读可写。


关于脑裂问题,可发现MySQL Group Replication与MongoDB Relicate Set有相似之处:

和MongoDB的Relicate Set相近,其读写库类似于Primary,只读库类似于Secondary。

(下图来自MySQL官方)


(下图来自MongoDB 3.4 Manual)







〇 部署

测试实例数量:3台
版本:MySQL 5.7.17


安装(此处用的是二进制包安装)
mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz


创建数据目录及日志目录:

  1. mkdir -p /data/mysql57/mysql3306
  2. mkdir -p /data/mysql57/mysql3307
  3. mkdir -p /data/mysql57/mysql3308
  4. mkdir -p /data/mysql57/logs/3306
  5. mkdir -p /data/mysql57/logs/3307
  6. mkdir -p /data/mysql57/logs/3308

解压二进制包并将其设置为basedir:

  1. mv mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz /data/mysql57
  2. cd /data/mysql57
  3. tar zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
  4. mv mysql-5.7.17-linux-glibc2.5-x86_64 mysql-basedir




〇 添加第一台实例:
添加3306实例的配置文件:

  1. vim /data/mysql57/mysql3306/3306.cnf
  2. [client]
  3. prompt = "(\u@\h) [\d]> "
  4. [mysqld]
  5. server_id = 3306
  6. user = mysql
  7. port = 3306
  8. socket = /tmp/mysql3306.sock
  9. basedir = /data/mysql57/mysql-basedir
  10. datadir = /data/mysql57/mysql3306
  11. pid-file = /data/mysql57/mysql3306/3306.pid
  12. log-error = /data/mysql57/logs/3306/error-log
  13. log-bin = /data/mysql57/logs/3306/binlog
  14. log-bin-index = /data/mysql57/logs/3306/binlog.index
  15. relay-log = /data/mysql57/logs/3306/relaylog
  16. relay-log-index = /data/mysql57/logs/3306/relaylog.index
  17. master_info_repository = TABLE
  18. relay_log_info_repository = TABLE
  19. log_slave_updates = ON
  20. binlog_checksum = NONE
  21. binlog_format = ROW
  22. transaction_isolation = READ-COMMITTED
  23. gtid_mode = ON
  24. enforce_gtid_consistency = ON
  25. # GR 配置项 其中loose前缀表示若Group Replication plugin未加载 mysql server仍继续启动
  26. transaction_write_set_extraction = XXHASH64
  27. loose-group_replication_group_name = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"    # 组名,此处可拿select uuid();生成
  28. loose-group_replication_start_on_boot = off    # 在mysqld启动时不自动启动组复制
  29. loose-group_replication_local_address = "127.0.0.1:24901"
  30. loose-group_replication_group_seeds = "127.0.0.1:24901,127.0.0.1:24902,127.0.0.1:24903"   
  31. loose-group_replication_bootstrap_group = off    



初始化3306实例datadir:

  1. /data/mysql57/mysql-basedir/bin/mysqld --defaults-file=/data/mysql57/3306.cnf --initialize-insecure

启动3306实例:

  1. /data/mysql57/mysql-basedir/bin/mysqld --defaults-file=/data/mysql57/3306.cnf &

通过MySQL Client进入第一个实例(密码为空)

  1. /data/mysql57/mysql-basedir/bin/mysql -uroot -p -S /tmp/mysql3306.sock

创建复制用户与授权,并让其作为group的第一个成员:

  1. SET SQL_LOG_BIN=0;
  2. CREATE USER repl@'%';
  3. GRANT REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY 'repl@123';
  4. FLUSH PRIVILEGES;
  5. SET SQL_LOG_BIN=1;
  6. CHANGE MASTER TO MASTER_USER='repl', MASTER_PASSWORD='repl@123' FOR CHANNEL 'group_replication_recovery';

安装GR插件:

  1. (root@localhost) [(none)]> INSTALL PLUGIN group_replication SONAME 'group_replication.so';
  2. Query OK, 0 rows affected (0.07 sec)

可以检查一下是否安装成功:

  1. (root@localhost) [(none)]> SELECT * FROM information_schema.plugins WHERE PLUGIN_NAME LIKE '%group%'\G
  2. *************************** 1. row ***************************
  3.            PLUGIN_NAME: group_replication
  4.         PLUGIN_VERSION: 1.0
  5.          PLUGIN_STATUS: ACTIVE
  6.            PLUGIN_TYPE: GROUP REPLICATION
  7.    PLUGIN_TYPE_VERSION: 1.1
  8.         PLUGIN_LIBRARY: group_replication.so
  9. PLUGIN_LIBRARY_VERSION: 1.7
  10.          PLUGIN_AUTHOR: Oracle
  11.     PLUGIN_DESCRIPTION: Group Replication (1.0.0)
  12.         PLUGIN_LICENSE: GPL
  13.            LOAD_OPTION: ON
  14. 1 row in set (0.00 sec)

开启第一个组复制:

  1. (root@localhost) [(none)]> SET GLOBAL group_replication_bootstrap_group=ON;
  2. Query OK, 0 rows affected (0.00 sec)
  3. (root@localhost) [(none)]> START GROUP_REPLICATION;
  4. Query OK, 0 rows affected (1.20 sec)
  5. # 启动组复制之后将group_replication_bootstrap_group设置为OFF
  6. # This option must only be set on one server and only when starting the group for the first time or restarting the entire group. After the group has been bootstrapped, set this option to OFF. It should be set to OFF both dynamically and in the configuration files
  7.  
  8. (root@localhost) [(none)]> SET GLOBAL group_replication_bootstrap_group=OFF;
  9. Query OK, 0 rows affected (0.01 sec)

检查一下组复制成员,其中member_id就是@@server_uuid的值

  1. (root@localhost) [(none)]> SELECT * FROM performance_schema.replication_group_members;
  2. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  3. | CHANNEL_NAME             | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
  4. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  5. | group_replication_applier | 3dc9cf4a-ec61-11e6-bdf3-000c297f23b7 | sAno1y     | 3306        | ONLINE       |
  6. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  7. 1 row in set (0.00 sec)

添加测试数据:

  1. (root@localhost) [(none)]> CREATE DATABASE test;
  2. Query OK, 1 row affected (0.00 sec)
  3. (root@localhost) [(none)]> USE test;
  4. Database changed
  5. (root@localhost) [test]> CREATE TABLE tb_test(id int PRIMARY KEY, name varchar(20)) CHARACTER SET utf8;
  6. Query OK, 0 rows affected (0.04 sec)
  7. (root@localhost) [test]> INSERT INTO tb_test VALUES(1,'风暴之灵');
  8. Query OK, 1 row affected (0.00 sec)
  9. (root@localhost) [test]> INSERT INTO tb_test VALUES(2,'影之灵龛');
  10. Query OK, 1 row affected (0.01 sec)
  11. (root@localhost) [test]> UPDATE tb_test SET name='斯嘉蒂之眼' WHERE id=2;
  12. Query OK, 1 row affected (0.02 sec)
  13. Rows matched: 1 Changed: 1 Warnings: 0
  14. (root@localhost) [test]> SELECT * FROM tb_test;
  15. +----+-----------------+
  16. | id | name           |
  17. +----+-----------------+
  18. | 1  | 风暴之灵        |
  19. | 2  | 斯嘉蒂之眼       |
  20. +----+-----------------+
  21. 2 rows in set (0.00 sec)

添加第二个实例(3307)
修改3307配置文件,将3306改成3307,并且将loose-group_replication_local_address的端口从24901改成24902

  1. cp /data/mysql57/3306.cnf /data/mysql57/3307.cnf
  2. sed -i "s/3306/3307/g" /data/mysql57/3307.cnf
  3. sed -i "s/24901\"/24902\"/g" 3307.cnf



初始化3307实例:

  1. /data/mysql57/mysql-basedir/bin/mysqld --defaults-file=/data/mysql57/3307.cnf --initialize-insecure

启动3307实例:

  1. /data/mysql57/mysql-basedir/bin/mysqld --defaults-file=/data/mysql57/3307.cnf &



通过MySQL Client进入3307实例:

  1. /data/mysql57/mysql-basedir/bin/mysql -uroot -p -S /tmp/mysql3307.sock

重复在3306实例的操作:

  1. SET SQL_LOG_BIN=0;
  2. CREATE USER repl@'%';
  3. GRANT REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY 'repl@123';
  4. FLUSH PRIVILEGES;
  5. SET SQL_LOG_BIN=1;
  6. CHANGE MASTER TO MASTER_USER='repl', MASTER_PASSWORD='repl@123' FOR CHANNEL 'group_replication_recovery';

在3307实例上安装GR插件,开启组复制:

  1. (root@localhost) [(none)]> INSTALL PLUGIN group_replication SONAME 'group_replication.so';
  2. Query OK, 0 rows affected (0.00 sec)
  3. (root@localhost) [(none)]> START GROUP_REPLICATION;
  4. Query OK, 0 rows affected (5.61 sec)

检查一下成员状态:

  1. (root@localhost) [(none)]> SELECT * FROM performance_schema.replication_group_members;
  2. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  3. | CHANNEL_NAME             | MEMBER_ID                           | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
  4. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  5. | group_replication_applier | 3dc9cf4a-ec61-11e6-bdf3-000c297f23b7 | sAno1y     | 3306        | ONLINE       |
  6. | group_replication_applier | 6bddae0d-eca1-11e6-b9d5-000c297f23b7 | sAno1y     | 3307        | RECOVERING   |
  7. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  8. 2 rows in set (0.00 sec)

过了一阵子再检查,仍然是RECOVERING。


再过一阵子检查,发现member_state被置为ERROR:

  1. (root@localhost) [(none)]> SELECT * FROM performance_schema.replication_group_members;
  2. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  3. | CHANNEL_NAME              | MEMBER_ID                           | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
  4. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  5. | group_replication_applier | 6bddae0d-eca1-11e6-b9d5-000c297f23b7 | sAno1y     | 3307        | ERROR        |
  6. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  7. 1 row in set (0.01 sec)

此时检查3306实例的组复制情况,发现检查不到另一个实例的信息了:

  1. (root@localhost) [(none)]> SELECT * FROM performance_schema.replication_group_members;
  2. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  3. | CHANNEL_NAME             | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
  4. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  5. | group_replication_applier | 3dc9cf4a-ec61-11e6-bdf3-000c297f23b7 | sAno1y     | 3306        | ONLINE       |
  6. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  7. 1 row in set (0.00 sec)

开多一个终端,检查3307实例的error log发现:

  1. 2017-02-07T12:06:21.674093Z 47 [ERROR] Slave I/O for channel 'group_replication_recovery': error connecting to master 'repl@sAno1y:3306' - retry-time: 60 retries: 1, Error_code: 2005

应该是解析的问题,修改hosts文件,在末尾加上主机名:

  1. [root@sAno1y 3307]# hostname
  2. sAno1y
  3. [root@sAno1y 3307]# cat /etc/hosts
  4. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 sAno1y
  5. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 sAno1y

重新操作3307实例:

  1. (root@localhost) [(none)]> STOP GROUP_REPLICATION;
  2. Query OK, 0 rows affected (0.00 sec)
  3. (root@localhost) [(none)]> START GROUP_REPLICATION;
  4. Query OK, 0 rows affected (7.80 sec)

检查组复制状态,发现两个实例的状态均为ONLINE了:

  1. (root@localhost) [(none)]> SELECT * FROM performance_schema.replication_group_members;
  2. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  3. | CHANNEL_NAME             | MEMBER_ID                           | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
  4. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  5. | group_replication_applier | 3dc9cf4a-ec61-11e6-bdf3-000c297f23b7 | sAno1y     | 3306        | ONLINE       |
  6. | group_replication_applier | 6bddae0d-eca1-11e6-b9d5-000c297f23b7 | sAno1y     | 3307        | ONLINE       |
  7. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  8. 2 rows in set (0.00 sec)

在3307上检查一下同步状态:

  1. (root@localhost) [(none)]> SELECT * FROM test.tb_test;
  2. +----+-----------------+
  3. | id | name           |
  4. +----+-----------------+
  5. | 1  | 风暴之灵         |
  6. | 2  | 斯嘉蒂之眼       |
  7. +----+-----------------+
  8. 2 rows in set (0.00 sec)

添加3308实例:
修改3308配置文件:

  1. cp /data/mysql57/3306.cnf /data/mysql57/3308.cnf
  2. sed -i "s/3306/3308/g" 3308.cnf
  3. sed -i "s/24901\"/24093\"/g" 3308.cnf

然后初始化并启动3308实例:

  1. /data/mysql57/mysql-basedir/bin/mysqld --defaults-file=/data/mysql57/3308.cnf --initialize-insecure
  2. /data/mysql57/mysql-basedir/bin/mysqld --defaults-file=/data/mysql57/3308.cnf &



同样进入3308实例:

  1. /data/mysql57/mysql-basedir/bin/mysql -uroot -p -S /tmp/mysql3308.sock



在3308实例上重复操作:

  1. SET SQL_LOG_BIN=0;
  2. CREATE USER repl@'%';
  3. GRANT REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY 'repl@123';
  4. FLUSH PRIVILEGES;
  5. SET SQL_LOG_BIN=1;
  6. CHANGE MASTER TO MASTER_USER='repl', MASTER_PASSWORD='repl@123' FOR CHANNEL 'group_replication_recovery';

继续重复操作,安装GR插件并启动它:

  1. INSTALL PLUGIN group_replication SONAME 'group_replication.so';
  2. START GROUP_REPLICATION;

最后再检查一下组复制成员的状态:

  1. (root@localhost) [(none)]> SELECT * FROM performance_schema.replication_group_members;
  2. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  3. | CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
  4. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  5. | group_replication_applier | 3dc9cf4a-ec61-11e6-bdf3-000c297f23b7 | sAno1y     | 3306        | ONLINE       |
  6. | group_replication_applier | 6bddae0d-eca1-11e6-b9d5-000c297f23b7 | sAno1y     | 3307        | ONLINE       |
  7. | group_replication_applier | 6ce8c980-ed4a-11e6-bf00-000c297f23b7 | sAno1y     | 3308        | ONLINE       |
  8. +---------------------------+--------------------------------------+-------------+-------------+--------------+
  9. 3 rows in set (0.00 sec)

当然在3308实例上也已将3306的事务apply过来了:

  1. (root@localhost) [(none)]> SELECT * FROM test.tb_test;
  2. +----+-----------------+
  3. | id | name           |
  4. +----+-----------------+
  5. | 1  | 风暴之灵         |
  6. | 2  | 斯嘉蒂之眼       |
  7. +----+-----------------+
  8. 2 rows in set (0.00 sec)

root@localhost用户在上述操作中为空密码,可以给root@localhost加个密码……
因为三个实例都在一个GR组里,所以对3306实例操作就行了:

  1. /data/mysql57/mysql-basedir/bin/mysql -uroot -p -S /tmp/mysql3306.sock -e "ALTER USER root@localhost IDENTIFIED BY 'root123';"



当然ALTER操作会被记录到3306的binlog里,并
同步到3307和3308实例上。



可以查看一下三台实例的read_only和super-read-only值:

  1. [root@sAno1y mysql57]# /data/mysql57/mysql-basedir/bin/mysql -uroot -proot123 -S /tmp/mysql3306.sock -e "SELECT @@read_only, @@super_read_only";
  2. mysql: [Warning] Using a password on the command line interface can be insecure.
  3. +-------------+-------------------+
  4. | @@read_only | @@super_read_only  |
  5. +-------------+-------------------+
  6. | 0           | 0                 |
  7. +-------------+-------------------+
  8. [root@sAno1y mysql57]# /data/mysql57/mysql-basedir/bin/mysql -uroot -proot123 -S /tmp/mysql3307.sock -e "SELECT @@read_only, @@super_read_only";
  9. mysql: [Warning] Using a password on the command line interface can be insecure.
  10. +-------------+-------------------+
  11. | @@read_only | @@super_read_only  |
  12. +-------------+-------------------+
  13. | 1           | 1                |
  14. +-------------+-------------------+
  15. [root@sAno1y mysql57]# /data/mysql57/mysql-basedir/bin/mysql -uroot -proot123 -S /tmp/mysql3308.sock -e "SELECT @@read_only, @@super_read_only";
  16. mysql: [Warning] Using a password on the command line interface can be insecure.
  17. +-------------+-------------------+
  18. | @@read_only | @@super_read_only  |
  19. +-------------+-------------------+
  20. | 1           | 1                 |
  21. +-------------+-------------------+

可以发现只有3306实例也就是第一个实例属于可写实例,而3307和3308均为read-only模式。
决定因素为第一个加入该GR组的成员,之后加入该GR组的均为ro,在该模式与MongoDB Replicate Set很相似。


当然如果要确定哪一个成员是primary,可以在三个成员中的任意一个执行:

  1. SELECT b.member_id, b.member_host, b.member_port
  2. FROM performance_schema.global_status a
  3. JOIN performance_schema.replication_group_members b
  4. ON a.variable_value = b.member_id
  5. WHERE a.variable_name= 'group_replication_primary_member';
  6. # 输出结果:
  7. +--------------------------------------+-------------+-------------+
  8. | member_id                            | member_host | member_port |
  9. +--------------------------------------+-------------+-------------+
  10. | 3dc9cf4a-ec61-11e6-bdf3-000c297f23b7 | sAno1y      | 3306        |
  11. +--------------------------------------+-------------+-------------+
  12. 1 row in set (0.00 sec)

至此,Group Replication默认的single-master mode已经搭建完毕。




〇 将Single-Master Mode修改为Multi-Master Mode

如果要将Single-Master Mode修改为Multi-Master Mode,也比较简单。
考虑到此时的Primary成员是3306,并且假定3306实例在对外提供写服务,我这边的操作如下:


首先停掉两个secondary的组复制,在3307和3308实例上操作

  1. STOP GROUP_REPLICATION;
  2. SET GLOBAL group_replication_single_primary_mode=FALSE;
  3. SET GLOBAL group_replication_enforce_update_everywhere_checks=TRUE;

再在3306实例上重复以上操作:

  1. STOP GROUP_REPLICATION;
  2. SET GLOBAL group_replication_single_primary_mode=FALSE;
  3. SET GLOBAL group_replication_enforce_update_everywhere_checks=TRUE;

然后在3306上作为第一个成员启动组复制:

  1. (root@localhost) [(none)]> SET GLOBAL group_replication_bootstrap_group=on;
  2. Query OK, 0 rows affected (0.00 sec)
  3. (root@localhost) [(none)]> START GROUP_REPLICATION;
  4. Query OK, 0 rows affected (1.05 sec)
  5. (root@localhost) [(none)]> SET GLOBAL group_replication_bootstrap_group=off;
  6. Query OK, 0 rows affected (0.00 sec)

在停启组复制的过程中,3306实例仍对外提供服务,此处模拟修改:

  1. (root@localhost) [(none)]> UPDATE test.tb_test SET name='灵魂守卫' WHERE id=1;
  2. Query OK, 1 row affected (0.02 sec)
  3. Rows matched: 1 Changed: 1 Warnings: 0
  4. (root@localhost) [(none)]> INSERT INTO test.tb_test VALUES(3,'幻影斧');
  5. Query OK, 1 row affected (0.00 sec)
  6. (root@localhost) [(none)]> SELECT * FROM test.tb_test;
  7. +----+-----------------+
  8. | id | name            |
  9. +----+-----------------+
  10. | 1  | 灵魂守卫         |
  11. | 2  | 斯嘉蒂之眼      |
  12. | 3  | 幻影斧           |
  13. +----+-----------------+
  14. 3 rows in set (0.00 sec)

再3307和3308两个实例上分别开启组复制:

  1. START GROUP_REPLICATION;

检查3307和3308是否将3306的事务应用过来

  1. [root@sAno1y mysql57]# /data/mysql57/mysql-basedir/bin/mysql -uroot -proot123 -S /tmp/mysql3307.sock -e "START GROUP_REPLICATION;"
  2. mysql: [Warning] Using a password on the command line interface can be insecure.
  3. [root@sAno1y mysql57]#
  4. [root@sAno1y mysql57]# /data/mysql57/mysql-basedir/bin/mysql -uroot -proot123 -S /tmp/mysql3308.sock -e "START GROUP_REPLICATION;"
  5. mysql: [Warning] Using a password on the command line interface can be insecure.
  6. [root@sAno1y mysql57]# /data/mysql57/mysql-basedir/bin/mysql -uroot -proot123 -S /tmp/mysql3307.sock -e "SELECT * FROM test.tb_test;"
  7. mysql: [Warning] Using a password on the command line interface can be insecure.
  8. +----+-----------------+
  9. | id | name            |
  10. +----+-----------------+
  11. | 1  | 灵魂守卫        |
  12. | 2  | 斯嘉蒂之眼       |
  13. | 3  | 幻影斧          |
  14. +----+-----------------+
  15. [root@sAno1y mysql57]# /data/mysql57/mysql-basedir/bin/mysql -uroot -proot123 -S /tmp/mysql3308.sock -e "SELECT * FROM test.tb_test;"
  16. mysql: [Warning] Using a password on the command line interface can be insecure.
  17. +----+-----------------+
  18. | id | name           |
  19. +----+-----------------+
  20. | 1  | 灵魂守卫         |
  21. | 2  | 斯嘉蒂之眼       |
  22. | 3  | 幻影斧           |
  23. +----+-----------------+

当然可以看到,在3306上做的修改,在3307和3308开启组复制之后也已经同步过来了。


那么再检查一下3307和3308是否可写:

  1. [root@sAno1y mysql57]# /data/mysql57/mysql-basedir/bin/mysql -uroot -proot123 -S /tmp/mysql3307.sock -e "SELECT @@read_only, @@super_read_only;"
  2. mysql: [Warning] Using a password on the command line interface can be insecure.
  3. +-------------+-------------------+
  4. | @@read_only | @@super_read_only |
  5. +-------------+-------------------+
  6. | 0           | 0                |
  7. +-------------+-------------------+
  8. [root@sAno1y mysql57]# /data/mysql57/mysql-basedir/bin/mysql -uroot -proot123 -S /tmp/mysql3308.sock -e "SELECT @@read_only, @@super_read_only;"
  9. mysql: [Warning] Using a password on the command line interface can be insecure.
  10. +-------------+-------------------+
  11. | @@read_only | @@super_read_only |
  12. +-------------+-------------------+
  13. | 0           | 0                 |
  14. +-------------+-------------------+

显然和Single-Master Mode不一样的是,除了3306实例,另外两个成员也就是3307和3308实例均为可写成员了。
也就是所谓的Multi-Master Mode


当然可以测试一下:
在3307实例上做insert,在3308实例上update,最后在3306上查询:

  1. [root@sAno1y mysql57]# /data/mysql57/mysql-basedir/bin/mysql -uroot -proot123 -S /tmp/mysql3307.sock -e "INSERT INTO test.tb_test VALUES(4,'吸血面具')";
  2. mysql: [Warning] Using a password on the command line interface can be insecure.
  3. [root@sAno1y mysql57]# /data/mysql57/mysql-basedir/bin/mysql -uroot -proot123 -S /tmp/mysql3308.sock -e "UPDATE test.tb_test SET name='撒旦之邪力' WHERE id=4;"
  4. mysql: [Warning] Using a password on the command line interface can be insecure.
  5. [root@sAno1y mysql57]# /data/mysql57/mysql-basedir/bin/mysql -uroot -proot123 -S /tmp/mysql3306.sock -e "SELECT * FROM test.tb_test;"
  6. mysql: [Warning] Using a password on the command line interface can be insecure.
  7. +----+-----------------+
  8. | id | name            |
  9. +----+-----------------+
  10. | 1  | 灵魂守卫         |
  11. | 2  | 斯嘉蒂之眼      |
  12. | 3  | 幻影斧           |
  13. | 4  | 撒旦之邪力       |
  14. +----+-----------------+

至此,已经成功将Single-Master Mode修改为Multi-Master Mode


P.S. 在多主模式中,已经不能通过下述SQL来查询primary member是哪一台实例了……虽然��明白为毛,可能在后续版本会改进???(猜测)
但总之在多主模式中,每一台status为online的成员都是primary。

  1. SELECT b.member_id, b.member_host, b.member_port
  2. FROM performance_schema.global_status a
  3. JOIN performance_schema.replication_group_members b
  4. ON a.variable_value = b.member_id
  5. WHERE a.variable_name= 'group_replication_primary_member';

总之……看起来很好用的样子。



从零开始搭建Multi-Master Mode的GR同样也很简单,可以参考:
 http://mysqlhighavailability.com/mysqlha/gr/doc/getting_started.html


两种工作模式在配置参数上的核心差别为:

  1. loose-group_replication_single_primary_mode=FALSE
  2. loose-group_replication_enforce_update_everywhere_checks=TRUE
  3. (single-master mode 这俩个参数的值为TRUE和FALSE)

〇 要求和限制

仅可用于InnoDB存储引擎(需要事务的支持和行级锁)
表必须有主键(创建无主键的表不会报错,但在插入数据的时候会抛出:ERROR 3098 (HY000): The table does not comply with the requirements by an external plugin.)
必须启用GTID
必须开启二进制日志,并且其格式必须为ROW(binlog_format=row)
冲突DDl、DML只能在同一成员上执行成功
在多主结构中,不完全支持外键(单主结构中是没有问题的)
不支持serializable的事务隔离级别
只支持IPv4,并且需要低延迟,高带宽的网络环境
GR最大支持9个成员
复制信息元数据必须存在系统表(master-info-repository=TABLE、relay-log-info-repository=TABLE)
二进制日志checksums必须关闭(binlog-checksum=NONE)
不支持savepoint的使用




〇 参考文档:

MySQL 5.7 Reference Manual - 19.2 Group Replication 

马楚成 - 使用群组复制实现MySQL高可用性 (https://www.mysql.com/news-and-events/web-seminars/mysql-cluster-ha-group-replication2-zh/)

mysqlha组文档 Docs ? Requirements and Limitations

本文永久更新链接地址http://www.linuxidc.com/Linux/2017-03/142378.htm

linux
相关资讯       MySQL 5.7.17  Group Relication 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款