在 TiDB 集群的部署中,除了推荐的 Ansible 方式之外,PingCAP 近期推出了一款全新的部署工具–TiUP。
本次测试单机单实例(单个节点只运行一个 TiDB 或者 TiKV 实例)下 TiUP 部署 TiDB 集群及 TiFlash。
使用到的主机如下:

所使用的 topology.yaml 文件的内容如下,请根据实际环境修改:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# # Global variables are applied to all deployments and as the default value of # # them if the specific deployment value missing. global: user: "tidb" ssh_port: 22 deploy_dir: "/home/tidb/deploy" data_dir: "/data1" # # Monitored variables are used to all the machine monitored: node_exporter_port: 9100 blackbox_exporter_port: 9115 # deploy_dir: "/home/tidb/deploy/monitored-9100" # data_dir: "/data1/monitored-9100" # log_dir: "/home/tidb/deploy/monitored-9100/log" # # Server configs are used to specify the runtime configuration of TiDB components # # All configuration items can be found in TiDB docs: # # - TiDB: https://pingcap.com/docs/stable/reference/configuration/tidb-server/configuration-file/ # # - TiKV: https://pingcap.com/docs/stable/reference/configuration/tikv-server/configuration-file/ # # - PD: https://pingcap.com/docs/stable/reference/configuration/pd-server/configuration-file/ # # All configuration items use points to represent the hierarchy, e.g: # # readpool.storage.use-unified-pool # # ^ ^ # # You can overwrite this configuration via instance-level `config` field server_configs: tidb: log.slow-threshold: 300 binlog.enable: false binlog.ignore-error: false tikv: # server.grpc-concurrency: 4 # raftstore.apply-pool-size: 2 # raftstore.store-pool-size: 2 # rocksdb.max-sub-compactions: 1 # storage.block-cache.capacity: "16GB" # readpool.unified.max-thread-count: 12 readpool.storage.use-unified-pool: true readpool.coprocessor.use-unified-pool: true pd: schedule.leader-schedule-limit: 4 schedule.region-schedule-limit: 2048 schedule.replica-schedule-limit: 64 replication.enable-placement-rules: true tiflash: logger.level: "info" # pump: # gc: 7 pd_servers: - host: 192.168.10.1 # ssh_port: 22 # name: "pd-1" # client_port: 2379 # peer_port: 2380 # deploy_dir: "/home/tidb/deploy/pd-2379" # data_dir: "/data1/pd-2379" # log_dir: "/home/tidb/deploy/pd-2379/log" # numa_node: "0,1" # # Config is used to overwrite the `server_configs.pd` values # config: # schedule.max-merge-region-size: 20 # schedule.max-merge-region-keys: 200000 - host: 192.168.10.2 - host: 192.168.10.3 tidb_servers: - host: 192.168.10.1 # ssh_port: 22 # port: 4000 # status_port: 10080 # deploy_dir: "/home/tidb/deploy/tidb-4000" # log_dir: "/home/tidb/deploy/tidb-4000/log" # numa_node: "0,1" # # Config is used to overwrite the `server_configs.tidb` values # config: # log.slow-query-file: tidb-slow-overwrited.log - host: 192.168.10.2 - host: 192.168.10.3 tikv_servers: - host: 192.168.10.4 # ssh_port: 22 # port: 20160 # status_port: 20180 # deploy_dir: "/home/tidb/deploy/tikv-20160" # data_dir: "/data1/tikv-20160" # log_dir: "/home/tidb/deploy/tikv-20160/log" # numa_node: "0,1" # # Config is used to overwrite the `server_configs.tikv` values # config: # server.grpc-concurrency: 4 # server.labels: { zone: "zone1", dc: "dc1", host: "host1" } - host: 192.168.10.5 - host: 192.168.10.6 tiflash_servers: - host: 192.168.10.7 # ssh_port: 22 # tcp_port: 9000 # http_port: 8123 # flash_service_port: 3930 # flash_proxy_port: 20170 # flash_proxy_status_port: 20292 # metrics_port: 8234 # deploy_dir: /home/tidb/deploy/tiflash-9000 # data_dir: /data1/tiflash-9000 # log_dir: /home/tidb/deploy/tiflash-9000/log # numa_node: "0,1" # # Config is used to overwrite the `server_configs.tiflash` values # config: # logger.level: "info" # learner_config: # log-level: "info" # - host: 192.168.10.15 # - host: 192.168.10.16 # pump_servers: # - host: 192.168.10.17 # ssh_port: 22 # port: 8250 # deploy_dir: "/home/tidb/deploy/pump-8249" # data_dir: "/data1/pump-8249" # log_dir: "/home/tidb/deploy/pump-8249/log" # numa_node: "0,1" # # Config is used to overwrite the `server_configs.drainer` values # config: # gc: 7 # - host: 192.168.10.18 # - host: 192.168.10.19 # drainer_servers: # - host: 192.168.10.17 # port: 8249 # data_dir: "/data1/drainer-8249" # # if drainer doesn't have checkpoint, use initial commitTS to initial checkpoint # # will get a latest timestamp from pd if setting to be -1 (default -1) # commit_ts: -1 # deploy_dir: "/home/tidb/deploy/drainer-8249" # log_dir: "/home/tidb/deploy/drainer-8249/log" # numa_node: "0,1" # # Config is used to overwrite the `server_configs.drainer` values # config: # syncer.db-type: "mysql" # syncer.to.host: "127.0.0.1" # syncer.to.user: "root" # syncer.to.password: "" # syncer.to.port: 3306 # - host: 192.168.10.19 monitoring_servers: - host: 192.168.10.3 # ssh_port: 22 # port: 9090 # deploy_dir: "/home/tidb/deploy/prometheus-8249" # data_dir: "/data1/prometheus-8249" # log_dir: "/home/tidb/deploy/prometheus-8249/log" grafana_servers: - host: 192.168.10.3 # port: 3000 # deploy_dir: /home/tidb/deploy/grafana-3000 alertmanager_servers: - host: 192.168.10.3 # ssh_port: 22 # web_port: 9093 # cluster_port: 9094 # deploy_dir: "/home/tidb/deploy/alertmanager-9093" # data_dir: "/data1/alertmanager-9093" # log_dir: "/home/tidb/deploy/alertmanager-9093/log" |
此时即可开始在 TiUP 节点上进行部署了:
1 2 3 |
tiup cluster deploy tidb-test v4.0.0-rc ./topology.yaml --user root |
部署开始前会根据 yaml 文件,生成当前的拓扑图,供 DBA 检查和修改:

输入节点的 root 密码之后,就可以开始部署了,日志如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
Attention: 1. If the topology is not what you expected, check your yaml file. 2. Please confirm there is no port/directory conflicts in same host. Do you want to continue? [y/N]: y Input SSH password: + Generate SSH keys ... Done + Download TiDB components - Download pd:v4.0.0-rc ... Done - Download tikv:v4.0.0-rc ... Done - Download tidb:v4.0.0-rc ... Done - Download tiflash:v4.0.0-rc ... Done - Download prometheus:v4.0.0-rc ... Done - Download grafana:v4.0.0-rc ... Done - Download alertmanager:v0.17.0 ... Done - Download node_exporter:v0.17.0 ... Done - Download blackbox_exporter:v0.12.0 ... Done + Initialize target host environments - Prepare 192.168.10.1:22 ... Done - Prepare 192.168.10.2:22 ... Done - Prepare 192.168.10.3:22 ... Done - Prepare 192.168.10.4:22 ... Done - Prepare 192.168.10.5:22 ... Done - Prepare 192.168.10.6:22 ... Done - Prepare 192.168.10.7:22 ... Done + Copy files - Copy pd -> 192.168.10.1 ... Done - Copy pd -> 192.168.10.2 ... Done - Copy pd -> 192.168.10.3 ... Done - Copy tikv -> 192.168.10.4 ... Done - Copy tikv -> 192.168.10.5 ... Done - Copy tikv -> 192.168.10.6 ... Done - Copy tidb -> 192.168.10.1 ... Done - Copy tidb -> 192.168.10.2 ... Done - Copy tidb -> 192.168.10.3 ... Done - Copy tiflash -> 192.168.10.7 ... Done - Copy prometheus -> 192.168.10.3 ... Done - Copy grafana -> 192.168.10.3 ... Done - Copy alertmanager -> 192.168.10.3 ... Done - Copy node_exporter -> 192.168.10.4 ... Done - Copy node_exporter -> 192.168.10.5 ... Done - Copy node_exporter -> 192.168.10.6 ... Done - Copy node_exporter -> 192.168.10.7 ... Done - Copy node_exporter -> 192.168.10.1 ... Done - Copy node_exporter -> 192.168.10.2 ... Done - Copy node_exporter -> 192.168.10.3 ... Done - Copy blackbox_exporter -> 192.168.10.4 ... Done - Copy blackbox_exporter -> 192.168.10.5 ... Done - Copy blackbox_exporter -> 192.168.10.6 ... Done - Copy blackbox_exporter -> 192.168.10.7 ... Done - Copy blackbox_exporter -> 192.168.10.1 ... Done - Copy blackbox_exporter -> 192.168.10.2 ... Done - Copy blackbox_exporter -> 192.168.10.3 ... Done Deployed cluster `tidb-test` successfully, you can start the cluster via `tiup cluster start tidb-test` |
可以看到部署肥肠的方便。随后,启动整个集群:
1 2 3 |
tiup cluster start tidb-test |
启动日志如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
[tidb@tidb1pd1 ~]$ tiup cluster start tidb-test Starting component `cluster`: /home/tidb/.tiup/components/cluster/v0.4.9/cluster start tidb-test Starting cluster tidb-test... + [ Serial ] - SSHKeySet: privateKey=/home/tidb/.tiup/storage/cluster/clusters/tidb-test/ssh/id_rsa, publicKey=/home/tidb/.tiup/storage/cluster/clusters/tidb-test/ssh/id_rsa.pub + [Parallel] - UserSSH: user=tidb, host=192.168.10.3 + [Parallel] - UserSSH: user=tidb, host=192.168.10.1 + [Parallel] - UserSSH: user=tidb, host=192.168.10.2 + [Parallel] - UserSSH: user=tidb, host=192.168.10.6 + [Parallel] - UserSSH: user=tidb, host=192.168.10.3 + [Parallel] - UserSSH: user=tidb, host=192.168.10.3 + [Parallel] - UserSSH: user=tidb, host=192.168.10.4 + [Parallel] - UserSSH: user=tidb, host=192.168.10.7 + [Parallel] - UserSSH: user=tidb, host=192.168.10.3 + [Parallel] - UserSSH: user=tidb, host=192.168.10.5 + [Parallel] - UserSSH: user=tidb, host=192.168.10.2 + [Parallel] - UserSSH: user=tidb, host=192.168.10.3 + [Parallel] - UserSSH: user=tidb, host=192.168.10.1 + [ Serial ] - ClusterOperate: operation=StartOperation, options={Roles:[] Nodes:[] Force:false Timeout:0} Starting component pd Starting instance pd 192.168.10.2:2379 Starting instance pd 192.168.10.3:2379 Starting instance pd 192.168.10.1:2379 Start pd 192.168.10.3:2379 success Start pd 192.168.10.1:2379 success Start pd 192.168.10.2:2379 success Starting component node_exporter Starting instance 192.168.10.1 Start 192.168.10.1 success Starting component blackbox_exporter Starting instance 192.168.10.1 Start 192.168.10.1 success Starting component node_exporter Starting instance 192.168.10.2 Start 192.168.10.2 success Starting component blackbox_exporter Starting instance 192.168.10.2 Start 192.168.10.2 success Starting component node_exporter Starting instance 192.168.10.3 Start 192.168.10.3 success Starting component blackbox_exporter Starting instance 192.168.10.3 Start 192.168.10.3 success Starting component tikv Starting instance tikv 192.168.10.6:20160 Starting instance tikv 192.168.10.5:20160 Starting instance tikv 192.168.10.4:20160 Start tikv 192.168.10.4:20160 success Start tikv 192.168.10.5:20160 success Start tikv 192.168.10.6:20160 success Starting component node_exporter Starting instance 192.168.10.4 Start 192.168.10.4 success Starting component blackbox_exporter Starting instance 192.168.10.4 Start 192.168.10.4 success Starting component node_exporter Starting instance 192.168.10.5 Start 192.168.10.5 success Starting component blackbox_exporter Starting instance 192.168.10.5 Start 192.168.10.5 success Starting component node_exporter Starting instance 192.168.10.6 Start 192.168.10.6 success Starting component blackbox_exporter Starting instance 192.168.10.6 Start 192.168.10.6 success Starting component tidb Starting instance tidb 192.168.10.3:4000 Starting instance tidb 192.168.10.1:4000 Starting instance tidb 192.168.10.2:4000 Start tidb 192.168.10.3:4000 success Start tidb 192.168.10.2:4000 success Start tidb 192.168.10.1:4000 success Starting component tiflash Starting instance tiflash 192.168.10.7:9000 Start tiflash 192.168.10.7:9000 success Starting component node_exporter Starting instance 192.168.10.7 Start 192.168.10.7 success Starting component blackbox_exporter Starting instance 192.168.10.7 Start 192.168.10.7 success Starting component prometheus Starting instance prometheus 192.168.10.3:9090 Start prometheus 192.168.10.3:9090 success Starting component grafana Starting instance grafana 192.168.10.3:3000 Start grafana 192.168.10.3:3000 success Starting component alertmanager Starting instance alertmanager 192.168.10.3:9093 Start alertmanager 192.168.10.3:9093 success Checking service state of pd 192.168.10.2 Active: active (running) since Mon 2020-04-20 10:36:12 CST; 52s ago 192.168.10.1 Active: active (running) since Mon 2020-04-20 10:36:13 CST; 52s ago 192.168.10.3 Active: active (running) since Mon 2020-04-20 10:36:12 CST; 52s ago Checking service state of tikv 192.168.10.5 Active: active (running) since Mon 2020-04-20 10:36:24 CST; 41s ago 192.168.10.4 Active: active (running) since Mon 2020-04-20 10:36:23 CST; 41s ago 192.168.10.6 Active: active (running) since Mon 2020-04-20 10:36:23 CST; 41s ago Checking service state of tidb 192.168.10.1 Active: active (running) since Mon 2020-04-20 10:36:40 CST; 27s ago 192.168.10.2 Active: active (running) since Mon 2020-04-20 10:36:39 CST; 27s ago 192.168.10.3 Active: active (running) since Mon 2020-04-20 10:36:38 CST; 28s ago Checking service state of tiflash 192.168.10.7 Active: active (running) since Mon 2020-04-20 10:36:49 CST; 19s ago Checking service state of prometheus 192.168.10.3 Active: active (running) since Mon 2020-04-20 10:36:54 CST; 13s ago Checking service state of grafana 192.168.10.3 Active: active (running) since Mon 2020-04-20 10:36:56 CST; 13s ago Checking service state of alertmanager 192.168.10.3 Active: active (running) since Mon 2020-04-20 10:37:02 CST; 8s ago Started cluster `tidb-test` successfully |
可以看到节点逐个启动了。TiUP 提供了 ansible 所不具有的查看集群状态的方式:
1 2 3 |
tiup cluster display tidb-test |

详细的显示了 IP,节点角色,端口,资源状态,数据目录,部署目录等等详细信息,非常有用。

下篇将使用 TiUP 搭建单机多实例集群。