一、方案背景:

因物理服务器内存损坏导致数据库集群的该从库节点数据库实例异常。经对MySQL数据库错误日志分析后,该从库节点的主从复制需要重新搭建。通过内部讨论,鉴于数据库数据量比较大(2TB),考虑使用MySQL8.0的clone方法重新搭建该从库的主从复制。

该方案的限制:克隆操作不能与DDL操作同时进行。

二、环境准备:

2.1> 在管控平台手工执行备份计划,对数据库集群进行全库物理备份。

主库服务器IP地址:192.168.139.195;

正常从库服务器IP地址:192.168.139.54;

故障从库服务器IP地址:192.168.139.196。

2.2> 主库:创建一个复制用的账号:

create user ‘repl’@’192.168.139.196’ identified with mysql_native_password by ‘123456’;

grant all privileges on *.* to ‘repl’@’192.168.139.196’;

flush privileges;

2.3> 正常从库:安装部署clone插件:

mysql -uadmin -p’qaz123′ -h 127.0.0.1 -P3306

查看super-read-only参数是否关闭,需要临时关闭:

show variables like ‘super_read_only’;

set global super_read_only=off;

安装clone插件:

INSTALL PLUGIN clone SONAME ‘mysql_clone.so’;

验证clone插件安装完成:

show plugins;

打开super-read-only参数:

set global super_read_only=on;

验证参数super_read_only=on:

show variables like ‘super_read_only’;

2.4> 故障从库:如果从库无法启动,重新初始化一个MySQL数据库实例。

MySQL数据库安装clone插件:

mysql -uadmin -p’qaz123′ -h 127.0.0.1 -P3306

查看super-read-only参数是否关闭,需要临时关闭:

show variables like ‘super_read_only’;

set global super_read_only=off;

安装clone插件:

INSTALL PLUGIN clone SONAME ‘mysql_clone.so’;

验证clone插件安装完成:

show plugins;

三、故障从库节点实施数据库clone操作:

3.1> 使用mysql用户后台执行脚本,进行远程主库实例克隆:

su – mysql

cd /home/mysql

nohup /home/mysql/clone_mysql.sh >/home/mysql/abc.log &

3.2> clone数据库的脚本内容:

cat /home/mysql/clone_mysql.sh

#!/bin/bash

USER=admin

PASSWD=qaz123

HOST=127.0.0.1

PORT=3306

begin_date=`date +”%Y-%m-%d %H:%M:%S”`

end_date=`date +”%Y-%m-%d %H:%M:%S”`

echo $begin_date >> /home/mysql/clonemysql.log

echo “NOW BEGINE CLONE MASTER DB”>> /home/mysql/clonemysql.log

echo “…………………………………………………..”>> /home/mysql/clonemysql.log

mysql -u$USER -p$PASSWD -h$HOST -P$PORT >>/home/mysql/clonemysql.log <<EOF

set global clone_enable_compression=on;

set global clone_max_network_bandwidth=50;

SET GLOBAL clone_valid_donor_list = ‘192.168.139.54:3306’;

CLONE INSTANCE FROM ‘repl’@’192.168.139.54’:3306 IDENTIFIED BY ‘123456’;

EOF

echo “…………………………………………………..”>> /home/mysql/clonemysql.log

echo $end_date >> /home/mysql/clonemysql.log

echo “NOW FINISH CLONE MASTER DB”>> /home/mysql/clonemysql.log

四、搭建主从复制关系:

4.1> 故障从库搭建主从复制关系:

mysql -uadmin -p’qaz123′ -h 127.0.0.1 -P3306

CHANGE REPLICATION SOURCE TO SOURCE_HOST = ‘192.168.139.195’, SOURCE_PORT = 3306,SOURCE_USER = ‘dbscale_internal’, SOURCE_PASSWORD = ‘qaz123’, SOURCE_AUTO_POSITION = 1;

启动主从复制:

mysql> start slave;

验证主从复制:

mysql> show slave status\G

4.2> 故障从库打开super_read_only参数

mysql -uadmin -p’qaz123′ -h 127.0.0.1 -P3306

打开super-read-only参数:

set global super_read_only=on;

验证参数super_read_only=on:

show variables like ‘super_read_only’;

五、 可能遇到的问题:

主、从库执行以下查询:

show global status like ‘Rpl_semi_sync_%’;

预期:

主库: Rpl_semi_sync_slave_status 应该是 off ,Rpl_semi_sync_master_status 为on

从库: Rpl_semi_sync_slave_status 应该是 on , Rpl_semi_sync_master_status 为off

set global Rpl_semi_sync_slave_enabled=1;

stop slave io_thread;

start slave io_thread;