背景
针对跨集群数据迁移并时效性要求较高(要求数据毫秒级别延迟),搭建异地容灾集群,读写分离集群。制定该方案实现doris数据迁移,并保障业务连续性。
同步原理
CCR 工具主要依赖一个轻量级进程:Syncers。Syncers 会从源集群获取 binlog,直接将元数据应用于目标集群,通知目标集群从源集群拉取数据。从而实现全量和增量迁移。
实施条件
- 源,目标doris集群版本均高于2.0.1版本
- 源,目标doris集群fe,be节点端口互通
- 目标doris集群中无脏数据(无源集群同名库表)
实施步骤
1、开启binlog
源,目标doris集群fe,be节点均需开启
FE节点
修改配置
vim $doris_home/fe/conf/fe.conf
新增:
enable_feature_binlog = true
experimental_enable_feature_binlog = true
滚动重启fe节点
BE节点
修改配置
vim $doris_home/be/conf/be.conf
新增:
enable_feature_binlog = true
experimental_enable_feature_binlog = true
滚动重启be节点
2、CCR环境搭建
在任一doris集群选一节点部署ccr-syncer服务
#编译安装
git clone https://github.com/selectdb/ccr-syncer
cd ccr-syncer
bash build.sh --output ccr
cd ccr
# 启动
cd bin && sh start_syncer.sh --daemon
#如果启动报错提示需要glibc-2.28,glibc-2.32,见最后故障处理
# 停止
sh stop_syncer.sh
3、开启源集群中同步库/表的 Binlog
# 如果是整库同步,可以执行如下脚本,使得该库下面所有的表都要打开 binlog.enable
vim ccr/bin/enable_db_binlog.sh
修改源集群的 host、port、user、password、db
或者 ./enable_db_binlog.sh -h $host -p $port -u $user -P $password -d $db
# 如果是单表同步,则只需要打开 table 的 binlog.enable,在源集群上执行:
ALTER TABLE enable_binlog SET ("binlog.enable" = "true");
4、同步数据
- 向 syncer 提交同步任务
curl -X POST -H "Content-Type: application/json" -d '{
"name": "ccr_test",
"src": {
"host": "10.10.83.6",
"port": "9030",
"thrift_port": "9020",
"user": "root",
"password": "",
"database": "your_db_name",
"table": ""
},
"dest": {
"host": "10.10.85.248",
"port": "9030",
"thrift_port": "9020",
"user": "root",
"password": "",
"database": "your_db_name",
"table": "your_table_name"
}
}' http://$ccr_host:9190/create_ccr
同步任务的参数说明:
name: CCR同步任务的名称,唯一即可
host、port:对应集群 Master FE的host和mysql(jdbc) 的端口
user、password:syncer以何种身份去开启事务、拉取数据等
database、table:
如果是db级别的同步,则填入your_db_name,your_table_name为空
如果是表级别同步,则需要填入your_db_name,your_table_name
向syncer发起同步任务中的name只能使用一次
- get_lag 查看同步进度
其中 job_name 是 create_ccr 时创建的 name
curl -X POST -H "Content-Type: application/json" -d '{
"name": "job_name"
}' http://$ccr_host:9190/get_lag
- pause 暂停同步任务
curl -X POST -H "Content-Type: application/json" -d '{
"name": "job_name"
}' http://127.0.0.1:9190/pause
- resume 恢复同步任务
curl -X POST -H "Content-Type: application/json" -d '{
"name": "job_name"
}' http://127.0.0.1:9190/resume
- delete 删除同步任务
curl -X POST -H "Content-Type: application/json" -d '{
"name": "job_name"
}' http://127.0.0.1:9190/delete
- version 获取版本信息
curl http://127.0.0.1:9190/version
# > return
{
"version": "2.0.1"}
- job status 查看 job 的状态
curl -X POST -H "Content-Type: application/json" -d '{
"name": "job_name"
}' http://127.0.0.1:9190/job_status
{
"success": true,
"status": {
"name": "ccr_db_table_alias",
"state": "running",
"progress_state": "TableIncrementalSync"
}
}
- list_jobs 展示已经创建的所有任务
curl http://127.0.0.1:9190/list_jobs
{
"success":true,"jobs":["ccr_db_table_alias"]}
数据校验
同步任务完成后,源,目标集群数据一致
- 整库校验
cat check_dorisdata.sh
#/bin/bash
db=