一、环境
tidb集群 7.1.1
数据同步使用binlog方式实时同步到mysql8.0中。
需要的工具:pump 负责收取tidb的binlog日志。
drainer 负责将各PUMP收取的日志进行排序和传输到MySQL
配置多个drainer,一个负责整理日志,一个负责发送到mysql
部署方式。可以给PUMP和drainer单独部署节点,我目前和数据节点都放一起了。
二、部署pump
根据不同节点配置IP
vi scale-out-pump.yaml
pump_servers:
- host: xxxxxxxxx01
ssh_port: 22
port: 8250
deploy_dir: "/app/tidb-deploy/pump-8250"
data_dir: "/app/tidb-data/pump-8250"
# The following configs are used to overwrite the `server_configs.pump` values.
config:
gc: 7
- host: xxxxxxxxx02
ssh_port: 22
port: 8250
deploy_dir: "/app/tidb-deploy/pump-8250"
data_dir: "/app/tidb-data/pump-8250"
# The following configs are used to overwrite the `server_configs.pump` values.
config:
gc: 7
执行命令进行扩容
tiup cluster list ##查看集群名称
tiup cluster scale-out <集群名称> scale-out-pump.yaml -utidb -p
tiup cluster display <集群名称> ##查看pump组件状态
三、开启binlog
tiup cluster edit-config <集群名称>
##添加下面配置
server_configs:
tidb:
binlog.enable: true
binlog.ignore-error: true
tiup cluster reload <集群名称> -R tidb ##重启server
四、部署drainer
本drainer负责收集binlog,不负责同步。
vi scale-out-drainer1.yaml
drainer_servers:
- host: xxxxxxxx01
deploy_dir: /app/tidb-deploy/tidb_binlog/drainer-8249
data_dir: /app/tidb-data/tidb_binlog/drainer_data-8249
config:
# drainer meta data directory path
syncer.db-type: "file"
syncer.to.dir: /app/binlog #binlog 存放路径
syncer.to.retention-time : 7 #本地binlog日志的保留时间为7天
# directory to save binlog file, default same as data-dir(save checkpoint file) if this is not configured.
# syncer.to.dir: "/path/to/save/binlog"
##检查下配置文件
tiup cluster check <集群名称> scale-out-drainer1.yaml --cluster
##部署drainer
tiup cluster scale-out <集群名称> scale-out-drainer1.yaml -utidb -p
##查看drainer状态
tiup cluster display <集群名称>
部署同步drainer,本场场景是没有数据的新环境。如果TIDB有存量数据,需要提前导入到mysql中。两端数据都静止下来,进行数据比对校验后,再开始同步。
vi drainer_scale-out.toml
drainer_servers:
- host:xxxxxx02
deploy_dir: /app/tidb-deploy/tidb_binlog/drainer-8249
data_dir: /app/tidb-data/tidb_binlog/drainer_data-8249
config:
syncer.db-type: "mysql"
syncer.to.host: "xxxxxxxx03" #mysql地址
syncer.to.user: "root" #mysql 用户
syncer.to.password: "xxxxx" #mysql 密码
syncer.to.port: 13306 #mysql端口
initial-commit-ts: -1 ##从启动时间开始同步
syncer.replicate-do-db: ["xxxx"] ##同步的数据库名
##校验脚本语法正确性
tiup cluster check <集群名称> drainer_scale-out.toml --cluster
##扩展同步drainer
tiup cluster scale-out <集群名称> drainer_scale-out.toml -utidb -p
##查看drianer状态
tiup cluster display tidb01
五、查看同步状态
##登录到TIDB中,执行命令
show pump status;
show drainer status;
另外在grafana监控中tidb-binlog的页中也能看到状态。
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




