Table of Contents

openGauss学习笔记-315 openGauss 数据迁移-MySQL迁移-迁移MySQL数据库至openGauss-增量迁移

315.1 功能介绍

增量迁移是指将mysql数据迁移期间(包括全量和增量迁移)产生的增量数据迁移至openGauss端。

315.2 原理简介

debezium mysql connector的source端,监控mysql数据库的binlog日志,并将数据(DDL和DML操作)以AVRO格式写入到kafka;debezium mysql connector的sink端,从kafka读取AVRO格式数据(DDL和DML操作),并组装为事务,在openGauss端按照事务粒度并行回放,从而完成数据(DDL和DML操作)从mysql在线迁移至openGauss端。由于该方案严格保证事务的顺序性,因此将DDL和DML路由在kafka的一个topic下,且该topic的分区数只能为1(参数num.partitions=1),从而保证source端推送到kafka,和sink端从kafka拉取数据都是严格保序的。

315.3 特性优势

  • 利用sysbench对MySQL进行压测,2路鲲鹏920 CPU、openEuler操作系统下,针对混合IUD场景,10张表50个线程(insert-30线程,update-10线程,delete-10线程),在线迁移性能可达3w tps。
  • 目标数据库的数据是有序的,且保证事务一致性。

315.4 操作步骤

增量迁移gs_replicate依赖MySQL一键式迁移工具gs_rep_portal,可实现增量迁移的安装、启动、停止、卸载整个过程。

315.4.1 下载gs_rep_portal
wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/tools/portal/PortalControl-5.0.0.tar.gz
  • 1.

解压,并进入portal对应目录

tar -zxvf PortalControl-5.0.0.tar.gz
cd portal
  • 1.
  • 2.
315.4.2 修改gs_rep_portal配置文件

配置文件位于config目录内,增量迁移相关的配置文件主要包含如下两个,相关参数含义简要说明如下:

  • toolspath.properties
# 增量迁移依赖包路径,可自定义修改
debezium.path=/ops/portal/tools/debezium/
# kafka路径,位于增量迁移依赖包路径下,可自定义修改
kafka.path=/ops/portal/tools/debezium/kafka_2.13-3.2.3/
# confluent路径,位于增量迁移依赖包路径下,可自定义修改
confluent.path=/ops/portal/tools/debezium/confluent-5.5.1/
# connector路径,位于增量迁移依赖包路径下,可自定义修改
connector.path=/ops/portal/tools/debezium/plugin/
# debezium mysql connector路径,位于connector路径下,可自定义修改
connector.mysql.path=/ops/portal/tools/debezium/plugin/debezium-connector-mysql/
# kafka下载路径
kafka.pkg.url=https://downloads.apache.org/kafka/3.2.3/kafka_2.13-3.2.3.tgz
# confluent下载路径
confluent.pkg.url=https://packages.confluent.io/archive/5.5/confluent-community-5.5.1-2.12.zip
# debezium mysql connector下载路径
connector.mysql.pkg.url=https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.0.0/tools/replicate-mysql2openGauss-5.0.0.tar.gz
# 增量迁移依赖安装包路径,可自定义修改
debezium.pkg.path=/ops/portal/pkg/debezium/
# kafka包名
kafka.pkg.name=kafka_2.13-3.2.3.tgz
# confluent包名
confluent.pkg.name=confluent-community-5.5.1-2.12.zip
# mysql2openGauss在线复制包名
connector.mysql.pkg.name=replicate-mysql2openGauss-5.0.0.tar.gz
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • migrationConfig.properties
# mysql用户名
mysql.user.name=root
# mysql密码
mysql.user.password=***
# mysql数据库ip
mysql.database.host=127.0.0.1
# mysql数据库端口
mysql.database.port=3306
# mysql数据库名称
mysql.database.name=test123
# openGauss用户名
opengauss.user.name=test
# openGauss密码
opengauss.user.password=***
# openGauss数据库ip
opengauss.database.host=127.0.0.1
# openGauss数据库端口
opengauss.database.port=5432
# openGauss数据库名称
opengauss.database.name=test1234
# openGauss数据库的schema名称
opengauss.database.schema=test123
# 在线迁移的安装方式,默认为offline,表示离线安装,需通过参数debezium.pkg.path指定离线依赖安装包的路径;若设置为online,对应在线安装,在线下载的安装包将存放在参数debezium.pkg.path指定的路径
default.install.mysql.incremental.migration.tools.way=offline
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
315.4.3 安装
sh gs_replicate.sh install mysql-opengauss workspace.id
  • 1.

其中workspace.id表示迁移任务id,取值为数字和小写字母的组合,不同的id区分不同的迁移任务,不同迁移任务可并行启动。若未设置workspace.id,则使用其默认值1。若使用已存在的workspace.id,并修改其中的配置,请在portal/workspace/${workspace.id}/config/路径下修改对应的配置文件。

315.4.4 启动
sh gs_replicate.sh start mysql-opengauss workspace.id
  • 1.
315.4.5 停止
sh gs_replicate.sh stop mysql-opengauss workspace.id
  • 1.
315.4.6 卸载
sh gs_replicate.sh uninstall mysql-opengauss workspace.id
  • 1.

上述安装、启动、停止、卸载命令均不会在后台运行,若需在后台运行,请在命令后添加&符号。

315.5 注意事项

  • 当前支持MySQL IUD操作(insert、update、delete)产生的增量数据迁移至openGauss。

  • 支持迁移openGauss数据库兼容的MySQL DDL语句,对于不兼容的DDL,迁移时会报错处理(openGauss在完善对DDL的兼容性)。

  • 为保证事务的顺序和一致性,不支持skip_event, limit_table, skip_table等设置。

  • MySQL需要5.7及以上版本。

  • MySQL参数设置要求为:log_bin=ON, binlog_format=ROW, binlog_row_image=FULL, gtid_mode = ON。若gtid_mode为off,则sink端按照事务顺序串行回放,会降低在线迁移性能。

  • 先进行全量迁移,再进行增量迁移,全量迁移可基于 gs_mysync工具完成。

  • Kafka中以AVRO格式存储数据,AVRO字段名称 命名规则为:

    • 以[A-Za-z_]开头
    • 随后仅包含[A-Za-z0-9_]

    因此,对于MySQL中的标识符命名,包括表名、列名等,需满足上述命名规范,否则在线迁移会报错。

原文链接:[ openGauss学习笔记-315 openGauss 数据迁移-迁移MySQL数据库至openGauss-增量迁移]

👍 点赞,你的认可是我创作的动力!

⭐️ 收藏,你的青睐是我努力的方向!

✏️ 评论,你的意见是我进步的财富!

openGauss学习笔记-315 openGauss 数据迁移-MySQL迁移-迁移MySQL数据库至openGauss-增量迁移_开源数据库