前提: MySQL GR 3节点(node1、node2、node3)部署成功,模式定为多主模式,单主模式也是一样的处理。
在线修改已有GR节点配置
分别登陆node1、node2、node3,执行以下命令,修改GR配置:增加一台新节点进入
mysql> set global group_replication_group_seeds="10.39.3.76:33061,10.39.3.70:33061,10.39.3.69:33761,10.39.3.71:33061";
Query OK, 0 rows affected (0.00 sec) mysql> show variables like '%group_replication_group_seeds%';
+-------------------------------+---------------------------------------------------------------------------------+
| Variable_name | Value |
+-------------------------------+---------------------------------------------------------------------------------+
| group_replication_group_seeds | 10.39.3.76:33061,10.39.3.70:33061,10.39.3.69:33061,10.39.3.71:33061 |
+-------------------------------+---------------------------------------------------------------------------------+
1 row in set (0.00 sec)
部署node4
修改my.cnf
[client]
port = 3306
socket = /data/mysql/mysql.sock
default-character-set = utf8mb4
[mysqld]
#base config 基础配置信息
port = 3306
socket = /data/mysql/mysql.sock
character-set-server = utf8mb4
basedir = /data/mysql
datadir = /data/mysql/data
pid-file = /data/mysql/mysql.pid
user = mysql
server-id = 4
bind-address = 0.0.0.0 ####binlog binlog配置,Group Replication是要根据GTID来进行同步的,所以需要开启GTID
gtid_mode=ON
enforce-gtid-consistency = ON
master-info-repository = TABLE
relay-log-info-repository = TABLE
log-bin=binlog
binlog-checksum = NONE
log-slave-updates = ON
binlog_format=ROW ###日志存放
log_error = /data/mysql/data/mysql-error.log
slow_query_log = 1
slow_query_log_file = /data/mysql/data/mysql-slow.log
log_queries_not_using_indexes=1 ### innodb设置
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_buffer_pool_size=24G
innodb_log_buffer_size=8M ###加入group replication设置
transaction-isolation=READ-COMMITTED
###同步算法
transaction_write_set_extraction=XXHASH64
###集群的uuid
loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
###是否随着服务启动集群
loose-group_replication_start_on_boot=off
##集群本机端口,和服务端口不同
loose-group_replication_local_address= "10.39.3.71:33061"
##集群包含的所有节点
loose-group_replication_group_seeds= "10.39.3.76:33061,10.39.3.70:33061,10.39.3.69:33061,10.39.3.71:33061"
#设置白名单
loose-group_replication_ip_whitelist='10.39.3.76/24,10.39.3.70/24,10.39.3.69/24,10.39.3.71/24,127.0.0.1/8'
##是否设置为主节点,当创建集群时其他加入的节点都以该节点为目标加入集群
loose-group_replication_bootstrap_group= off
###多主模式 默认单主模式
loose-group_replication_single_primary_mode=FALSE
loose-group_replication_enforce_update_everywhere_checks= TRUE
###单主模式 默认单主模式
#loose-group_replication_single_primary_mode=true
#loose-group_replication_enforce_update_everywhere_checks=false
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
初始化数据(mysql01-04)
mysqld --initialize-insecure --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data
增加权限(mysql01-04)
chown -R mysql.mysql /data/mysql
启动mysql
/etc/init.d/mysqld start
修改密码(mysql01-04)
mysqladmin -u root password 'thAd6Zelma7_gropE3936polLUtioN' -p
进入mysql创建授权用户(dbnode1)###创建授权用户不写入bin_log
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';
###安装mysql group replication:
INSTALL PLUGIN group_replication SONAME 'group_replication.so';
mysql> SHOW PLUGINS;
| Name |Status | Type | Library | License |
| binlog | ACTIVE | STORAGE ENGINE | NULL GPL
group_replication | ACTIVE | GROUP REPLICATION | group_replication.so | GPL|
###开启兼容模式
set global group_replication_allow_local_disjoint_gtids_join=ON;
###启动
START GROUP_REPLICATION;
###查看group在线机器
mysql> SELECT * FROM performance_schema.replication_group_members;
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
group_replication_applier | 02d70597-9f73-11e7-8a51-000c29578bd4 | node1 | 3306 | ONLINE |
group_replication_applier | b8a02335-a1bb-11e7-b39b-000c29c4cbb3 | node2 | 3306 | ONLINE |
group_replication_applier | dc19223f-a1bb-11e7-85ce-000c29826f1f | node3 | 3306 | ONLINE |
###验证node4已经加入GR集群:
group_replication_applier | dc19223f-a1bb-11e7-85ce-000c29826f1e | node4 | 3306 | ONLINE |
row in set (0.00 sec)
后续操作
到这里我们已经完成了node4的动态添加,当然,为了下次node1、node2、node3重启后gr配置仍然能够生效,我们需要修改node1.cnf、node2.cnf和node3.cnf里面的一个配置项为:
loose-group_replication_group_seeds= "10.39.3.76:33061,10.39.3.70:33061,10.39.3.69:66061,10.39.3.71:33061"
这样能够确保下次重启这些节点,GR的配置能够是最新的配置。