MySQL 8017+版本的clone-plugin 应用

1 . Clone Plugin介绍

本地克隆:

启动克隆操作的MySQL服务器实例中的数据,克隆到同服务器或同节点上的一个目录里

image.png

远程克隆:

默认情况下,远程克隆操作会删除接受者(recipient)数据目录中的数据,并将其替换为捐赠者(donor)的克隆数据。您也可以将数据克隆到接受者的其他目录,以避免删除现有数据。(可选)

image.png

2. 原理

# PAGE COPY这里有两个动作开启redoarchiving功能,从当前点开始存储新增的redolog,这样从当前点开始所有的增量修改都不会丢失。同时上一步在page track的page被发送到目标端。确保当前点之前所做的变更一定发送到目标端。关于redoarchiving,实际上这是官方早就存在的功能,主要用于官方的企业级备份工具,但这里clone利用了该特性来维持增量修改产生的redo。 在开始前会做一次checkpoint, 开启一个后台线程log_archiver_thread()来做日志归档。当有新的写入时(notify_about_advanced_write_lsn)也会通知他去archive。当arch_log_sys处于活跃状态时,他会控制日志写入以避免未归档的日志被覆盖(log_writer_wait_on_archiver),注意如果log_writer等待时间过长的话, archive任务会被中断掉.# Redo Copy停止RedoArchiving",所有归档的日志被发送到目标端,这些日志包含了从page copy阶段开始到现在的所有日志,另外可能还需要记下当前的复制点,例如最后一个事务提交时的binlog位点或者gtid信息,在系统页中可以找到# Done目标端重启实例,通过crash recovery将redolog应用上去。

3. 限制

官方文档列出的一些限制:The clone pluginissubjecttothese limitations:*DDL,isnot permitted during a cloning operation.This limitation should be consideredwhenselectingdatasources.A workaroundistouse dedicated donor instances,which can accommodate DDL operations being blockedwhiledataiscloned.Concurrent DMLispermitted.*An instance cannot be cloned from a different MySQL server version.The donorandrecipient must have the same MySQL server version.For example,you cannot clone between MySQL5.7andMySQL8.0\.The clone pluginisonly supportedinMySQL8.0.17andhigher.*Only a single MySQL instance can be cloned at a time.Cloning multiple MySQL instancesina single cloning operationisnot supported.*The X Protocol port specified byis not supportedforremote cloning operations*The clone plugin does not support cloning of MySQL server configurations.*The clone plugin does not support cloning of binary logs.*The clone plugin only clonesdatastoredin`InnoDB`.Other storage enginedataisnot cloned.*Connectingtothe donor MySQL server instance through MySQL Routerisnot supported.*Local cloning operationsdonot support cloning of general tablespaces that were created with an absolute path.A cloned tablespace file with the same pathasthe source tablespace file would cause a conflict.

4. 应用

4.1 本地

4.1.1 加载插件

INSTALL PLUGIN clone SONAME 'mysql_clone.so';或[mysqld]plugin-load-add=mysql_clone.soclone=FORCE_PLUS_PERMANENTSELECT PLUGIN_NAME, PLUGIN_STATUSFROM INFORMATION_SCHEMA.PLUGINSWHERE PLUGIN_NAME LIKE 'clone';

4.1.2 创建克隆专用用户

CREATEUSERclone_user@'%'IDENTIFIEDby'password';GRANTBACKUP_ADMINON*.*TO'clone_user';# BACKUP_ADMIN是MySQL8.0 才有的备份锁的权限

4.1.3 本地克隆

[root@db013306]# mkdir -p /data/test/[root@db013306]# chown -R mysql.mysql /data/mysql-uclone_user-ppasswordCLONELOCALDATADIRECTORY='/data/test/clonedir';# 观测状态db01[(none)]>SELECTSTAGE,STATE,END_TIMEFROMperformance_schema.clone_progress;+-----------+-------------+----------------------------+|STAGE|STATE|END_TIME|+-----------+-------------+----------------------------+|DROPDATA|Completed|2020-04-2021:13:19.264003||FILECOPY|Completed|2020-04-2021:13:20.025444||PAGECOPY|Completed|2020-04-2021:13:20.028552||REDOCOPY|Completed|2020-04-2021:13:20.030042||FILESYNC|Completed|2020-04-2021:13:20.439444||RESTART|NotStarted|NULL||RECOVERY|NotStarted|NULL|+-----------+-------------+----------------------------+7rowsinset(0.00sec)#日志观测: set global log_error_verbosity=3;tail-f db01.errCLONELOCALDATADIRECTORY='/data/test/clonedir1';

4.1.4 启动新实例

[root@db01 clonedir]# mysqld_safe--datadir=/data/test/clonedir--port=3333--socket=/tmp/mysql3333.sock--user=mysql--mysqlx=OFF&

4.2 远程clone

4.2.1 创建远程clone用户

# 捐赠者授权CREATEUSERclone_user@'10.0.0.51'IDENTIFIEDby'password1';GRANTBACKUP_ADMINON*.*TO'clone_user'@'10.0.0.51';# 接受者授权CREATEUSERclone_user@'10.0.0.52'IDENTIFIEDby'password2';GRANTCLONE_ADMINON*.*TO'clone_user'@'10.0.0.52';

4.2.2 远程clone

# 开始克隆SETGLOBALclone_valid_donor_list='10.0.0.51:3306';mysql-uclone_user-ppassword2-h10.0.0.52-P3306CLONEINSTANCEFROMclone_user@'10.0.0.51':3306IDENTIFIEDBY'password1';# 查看状态:SELECTSTAGE,STATE,END_TIMEFROMperformance_schema.clone_progress;SELECTSTATEFROMperformance_schema.clone_status;

4.2.3 构建主从

# 主:create user repl@'%'identified WITH'mysql_native_password'by'123';GRANTREPLICATIONSLAVE,REPLICATIONCLIENTON*.*TO'repl'@'%';# 从:CHANGEMASTERTOMASTER_HOST='10.0.0.51',MASTER_USER='repl',MASTER_PASSWORD='123',MASTER_PORT=3306,MASTER_AUTO_POSITION=1;start slave;

恢复MGR 节点

# 假设三节点MGR某个节点异常,需要重新把这个节点加入到MGR集群中,具体操作过程如下:# 贡献者端执行(10.0.0.51)DROPUSER'donor_clone_user'@'10.0.0.51';CREATEUSER'donor_clone_user'@'10.0.0.51'IDENTIFIEDBY'password';GRANTBACKUP_ADMINon*.*to'donor_clone_user'@'10.0.0.51';INSTALLPLUGINclone SONAME'mysql_clone.so';# 接收者端执行(10.0.0.52)DROPUSER'recipient_clone_user'@'10.0.0.52';CREATEUSER'recipient_clone_user'@'10.0.0.52'IDENTIFIEDBY'password';GRANTCLONE_ADMINon*.*to'recipient_clone_user'@'10.0.0.52';INSTALLPLUGINclone SONAME'mysql_clone.so';SETGLOBALclone_valid_donor_list='10.0.0.51:3306';mysql-urecipient_clone_user-ppassword-h10.0.0.52-P3311CLONEINSTANCEFROM'donor_clone_user'@'10.0.0.51':3306IDENTIFIEDBY'password';mysql-uroot-pstart group_replication;select*fromperformance_schema.replication_group_members;

作者:MySQL_oldguo

链接:https://www.jianshu.com/p/eeb2d31923b1

来源:简书

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容