MySQL 8.0 clone插件提供从一个实例克隆数据的功能,克隆功能提供了更有效的方式来快速创建MySQL实例,搭建主从复制和组复制。本文介绍使用 MySQL 8.0 clone 插件快速添加组复制(MGR)节点的方法。
参考:http://wendaok.cn/post/16540.html
已有MGR集群,多主模式:
192.168.56.101
192.168.56.102
192.168.56.103
通过clone插件新加节点: 192.168.56.104
完整路径 /home/mysql/etc/my.cnf_8.0.19,除了以下三个参数不一样外,其他与已有MGR节点的配置文件保持一致。
server_id
loose-group_replication_local_address
report_host
[mysqld]
port=3306
basedir=/usr/local/mysql8
datadir=/mysql/data8/
socket=/mysql/data8/mysql.sock
pid_file=/mysql/data8/mysql.pid
log_bin=binlog
log_slave_updates=ON
binlog_format=ROW
binlog_checksum=NONE
master_info_repository=TABLE
relay_log_info_repository=TABLE
gtid_mode=ON
enforce_gtid_consistency=ON
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=“192.168.56.104:33061”
loose-group_replication_group_seeds=“192.168.56.101:33061,192.168.56.102:33061,192.168.56.103:33061”
loose-group_replication_bootstrap_group=OFF
server_id=4
report_host=192.168.56.104
report_port=3306
初始化新加入节点的MySQL数据库。
useradd mysql
mkdir -p /mysql/data8
sudo chown -R mysql:mysql /mysql/data8
sudo chown -R mysql.mysql /home/mysql/etc/
/usr/local/mysql8/bin/mysqld --defaults-file=/home/mysql/etc/my.cnf_8.0.19 --initialize-insecure
在新加入的节点上执行:
/usr/local/mysql8/bin/mysqld_safe --defaults-file=/home/mysql/etc/my.cnf_8.0.19 &
/usr/local/mysql8/bin/mysql -S /mysql/data8/mysql.sock
mysql> INSTALL PLUGIN group_replication SONAME ‘group_replication.so’;
mysql> INSTALL PLUGIN clone SONAME ‘mysql_clone.so’;
5、已有MGR集群添加clone账号,并授权
由于已有MGR集群是多主模式,在任一节点上执行都可以,我们选择在192.168.56.101节点上执行:
mysql> create user ‘clone_user’@’%’ identified by ‘123456’;
mysql> grant BACKUP_ADMIN on . to ‘clone_user’@’%’;
mysql> grant CLONE_ADMIN on . to ‘clone_user’@’%’;
6、执行克隆任务
在新加节点 192.168.56.104上执行:
mysql> SET GLOBAL clone_valid_donor_list = ‘192.168.56.101:3306’;
mysql> CLONE INSTANCE FROM ‘clone_user’@‘192.168.56.101’:3306 IDENTIFIED BY ‘123456’;
克隆完成后,新加入的节点会自动重启。
7、添加新节点到白名单中
添加新节点ip到白名单,要在所有节点上执行。
mysql> set global group_replication_ip_whitelist=‘192.168.56.104/24’;
如果不添加白名单,下一步启动组复制会报错,如下:
2020-02-22T14:41:29.597726+08:00 0 [Warning] [MY-011735] [Repl] Plugin group_replication reported: ‘[GCS] Connection attempt from IP address ::ffff:192.168.56.104 refused. Address is not in the IP whitelist.’
8、启动组复制,加入MGR集群
在新加入的节点上执行启动组复制:
mysql> set global group_replication_single_primary_mode=OFF;
mysql> set global group_replication_enforce_update_everywhere_checks=ON;
mysql> START GROUP_REPLICATION;
mysql> SELECT MEMBER_HOST,MEMBER_PORT,MEMBER_STATE,MEMBER_ROLE,MEMBER_VERSION FROM performance_schema.replication_group_members;
±---------------±------------±-------------±------------±---------------+
| MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
±---------------±------------±-------------±------------±---------------+
| 192.168.56.101 | 3306 | ONLINE | PRIMARY | 8.0.19 |
| 192.168.56.102 | 3306 | ONLINE | PRIMARY | 8.0.19 |
| 192.168.56.103 | 3306 | ONLINE | PRIMARY | 8.0.19 |
| 192.168.56.104 | 3306 | ONLINE | PRIMARY | 8.0.19 |
±---------------±------------±-------------±------------±---------------+