作者:马莹乐

爱可生研发团队成员,负责 mysql 中间件和数据库管理平台的测试。擅长找茬(测试技术爱好者),欢迎大家试用 dtle~

本文来源:原创投稿

*爱可生开源社区出品,原创内容未经授权不得随意使用,转载请联系小编并注明来源。

dtle 是一款爱可生 MySQL 开源数据传输中间件,此文简要介绍初步使用方法。
项目地址:https://github.com/actiontech/dtle

一、下载安装

环境说明:
  • 准备三台主机,主机名分别为:node4、node5、node6
  • 三台均为 agent,另将 node4 和 node5 作为 manager

1.1 下载

下载 dtle 最新的 release rpm 包

地址:https://github.com/actiontech/dtle/releases

dtle 安装包下载:

  1. wget https://github.com/actiontech/dtle/releases/download/v2.19.11.0/dtle-2.19.11.0.x86_64.rpm

1.2 安装

安装步骤:

https://actiontech.github.io/dtle-docs-cn/4/4.0_installation.html

分别将 node4,node5 和 node6 的 dtle 安装完成。

1.3 启动 dtle

dtle 安装完成后,并未启动,需要先配置 dtle 的 conf 文件,再启动。

1.4 配置 dtle.conf

配置相关说明:

https://actiontech.github.io/dtle-docs-cn/4/4.1nodeconfiguration.html

dtle.conf 准备:以下配置文件替分别替换原有 dtle.conf(/opt/dtle/etc/dtle/dtle.conf)

node4 的 dtle.conf
  1. # Setup data dir

  2. data_dir = "/opt/dtle/data"

  3. log_level = "DEBUG"

  4. log_file = "/opt/dtle.log"

  5. #log_to_stdout = true


  6. bind_addr = "172.100.9.4"


  7. # Modify our port to avoid a collision with server

  8. ports {

  9. http = 8190

  10. }


  11. # Enable the manager

  12. manager {

  13. enabled = true


  14. # Self-elect, should be 3 or 5 for production,

  15. # Addresses to attempt to join when the server starts.

  16. join = [ "172.100.9.4","172.100.9.5" ]

  17. }


  18. # Enable the agent

  19. agent {

  20. enabled = true

  21. managers = ["172.100.9.4:8191","172.100.9.5:8191"]

  22. }


  23. metric{

  24. collection_interval = "15s"

  25. publish_allocation_metrics = "true"

  26. publish_node_metrics = "true"

  27. }


  28. addresses {

  29. http = "172.100.9.4"

  30. rpc = "172.100.9.4"

  31. serf = "172.100.9.4"

  32. }

  33. advertise {

  34. http = "172.100.9.4"

  35. rpc = "172.100.9.4"

  36. serf = "172.100.9.4"

  37. }

node5 的 dtle.conf
  1. # Setup data dir

  2. data_dir = "/opt/dtle/data"

  3. log_level = "DEBUG"

  4. log_file = "/opt/dtle.log"

  5. #log_to_stdout = true


  6. bind_addr = "172.100.9.5"


  7. # Modify our port to avoid a collision with server

  8. ports {

  9. http = 8190

  10. }


  11. # Enable the manager

  12. manager {

  13. enabled = true


  14. # Self-elect, should be 3 or 5 for production,

  15. # Addresses to attempt to join when the server starts.

  16. join = [ "172.100.9.4","172.100.9.5" ]

  17. }


  18. # Enable the agent

  19. agent {

  20. enabled = true

  21. managers = ["172.100.9.4:8191","172.100.9.5:8191"]

  22. }


  23. metric{

  24. collection_interval = "15s"

  25. publish_allocation_metrics = "true"

  26. publish_node_metrics = "true"

  27. }


  28. addresses {

  29. http = "172.100.9.5"

  30. rpc = "172.100.9.5"

  31. serf = "172.100.9.5"

  32. }

  33. advertise {

  34. http = "172.100.9.5"

  35. rpc = "172.100.9.5"

  36. serf = "172.100.9.5"

  37. }

node6 的 dtle.conf

  1. # Setup data dir

  2. data_dir = "/opt/dtle/data"

  3. log_level = "DEBUG"

  4. log_file = "/opt/dtle.log"

  5. #log_to_stdout = true


  6. bind_addr = "172.100.9.6"


  7. # Modify our port to avoid a collision with server

  8. ports {

  9. http = 8190

  10. }


  11. # Enable the manager

  12. manager {

  13. enabled = false


  14. # Self-elect, should be 3 or 5 for production,

  15. # Addresses to attempt to join when the server starts.

  16. join = [ "172.100.9.4","172.100.9.5" ]

  17. }


  18. # Enable the agent

  19. agent {

  20. enabled = true

  21. managers = ["172.100.9.4:8191","172.100.9.5:8191"]

  22. }


  23. metric{

  24. collection_interval = "15s"

  25. publish_allocation_metrics = "true"

  26. publish_node_metrics = "true"

  27. }


  28. addresses {

  29. http = "172.100.9.6"

  30. rpc = "172.100.9.6"

  31. serf = "172.100.9.6"

  32. }

  33. advertise {

  34. http = "172.100.9.6"

  35. rpc = "172.100.9.6"

  36. serf = "172.100.9.6"

  37. }

1.5 启动 dtle

启动命令说明:

https://actiontech.github.io/dtle-docs-cn/4/4.2_command.html

1.6 查看 3 个节点 dtle 进程

node 4

node 5

node 6

1.7 尝试查看 dtle 架构是否符合预期

命令说明:

https://actiontech.github.io/dtle-docs-cn/4/4.2_command.html

其中,members 展示的是集群中 manager 节点的信息。

HTTP API:

https://actiontech.github.io/dtle-docs-cn/4/4.4httpapi.html

输出内容为 json 格式,可以安装 jq,使之格式化展示。

二、源端/目标端准备

MySQL 迁移用户准备。

2.1 创建用户

源端用户创建,

目标端用户创建,

有关源端/目标端用户的最小权限说明:

https://actiontech.github.io/dtle-docs-cn/4/4.5mysqluser_privileges.html

2.2 数据准备

源端数据准备,

目标端测试前库表情况,

2.3 创建 job

创建全量 + 增量,表级别迁移 job,分别使用 node5 和 node6 节点的 dtle 作为源端和目标端迁移的 agent。

job 配置相关参数:

https://actiontech.github.io/dtle-docs-cn/4/4.3jobconfiguration.html

2.3.1 准备 job.json

job.json

  1. {

  2. "Name":"have_a_try",

  3. "Failover":false,

  4. "Orders":[],

  5. "Type":"synchronous",

  6. "Tasks":[

  7. {

  8. "Type":"Src",

  9. "NodeId":"ee97dc49-85ed-febc-4d3c-cfbfa87f46bd",

  10. "Config":{

  11. "Gtid":"",

  12. "DropTableIfExists":false,

  13. "SkipCreateDbTable":false,

  14. "ApproveHeterogeneous":true,

  15. "ReplChanBufferSize":"600",

  16. "ChunkSize":"2000",

  17. "ExpandSyntaxSupport":false,

  18. "MsgBytesLimit":"20480",

  19. "MsgsLimit":"65536",

  20. "BytesLimit":"67108864",

  21. "GroupMaxSize":"1",

  22. "GroupTimeout":"100",

  23. "SqlFilter":[],

  24. "ReplicateDoDb":[

  25. {

  26. "TableSchema":"test",

  27. "Tables":[

  28. {

  29. "TableName":"test1"

  30. }

  31. ]

  32. }

  33. ],

  34. "ConnectionConfig":{

  35. "Host":"172.100.9.1",

  36. "Port":"3306",

  37. "User":"src_test",

  38. "Password":"test"

  39. }

  40. }

  41. },

  42. {

  43. "Type":"Dest",

  44. "NodeId":"e623aedd-5c37-da67-4ddf-1a82ce1ac298",

  45. "Config":{

  46. "ParallelWorkers":"1",

  47. "ConnectionConfig":{

  48. "Host":"172.100.9.2",

  49. "Port":"3306",

  50. "User":"dest_test",

  51. "Password":"test"

  52. }

  53. }

  54. }

  55. ]

  56. }

其中 NodeId 可通过命令或者 HTTP API 查询得知。

2.3.2 创建 job

创建 job 试用 HTTP API:

https://actiontech.github.io/dtle-docs-cn/4/4.4httpapi.html

创建完成后查询 job 状态为 running。

job 详细信息可使用 HTTP API 查询,示例:

  1. [

  2. {

  3. "CreateIndex":109,

  4. "ID":"ba13f3e1-0630-f141-4c60-a1f36c61cdb3",

  5. "JobModifyIndex":2372,

  6. "JobSummary":{

  7. "Constraints":null,

  8. "CreateIndex":109,

  9. "Datacenters":[

  10. "dc1"

  11. ],

  12. "EnforceIndex":false,

  13. "Failover":false,

  14. "ID":"ba13f3e1-0630-f141-4c60-a1f36c61cdb3",

  15. "JobModifyIndex":2372,

  16. "ModifyIndex":2372,

  17. "Name":"have_a_try",

  18. "Orders":[


  19. ],

  20. "Region":"global",

  21. "Status":"running",

  22. "StatusDescription":"",

  23. "Tasks":[

  24. {

  25. "Config":{

  26. "GroupMaxSize":"1",

  27. "ChunkSize":"2000",

  28. "BinlogFile":"1.000002",

  29. "MsgsLimit":"65536",

  30. "GroupTimeout":"100",

  31. "DropTableIfExists":false,

  32. "ExpandSyntaxSupport":false,

  33. "BytesLimit":"67108864",

  34. "MsgBytesLimit":"20480",

  35. "ReplChanBufferSize":"600",

  36. "NatsAddr":"172.100.9.6:8193",

  37. "ApproveHeterogeneous":true,

  38. "SqlFilter":[


  39. ],

  40. "BinlogPos":4261,

  41. "ConnectionConfig":{

  42. "Host":"172.100.9.1",

  43. "Port":"3306",

  44. "User":"src_test",

  45. "Password":"*"

  46. },

  47. "TrafficAgainstLimits":0,

  48. "Gtid":"8868d98f-af5e-11e8-9aa9-0242ac110002:1-16",

  49. "ReplicateDoDb":[

  50. {

  51. "TableSchema":"test",

  52. "Tables":[

  53. {

  54. "TableName":"test1"

  55. }

  56. ]

  57. }

  58. ],

  59. "SkipCreateDbTable":false

  60. },

  61. "ConfigLock":{


  62. },

  63. "Constraints":null,

  64. "Driver":"MySQL",

  65. "Leader":false,

  66. "NodeID":"ee97dc49-85ed-febc-4d3c-cfbfa87f46bd",

  67. "NodeName":"",

  68. "Type":"Src"

  69. },

  70. {

  71. "Config":{

  72. "BinlogFile":"1.000002",

  73. "BinlogPos":4261,

  74. "ConnectionConfig":{

  75. "Host":"172.100.9.2",

  76. "Port":"3306",

  77. "User":"dest_test",

  78. "Password":"*"

  79. },

  80. "Gtid":"8868d98f-af5e-11e8-9aa9-0242ac110002:1-16",

  81. "ParallelWorkers":"1",

  82. "NatsAddr":"172.100.9.6:8193"

  83. },

  84. "ConfigLock":{


  85. },

  86. "Constraints":null,

  87. "Driver":"MySQL",

  88. "Leader":true,

  89. "NodeID":"e623aedd-5c37-da67-4ddf-1a82ce1ac298",

  90. "NodeName":"",

  91. "Type":"Dest"

  92. }

  93. ],

  94. "Type":"synchronous"

  95. },

  96. "ModifyIndex":2372,

  97. "Name":"have_a_try",

  98. "Status":"running",

  99. "StatusDescription":"",

  100. "Type":"synchronous"

  101. }

  102. ]

2.4 查询目标端迁移情况

目标端迁移前后对比:

新增两个库其中 test 库是我们 job 迁移的结果。

dtle 库相关说明:

https://actiontech.github.io/dtle-docs-cn/3/3.3impacton_dest.html

2.5 在源端执行普通 DML 操作

2.6 在源端执行普通 DDL 操作

小结

更多用法,详见项目文档,欢迎试用~

https://actiontech.github.io/dtle-docs-cn/
如果有更多关于 DTLE 相关的技术问题,
可以扫码或直接加入官方QQ技术交流群(852990221)进行交流。