阿里云到京东云的MySQL复制
以下步骤演示如何搭建从阿里云RDS到京东云RDS的MySQL复制.
检查阿里云RDS的环境
MySQL版本为5.7.18
检查权限:
mysql> select user();
+---------------------+
| user() |
+---------------------+
| root@180.169.60.146 |
+---------------------+
1 row in set (0.02 sec)
mysql> show grants for 'root'@'%' \G
*************************** 1. row ***************************
Grants for root@%: GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'root'@'%' WITH GRANT OPTION
1 row in set (0.02 sec)
检查京东云RDS的环境
MySQL版本为5.7.21
注意: 京东云RDS实例的用户权限是以schema为基础的. 需要在创建迁移job前,通过京东云RDS为该MySQL实例创建两个schema: dtle(存储dtle元数据) 和 迁移的目标库
mysql> select user();
+---------------------------+
| user() |
+---------------------------+
| actiontech@180.169.60.146 |
+---------------------------+
1 row in set (0.00 sec)
mysql> show grants for 'actiontech'@'%';
+------------------------------------------------------------+
| Grants for actiontech@% |
+------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'actiontech'@'%' |
| GRANT ALL PRIVILEGES ON `actiontech`.* TO 'actiontech'@'%' |
+------------------------------------------------------------+
2 rows in set (0.00 sec)
申请京东云ECS
需要申请京东云ECS, 用于
示例主机IP为192.168.0.17
, 规格是1c4g40g
安装并配置dtle
安装dtle:
rpm -ivh dtle-xxx.rpm
配置 /etc/dtle/nomad.hcl
:
# 省略未修改配置
bind_addr = "192.168.0.17"
advertise {
http = "192.168.0.17"
rpc = "192.168.0.17"
serf = "192.168.0.17"
}
启动dtle:
systemctl start dtle-consul dtle-nomad
增加复制任务
复制配置文件 job.json 内容如下:
{
"Job": {
"ID":"ali-jd-demo",
"Datacenters": ["dc1"],
"TaskGroups": [{
"Name": "src",
"Tasks": [{
"Name": "src",
"Driver": "dtle",
"Config": {
"Gtid":"",
"ReplicateDoDb": [{
"TableSchema": "actiontech",
"Tables": []
}],
"SrcConnectionConfig": {
"Host":"rm-xxxx.mysql.rds.aliyuncs.com",
"Port":"3306",
"User":"root",
"Password":"Acti0ntech"
},
"DestConnectionConfig": {
"Host":"mysql-cn-east-2-yyyy.public.jcloud.com",
"Port":"3306",
"User":"actiontech",
"Password":"Acti0ntech"
}
}
}]
}, {
"Name": "dest",
"Tasks": [{
"Name": "dest",
"Driver": "dtle",
"Config": {
"DestType": "mysql"
}
}]
}]
}
}
向dtle发布任务:
curl -XPOST "192.168.0.17:4646/v1/jobs" -d @job.json
检查任务运行状态:
curl -XGET "192.168.0.17:4646/v1/job/ali-jd-demo" -s | jq '.Status'
其他
如要使用链路压缩等功能, 可参照MySQL的跨数据中心的双向复制
consul 默认只能从从本机查询。若要从外部访问KV,请更改/etc/dtle/consul.hcl中的 client_addr
。
并相应配置nomad.hcl。