TiDB Binlog 部署拓扑

本文介绍在部署最小拓扑集群的基础上,同时部署 TiDB Binlog。TiDB Binlog 是目前广泛使用的增量同步组件,可提供准实时备份和同步功能。

拓扑信息

实例个数物理机配置IP配置
TiDB316 VCore 32 GB10.0.1.1
10.0.1.2
10.0.1.3
默认端口配置;
开启 enable_binlog;
开启 ignore-error
PD34 VCore 8 GB10.0.1.4
10.0.1.5
10.0.1.6
默认端口配置
TiKV316 VCore 32 GB10.0.1.7
10.0.1.8
10.0.1.9
默认端口配置
Pump38 VCore 16GB10.0.1.1
10.0.1.7
10.0.1.8
默认端口配置;
设置 GC 时间 7 天
Drainer18 VCore 16GB10.0.1.12默认端口配置;
设置默认初始化 commitTS -1 为最近的时间戳
配置下游目标 TiDB 10.0.1.12:4000

拓扑模版

简单 TiDB Binlog 配置模板(下游为 MySQL)

  1. # # Global variables are applied to all deployments and used as the default value of
  2. # # the deployments if a specific deployment value is missing.
  3. global:
  4. user: "tidb"
  5. ssh_port: 22
  6. deploy_dir: "/tidb-deploy"
  7. data_dir: "/tidb-data"
  8. server_configs:
  9. tidb:
  10. binlog.enable: true
  11. binlog.ignore-error: true
  12. pd_servers:
  13. - host: 10.0.1.4
  14. - host: 10.0.1.5
  15. - host: 10.0.1.6
  16. tidb_servers:
  17. - host: 10.0.1.1
  18. - host: 10.0.1.2
  19. - host: 10.0.1.3
  20. tikv_servers:
  21. - host: 10.0.1.7
  22. - host: 10.0.1.8
  23. - host: 10.0.1.9
  24. pump_servers:
  25. - host: 10.0.1.1
  26. - host: 10.0.1.2
  27. - host: 10.0.1.3
  28. drainer_servers:
  29. - host: 10.0.1.12
  30. config:
  31. syncer.db-type: "tidb"
  32. syncer.to.host: "10.0.1.12"
  33. syncer.to.user: "root"
  34. syncer.to.password: ""
  35. syncer.to.port: 4000
  36. monitoring_servers:
  37. - host: 10.0.1.10
  38. grafana_servers:
  39. - host: 10.0.1.10
  40. alertmanager_servers:
  41. - host: 10.0.1.10
  42. ``` 简单 TiDB Binlog 配置模板(下游为 file)

# Global variables are applied to all deployments and used as the default value of

# the deployments if a specific deployment value is missing.

global: user: “tidb” ssh_port: 22 deploy_dir: “/tidb-deploy” data_dir: “/tidb-data”

server_configs: tidb: binlog.enable: true binlog.ignore-error: true

pd_servers:

  • host: 10.0.1.4
  • host: 10.0.1.5
  • host: 10.0.1.6 tidb_servers:
  • host: 10.0.1.1
  • host: 10.0.1.2
  • host: 10.0.1.3 tikv_servers:
  • host: 10.0.1.7
  • host: 10.0.1.8
  • host: 10.0.1.9

pump_servers:

  • host: 10.0.1.1
  • host: 10.0.1.2
  • host: 10.0.1.3 drainer_servers:
  • host: 10.0.1.12

    drainer meta data directory path

    data_dir: “/path/to/save/data” config: syncer.db-type: “file”

    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”

monitoring_servers:

  • host: 10.0.1.10

grafana_servers:

  • host: 10.0.1.10

alertmanager_servers:

  • host: 10.0.1.10 ``` 详细 TiDB Binlog 配置模板
  1. # # Global variables are applied to all deployments and used as the default value of
  2. # # the deployments if a specific deployment value is missing.
  3. global:
  4. user: "tidb"
  5. ssh_port: 22
  6. deploy_dir: "/tidb-deploy"
  7. data_dir: "/tidb-data"
  8. # # Monitored variables are applied to all the machines.
  9. monitored:
  10. node_exporter_port: 9100
  11. blackbox_exporter_port: 9115
  12. # deploy_dir: "/tidb-deploy/monitored-9100"
  13. # data_dir: "/tidb-data/monitored-9100"
  14. # log_dir: "/tidb-deploy/monitored-9100/log"
  15. # # Server configs are used to specify the runtime configuration of TiDB components.
  16. # # All configuration items can be found in TiDB docs:
  17. # # - TiDB: https://docs.pingcap.com/zh/tidb/stable/tidb-configuration-file
  18. # # - TiKV: https://docs.pingcap.com/zh/tidb/stable/tikv-configuration-file
  19. # # - PD: https://docs.pingcap.com/zh/tidb/stable/pd-configuration-file
  20. # # All configuration items use points to represent the hierarchy, e.g:
  21. # # readpool.storage.use-unified-pool
  22. # #
  23. # # You can overwrite this configuration via the instance-level `config` field.
  24. server_configs:
  25. tidb:
  26. log.slow-threshold: 300
  27. binlog.enable: true
  28. binlog.ignore-error: true
  29. tikv:
  30. # server.grpc-concurrency: 4
  31. # raftstore.apply-pool-size: 2
  32. # raftstore.store-pool-size: 2
  33. # rocksdb.max-sub-compactions: 1
  34. # storage.block-cache.capacity: "16GB"
  35. # readpool.unified.max-thread-count: 12
  36. readpool.storage.use-unified-pool: false
  37. readpool.coprocessor.use-unified-pool: true
  38. pd:
  39. schedule.leader-schedule-limit: 4
  40. schedule.region-schedule-limit: 2048
  41. schedule.replica-schedule-limit: 64
  42. pd_servers:
  43. - host: 10.0.1.4
  44. # ssh_port: 22
  45. # name: "pd-1"
  46. # client_port: 2379
  47. # peer_port: 2380
  48. # deploy_dir: "/tidb-deploy/pd-2379"
  49. # data_dir: "/tidb-data/pd-2379"
  50. # log_dir: "/tidb-deploy/pd-2379/log"
  51. # numa_node: "0,1"
  52. # # The following configs are used to overwrite the `server_configs.pd` values.
  53. # config:
  54. # schedule.max-merge-region-size: 20
  55. # schedule.max-merge-region-keys: 200000
  56. - host: 10.0.1.5
  57. - host: 10.0.1.6
  58. tidb_servers:
  59. - host: 10.0.1.1
  60. # ssh_port: 22
  61. # port: 4000
  62. # status_port: 10080
  63. # deploy_dir: "/tidb-deploy/tidb-4000"
  64. # log_dir: "/tidb-deploy/tidb-4000/log"
  65. # numa_node: "0,1"
  66. # # The following configs are used to overwrite the `server_configs.tidb` values.
  67. # config:
  68. # log.slow-query-file: tidb-slow-overwrited.log
  69. - host: 10.0.1.2
  70. - host: 10.0.1.3
  71. tikv_servers:
  72. - host: 10.0.1.7
  73. # ssh_port: 22
  74. # port: 20160
  75. # status_port: 20180
  76. # deploy_dir: "/tidb-deploy/tikv-20160"
  77. # data_dir: "/tidb-data/tikv-20160"
  78. # log_dir: "/tidb-deploy/tikv-20160/log"
  79. # numa_node: "0,1"
  80. # # The following configs are used to overwrite the `server_configs.tikv` values.
  81. # config:
  82. # server.grpc-concurrency: 4
  83. # server.labels: { zone: "zone1", dc: "dc1", host: "host1" }
  84. - host: 10.0.1.8
  85. - host: 10.0.1.9
  86. pump_servers:
  87. - host: 10.0.1.1
  88. ssh_port: 22
  89. port: 8250
  90. deploy_dir: "/tidb-deploy/pump-8250"
  91. data_dir: "/tidb-data/pump-8250"
  92. # The following configs are used to overwrite the `server_configs.pump` values.
  93. config:
  94. gc: 7
  95. - host: 10.0.1.2
  96. ssh_port: 22
  97. port: 8250
  98. deploy_dir: "/tidb-deploy/pump-8250"
  99. data_dir: "/tidb-data/pump-8250"
  100. # The following configs are used to overwrite the `server_configs.pump` values.
  101. config:
  102. gc: 7
  103. - host: 10.0.1.3
  104. ssh_port: 22
  105. port: 8250
  106. deploy_dir: "/tidb-deploy/pump-8250"
  107. data_dir: "/tidb-data/pump-8250"
  108. # The following configs are used to overwrite the `server_configs.pump` values.
  109. config:
  110. gc: 7
  111. drainer_servers:
  112. - host: 10.0.1.12
  113. port: 8249
  114. deploy_dir: "/tidb-deploy/drainer-8249"
  115. data_dir: "/tidb-data/drainer-8249"
  116. # If drainer doesn't have a checkpoint, use initial commitTS as the initial checkpoint.
  117. # Will get a latest timestamp from pd if commit_ts is set to -1 (the default value).
  118. commit_ts: -1
  119. # The following configs are used to overwrite the `server_configs.drainer` values.
  120. config:
  121. syncer.db-type: "tidb"
  122. syncer.to.host: "10.0.1.12"
  123. syncer.to.user: "root"
  124. syncer.to.password: ""
  125. syncer.to.port: 4000
  126. syncer.to.checkpoint:
  127. schema: "tidb_binlog"
  128. type: "tidb"
  129. host: "10.0.1.14"
  130. user: "root"
  131. password: "123"
  132. port: 4000
  133. - host: 10.0.1.13
  134. port: 8249
  135. deploy_dir: "/tidb-deploy/drainer-8249"
  136. data_dir: "/tidb-data/drainer-8249"
  137. # If Drainer does not have a checkpoint, use the initial commitTS as the initial checkpoint.
  138. # If commit_ts is set to -1 (the default value), you will get a latest timestamp from PD.
  139. commit_ts: -1
  140. # The following configurations are used to overwrite the `server_configs.drainer` values.
  141. config:
  142. syncer.db-type: "kafka"
  143. syncer.replicate-do-db:
  144. - db1
  145. - db2
  146. syncer.to.kafka-addrs: "10.0.1.20:9092,10.0.1.21:9092,10.0.1.22:9092"
  147. syncer.to.kafka-version: "2.4.0"
  148. syncer.to.topic-name: "asyouwish"
  149. monitoring_servers:
  150. - host: 10.0.1.10
  151. # ssh_port: 22
  152. # port: 9090
  153. # deploy_dir: "/tidb-deploy/prometheus-8249"
  154. # data_dir: "/tidb-data/prometheus-8249"
  155. # log_dir: "/tidb-deploy/prometheus-8249/log"
  156. grafana_servers:
  157. - host: 10.0.1.10
  158. # port: 3000
  159. # deploy_dir: /tidb-deploy/grafana-3000
  160. alertmanager_servers:
  161. - host: 10.0.1.10
  162. # ssh_port: 22
  163. # web_port: 9093
  164. # cluster_port: 9094
  165. # deploy_dir: "/tidb-deploy/alertmanager-9093"
  166. # data_dir: "/tidb-data/alertmanager-9093"
  167. # log_dir: "/tidb-deploy/alertmanager-9093/log"

以上 TiDB 集群拓扑文件中,详细的配置项说明见通过 TiUP 部署 TiDB 集群的拓扑文件配置

关键参数介绍

拓扑配置模版的关键参数如下:

  • server_configs.tidb.binlog.enable: true

    开启 TiDB Binlog 服务,默认为 false。

  • server_configs.tidb.binlog.ignore-error: true

    高可用场景建议开启,如果设置为 true,发生错误时,TiDB 会停止写入 TiDB Binlog,并且在监控项 tidb_server_critical_error_total 上计数加 1;如果设置为 false,一旦写入 TiDB Binlog 失败,会停止整个 TiDB 的服务。

  • drainer_servers.config.syncer.db-type

    TiDB Binlog 的下游类型,目前支持 mysqltidbkafkafile

  • drainer_servers.config.syncer.to

    TiDB Binlog 的下游配置。根据 db-type 的不同,该选项可配置下游数据库的连接参数、Kafka 的连接参数、文件保存路径。详细说明可参见 TiDB Binlog 配置说明

TiDB Binlog 部署拓扑 - 图1

注意

  • 编辑配置文件模版时,如无需自定义端口或者目录,仅修改 IP 即可。
  • 无需手动创建配置文件中的 tidb 用户,TiUP cluster 组件会在目标主机上自动创建该用户。可以自定义用户,也可以和中控机的用户保持一致。
  • 如果部署目录配置为相对路径,会部署在用户的 Home 目录下。