如何将TIDB作为Mysql的从库实现实时数据同步

-------------------------------------------------------------------

欢迎关注作者

墨天伦:潇湘秦的个人主页 - 墨天轮
CSDN:潇湘秦-CSDN博客

公众号:潇湘秦

-------------------------------------------------------------------

      

    近期一个MES项目架构比较复杂,使用了mysql集群和TIDB集群,其中TIDB将作为报表库,如何将mysql的数据实时同步到TIDB

本文介绍TIDB DM工具实时同步mysql数据库,大部分参考了官方文档,这里做一个示例。

相关文章 :

传统制造型企业数据库选型之困  传统制造型企业数据库选型之困 - 墨天轮
TIDB7.5LTS集群安装配置手册 TIDB7.5LTS集群安装配置手册 - 墨天轮

一. 架构和环境介绍

OS:Centos7.9

mysql主从:8.0.30

TIDB(7node):7.5

前提已经安装配置好mysql主从和TIDB集群

具体的搭建过程可以参考我的两篇博文

TIDB7.5LTS集群安装配置手册 TIDB7.5LTS集群安装配置手册 - 墨天轮

手把手教你搭建mysql主从集群 手把手教你搭建mysql主从集群 - 墨天轮

数据流转图如下

二. 安装DM集群

 TiDB Data Migration (DM) 是一款便捷的数据迁移工具,支持从与 MySQL 协议兼容的数据库(MySQL、MariaDB、Aurora MySQL)到 TiDB 的全量数据迁移和增量数据同步。使用 DM 工具有利于简化数据迁移过程,降低数据迁移运维成本

产品特性

  • 与 TiDB 同样保持 MySQL 兼容性。高度兼容 MySQL 协议、MySQL 5.7 和 MySQL 8.0 的常用功能及语法。
  • 支持 DML & DDL 事件同步。支持解析和同步 binlog 中的 DML 和 DDL 事件。
  • 支持合库合表同步模式。可以方便的将上游各个分片 MySQL 实例的各个分表数据,合并同步到下游 TiDB 的一张表。支持自定义编写同步规则以方便各种可能的同步需求,且具备自动识别和处理上游分片 MySQL 的 DDL 变更,大幅简化运维成本。
  • 内置多种过滤器以灵活适应不同场景。支持以预定义事件类型、正则表达式、SQL 表达式等多种方式在数据同步过程中对 MySQL binlog 事件进行过滤。
  • 集中管理。DM 支持上千个节点的集群规模,可同时运行并集中管理大量数据迁移同步任务。
  • 对第三方 Online Schema Change 工具变更过程的同步优化。在 MySQL 生态中,gh-ost 与 pt-osc 等工具被广泛使用,DM 对其变更过程进行了特殊的优化,以避免对不必要的中间数据进行迁移。详细信息可参考 online-ddl
  • 高可用。支持迁移任务在不同节点自由调度,少量工作节点宕机并不会影响进行中的任务

使用限制

在使用 DM 工具之前,需了解以下限制:
数据库版本要求
MySQL 版本 5.5 ~ 5.7
MySQL 版本 = 8.0 (实验特性)##本次使用的8.0.30 虽然有warning 但是还是可以使用的
MariaDB 版本 >= 10.1.2 (实验特性)
注意
如果上游 MySQL/MariaDB servers 间构成主从复制结构,则需要 MySQL 版本高于 5.7.1 或者 MariaDB 版本等于或高于 10.1.3。
DDL 语法兼容性限制
目前,TiDB 部分兼容 MySQL 支持的 DDL 语句。因为 DM 使用 TiDB parser 来解析处理 DDL 语句,所以目前仅支持 TiDB parser 支持的 DDL 语法。详见 TiDB DDL 语法支持
DM 遇到不兼容的 DDL 语句时会报错。要解决此报错,需要使用 dmctl 手动处理,要么跳过该 DDL 语句,要么用指定的 DDL 语句来替换它。详见如何处理不兼容的 DDL 语句
DM 不会将视图的 DDL 语句同步到下游的 TiDB 集群,也不会将针对视图的 DML 语句同步到下游。在该场景下,建议用户在下游 TiDB 集群中自行创建视图。
GBK 字符集兼容性限制
  • DM 在 v5.4.0 之前不支持将 charset=GBK 的表迁移到 TiDB。
2.1使用TIUP安装dm,dmctl

  安装配置期间建议先开通外网,方便安装配置

  tiup list   #列出可以安装下载的组件

 tiup install dm dmctl   #安装dm和dmctl

[root@tidb01 ~]# tiup list
Available components:
Name            Owner      Description
----            -----      -----------
PCC             community  A tool used to capture plan changes among different versions of TiDB
bench           pingcap    Benchmark database with different workloads
br              pingcap    TiDB/TiKV cluster backup restore tool.
cdc             pingcap    CDC is a change data capture tool for TiDB
chaosd          community  An easy-to-use Chaos Engineering tool used to inject failures to a physical node
client          pingcap    Client to connect playground
cloud           pingcap    CLI tool to manage TiDB Cloud
cluster         pingcap    Deploy a TiDB cluster for production
ctl             pingcap    TiDB controller suite
dm              pingcap    Data Migration Platform manager
dmctl           pingcap    dmctl component of Data Migration Platform.
errdoc          pingcap    Document about TiDB errors
pd-recover      pingcap    PD Recover is a disaster recovery tool of PD, used to recover the PD cluster which cannot start or provide services normally.
playground      pingcap    Bootstrap a local TiDB cluster for fun
tidb            pingcap    TiDB is an open source distributed HTAP database compatible with the MySQL protocol.
tidb-dashboard  pingcap    TiDB Dashboard is a Web UI for monitoring, diagnosing, and managing the TiDB cluster
tidb-lightning  pingcap    TiDB Lightning is a tool used for fast full import of large amounts of data into a TiDB cluster
tikv-br         pingcap    TiKV cluster backup restore tool
tikv-cdc        pingcap    TiKV-CDC is a change data capture tool for TiKV
tiproxy         pingcap    TiProxy is a database proxy that is based on TiDB.
tiup            pingcap    TiUP is a command-line component management tool that can help to download and install TiDB platform components to the local system
[root@tidb01 ~]#  tiup install dm dmctl
component dm version v1.14.1 is already installed
component dmctl version v7.6.0 is already installed
[root@lyspltidb01 ~]# 
2.2 编辑初始化配置文件

tiup dm template > dmtopology.yaml  ##使用命令生成参数模板

vi dmtopology.yaml ##根据自己IP编辑参数模板

[root@tidb01 ~]# tiup dm template > topology.yaml
[root@tidb01 ~]# cat dmtopology.yaml
# The topology template is used deploy a minimal DM cluster, which suitable
# for scenarios with only three machinescontains. The minimal cluster contains
# - 3 master nodes
# - 3 worker nodes
# You can change the hosts according your environment
---
global:
user: "tidb"
ssh_port: 22  #
deploy_dir: "/home/tidb/dm/deploy"   ##根据自己本地情况修改
data_dir: "/home/tidb/dm/data"
# arch: "amd64"

master_servers:
- host: 172.19.0.101    ###配置master和worker节点IP,我是配置在TIKV的三个节点上
- host: 172.19.0.102
- host: 172.19.0.103

worker_servers:
- host: 172.19.0.101
- host: 172.19.0.102
- host: 172.19.0.103

monitoring_servers:
- host: 172.19.0.101

grafana_servers:
- host: 172.19.0.101

alertmanager_servers:
- host: 172.19.0.101
2.3 执行命令部署集群

 tiup list dm-master   ##查看可用的dm master版本,

tiup dm deploy dm-mes v7.5.0 ./dmtopology.yaml --user root -p    ##使用命令部署集群 dm-mes 为集群的名字

[root@tidb01 ~]# tiup list dm-master
Available versions for dm-master:
Version Installed Release Platforms
------- --------- ------- ---------
nightly -> v8.0.0-alpha-nightly 2024-03-06T12:56:19Z darwin/amd64,darwin/arm64,linux/amd64,linux/arm64
v2.0.0-rc 2020-08-21T17:49:08+08:00 linux/amd64,linux/arm64
v2.0.0-rc.2 2020-09-01T20:51:29+08:00 linux/amd64,linux/arm64
v2.0.0 2020-10-30T16:10:58+08:00 linux/amd64,linux/arm64
v2.0.
  • 19
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

潇湘秦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值