MySQL Group Replication 动态添加成员节点

http://blog.csdn.net/d6619309/article/details/54095888

 

1. 背景

前面文章已经介绍如何部署MySQL GR 的两种模式:

在前面的部署里面,因为是预先知道需要部署的组节点规模,所以我们能够在my.cnf里面体现出组成员信息。但是,前面的部署并没有体现出动态添加组节点。

这篇文章介绍如何动态地往一个组里面添加新的成员。

前提: MySQL GR 3节点(s1、s2、s3)部署成功,模式定为Multi-Primary Mode,Single-Primary Mode也是一样的处理。

目标: 不重启已有GR节点的基础上,添加新成员s4、s5,组成5节点的GR。

2. 部署过程

假设已经通过3节点的部署(部署参考上面的博客)

2.1 在线修改已有GR节点配置

分别登陆s1、s2、s3,执行以下命令,修改GR配置:

mysql> set global group_replication_group_seeds="127.0.0.1:24901,127.0.0.1:24902,127.0.0.1:24903,127.0.0.1:24904,127.0.0.1:24905";
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like '%group_replication_group_seeds%';
+-------------------------------+---------------------------------------------------------------------------------+
| Variable_name                 | Value                                                                           |
+-------------------------------+---------------------------------------------------------------------------------+
| group_replication_group_seeds | 127.0.0.1:24901,127.0.0.1:24902,127.0.0.1:24903,127.0.0.1:24904,127.0.0.1:24905 |
+-------------------------------+---------------------------------------------------------------------------------+
1 row in set (0.00 sec)

2.2 部署s4

安装s4:

mysql-5.7/bin/mysqld --initialize-insecure --basedir=$PWD/mysql-5.7 --datadir=$PWD/data/s4

增加配置s4.cnf:

# server configuration
[mysqld]
datadir=/dba/mysql/data/s4
basedir=/dba/mysql/mysql-5.7/

port=24804
socket=/dba/mysql/data/s4/s4.sock

server_id=4
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
log_bin=binlog
binlog_format=ROW

transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "127.0.0.1:24904"
loose-group_replication_group_seeds= "127.0.0.1:24901,127.0.0.1:24902,127.0.0.1:24903,127.0.0.1:24904,127.0.0.1:24905"
loose-group_replication_bootstrap_group= off
loose-group_replication_single_primary_mode=false
loose-group_replication_enforce_update_everywhere_checks=true

启动s4:

nohup mysql-5.7/bin/mysqld --defaults-file=data/s4/s4.cnf >data/s4/nohup.out 2>data/s4/nohup.out &

使用以下命令登陆s4:

mysql -uroot -h127.0.0.1 -P24804 --skip-password
  • 1

修改root密码:

SET SQL_LOG_BIN=0;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql';
SET SQL_LOG_BIN=1;

创建gr所需要用户并授权:

SET SQL_LOG_BIN=0;
CREATE USER rpl_user@'%';
GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%' IDENTIFIED BY 'rpl_pass';
FLUSH PRIVILEGES;
SET SQL_LOG_BIN=1;
CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='rpl_pass' FOR CHANNEL 'group_replication_recovery';

安装组复制插件并开启插件

INSTALL PLUGIN group_replication SONAME 'group_replication.so';

START GROUP_REPLICATION;

验证s4已经加入GR集群:

mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 933a5345-d321-11e6-b971-fa163ee40410 | yourhost  |       24801 | ONLINE       |
| group_replication_applier | 95155949-d325-11e6-b68e-fa163ee40410 | yourhost  |       24804 | ONLINE       |
| group_replication_applier | 9abe6249-d321-11e6-bb5c-fa163ee40410 | yourhost  |       24802 | ONLINE       |
| group_replication_applier | a1c89c34-d321-11e6-bbbc-fa163ee40410 | yourhost  |       24803 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
4 rows in set (0.00 sec)

2.3 部署s5

与s4相同的部署即可以将s5加入GR集群:

s5.cnf配置:

# server configuration
[mysqld]
datadir=/dba/mysql/data/s5
basedir=/dba/mysql/mysql-5.7/

port=24805
socket=/dba/mysql/data/s5/s5.sock

server_id=5
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
log_bin=binlog
binlog_format=ROW

transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "127.0.0.1:24905"
loose-group_replication_group_seeds= "127.0.0.1:24901,127.0.0.1:24902,127.0.0.1:24903,127.0.0.1:24904,127.0.0.1:24905"
loose-group_replication_bootstrap_group= off
loose-group_replication_single_primary_mode=false
loose-group_replication_enforce_update_everywhere_checks=true
nohup mysql-5.7/bin/mysqld --defaults-file=data/s5/s5.cnf >data/s5/nohup.out 2>data/s5/nohup.out &
  • 1

其他后续步骤省略,依据s4的部署执行即可。

最后也成功将s5加入GR集群:

mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 933a5345-d321-11e6-b971-fa163ee40410 | yourhost  |       24801 | ONLINE       |
| group_replication_applier | 95155949-d325-11e6-b68e-fa163ee40410 | yourhost  |       24804 | ONLINE       |
| group_replication_applier | 9abe6249-d321-11e6-bb5c-fa163ee40410 | yourhost  |       24802 | ONLINE       |
| group_replication_applier | a1c89c34-d321-11e6-bbbc-fa163ee40410 | yourhost  |       24803 | ONLINE       |
| group_replication_applier | e973e06c-d327-11e6-98bc-fa163ee40410 | yourhost  |       24805 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
5 rows in set (0.01 sec)

2.4 后续操作

到这里我们已经完成了s4和s5的动态添加,当然,为了下次s1、s2、s3重启后gr配置仍然能够生效,我们需要修改s1.cnf、s2.cnf和s3.cnf里面的一个配置项为:

loose-group_replication_group_seeds= "127.0.0.1:24901,127.0.0.1:24902,127.0.0.1:24903,127.0.0.1:24904,127.0.0.1:24905"

这样能够确保下次重启这些节点,GR的配置能够是最新的配置。

启动s5

Leave a Reply

Your email address will not be published. Required fields are marked *