原 【DB宝57】使用Docker-Compose快速部署TiDB集群环境
一、快速部署
参考连接:https://docs.pingcap.com/zh/tidb/v3.0/deploy-test-cluster-using-docker-compose
本文档介绍如何在单机上通过 Docker Compose 快速一键部署一套 TiDB 测试集群。Docker Compose 可以通过一个 YAML 文件定义多个容器的应用服务,然后一键启动或停止。
确保你的机器上已安装:
- Docker(17.06.0 及以上版本)
- Docker Compose
- Git
1.1、下载tidb-docker-compose
1 2 3 4 5 6 7 8 | [root@docker35 ~]# git clone https://github.com/pingcap/tidb-docker-compose.git Cloning into 'tidb-docker-compose'... remote: Enumerating objects: 8, done. remote: Counting objects: 100% (8/8), done. remote: Compressing objects: 100% (8/8), done. remote: Total 554 (delta 0), reused 6 (delta 0), pack-reused 546 Receiving objects: 100% (554/554), 284.17 KiB | 204.00 KiB/s, done. Resolving deltas: 100% (243/243), done. |
1.2、创建并启动集群
创建并启动集群,获取最新 Docker 镜像:
1 | cd tidb-docker-compose && docker-compose pull && docker-compose up -d |
执行过程:
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 | [root@docker35 ~]# cd tidb-docker-compose/ [root@docker35 tidb-docker-compose]# ll total 64 drwxr-xr-x 3 root root 60 Apr 14 15:13 compose drwxr-xr-x 4 root root 4096 Apr 14 15:13 config drwxr-xr-x 3 root root 59 Apr 14 15:13 dashboard-installer drwxr-xr-x 3 root root 19 Apr 14 15:13 docker -rw-r--r-- 1 root root 11343 Apr 14 15:13 docker-compose-binlog.yml -rw-r--r-- 1 root root 292 Apr 14 15:13 docker-compose-test.yml -rw-r--r-- 1 root root 1566 Apr 14 15:13 docker-compose-tiflash-nightly.yml -rw-r--r-- 1 root root 5445 Apr 14 15:13 docker-compose.yml -rw-r--r-- 1 root root 4736 Apr 14 15:13 docker-swarm.yml -rw-r--r-- 1 root root 11294 Apr 14 15:13 LICENSE drwxr-xr-x 2 root root 24 Apr 14 15:13 pd -rw-r--r-- 1 root root 11335 Apr 14 15:13 README.md drwxr-xr-x 2 root root 24 Apr 14 15:13 tidb drwxr-xr-x 2 root root 24 Apr 14 15:13 tidb-binlog drwxr-xr-x 2 root root 24 Apr 14 15:13 tidb-vision drwxr-xr-x 2 root root 24 Apr 14 15:13 tikv drwxr-xr-x 6 root root 95 Apr 14 15:13 tispark drwxr-xr-x 2 root root 29 Apr 14 15:13 tools [root@docker35 tidb-docker-compose]# du -sh . 3.3M . [root@docker35 tidb-docker-compose]# docker-compose pull && docker-compose up -d Pulling pd0 ... done Pulling pd1 ... done Pulling pd2 ... done Pulling tikv0 ... done Pulling tikv1 ... done Pulling tikv2 ... done Pulling tidb ... done Pulling tispark-master ... done Pulling tispark-slave0 ... done Pulling tidb-vision ... done Pulling pushgateway ... done Pulling prometheus ... done Pulling grafana ... done Building with native build. Learn about native build in Compose here: https://docs.docker.com/go/compose-native-build/ Creating network "tidb-docker-compose_default" with the default driver Creating tidb-docker-compose_prometheus_1 ... done Creating tidb-docker-compose_grafana_1 ... done Creating tidb-docker-compose_pd0_1 ... done Creating tidb-docker-compose_pd2_1 ... done Creating tidb-docker-compose_pd1_1 ... done Creating tidb-docker-compose_tidb-vision_1 ... done Creating tidb-docker-compose_pushgateway_1 ... done Creating tidb-docker-compose_tikv2_1 ... done Creating tidb-docker-compose_tikv0_1 ... done Creating tidb-docker-compose_tikv1_1 ... done Creating tidb-docker-compose_tidb_1 ... done Creating tidb-docker-compose_tispark-master_1 ... done Creating tidb-docker-compose_tispark-slave0_1 ... done [root@docker35 tidb-docker-compose]# docker ps | grep tidb 0f0c9308b722 pingcap/tispark:latest "/opt/spark/sbin/sta…" 20 minutes ago Up 26 seconds 0.0.0.0:38081->38081/tcp tidb-docker-compose_tispark-slave0_1 b0cfd6181ced pingcap/tispark:latest "/opt/spark/sbin/sta…" 20 minutes ago Up 26 seconds 0.0.0.0:7077->7077/tcp, 0.0.0.0:8080->8080/tcp tidb-docker-compose_tispark-master_1 8d3eb1f375c4 pingcap/tidb:latest "/tidb-server --stor…" 20 minutes ago Up 25 seconds 0.0.0.0:4000->4000/tcp, 0.0.0.0:10080->10080/tcp tidb-docker-compose_tidb_1 15c524d6a77d pingcap/tikv:latest "/tikv-server --addr…" 20 minutes ago Up 2 seconds 20160/tcp tidb-docker-compose_tikv2_1 34e5e542e6af pingcap/tikv:latest "/tikv-server --addr…" 20 minutes ago Up 1 second 20160/tcp tidb-docker-compose_tikv1_1 cf16e9611c14 pingcap/tikv:latest "/tikv-server --addr…" 20 minutes ago Up 32 seconds 20160/tcp tidb-docker-compose_tikv0_1 560daefe9121 pingcap/tidb-vision:latest "/bin/sh -c 'sed -i …" 20 minutes ago Up 26 seconds 80/tcp, 443/tcp, 2015/tcp, 0.0.0.0:8010->8010/tcp tidb-docker-compose_tidb-vision_1 25ba4d9a30d7 prom/pushgateway:v0.3.1 "/bin/pushgateway --…" 20 minutes ago Up 35 seconds 9091/tcp tidb-docker-compose_pushgateway_1 cd1c88da452c pingcap/pd:latest "/pd-server --name=p…" 20 minutes ago Up 26 seconds 2380/tcp, 0.0.0.0:1029->2379/tcp tidb-docker-compose_pd0_1 ce363e945cdc prom/prometheus:v2.2.1 "/bin/prometheus --l…" 20 minutes ago Up 36 seconds 0.0.0.0:9090->9090/tcp tidb-docker-compose_prometheus_1 5768329d5789 pingcap/pd:latest "/pd-server --name=p…" 20 minutes ago Up 32 seconds 2380/tcp, 0.0.0.0:1027->2379/tcp tidb-docker-compose_pd2_1 f132ec8ae049 pingcap/pd:latest "/pd-server --name=p…" 20 minutes ago Up 32 seconds 2380/tcp, 0.0.0.0:1028->2379/tcp tidb-docker-compose_pd1_1 cc36a50a0d74 grafana/grafana:6.0.1 "/run.sh" 20 minutes ago Up 33 seconds 0.0.0.0:3000->3000/tcp tidb-docker-compose_grafana_1 [root@docker35 tidb-docker-compose]# docker ps | grep tidb | wc -l 13 |
二、访问集群
2.1、访问TiDB
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 | [root@docker35 tidb-docker-compose]# mysql -h 127.0.0.1 -P 4000 -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.25-TiDB-v5.0.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | INFORMATION_SCHEMA | | METRICS_SCHEMA | | PERFORMANCE_SCHEMA | | mysql | | test | +--------------------+ 5 rows in set (0.00 sec) mysql> create database lhrdb charset utf8mb4; Query OK, 0 rows affected (0.07 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | INFORMATION_SCHEMA | | METRICS_SCHEMA | | PERFORMANCE_SCHEMA | | lhrdb | | mysql | | test | +--------------------+ 6 rows in set (0.00 sec) |
2.2、访问集群 Grafana 监控
访问集群 Grafana 监控页面:http://localhost:3000 默认用户名和密码均为 admin。如下内容都可以监控到:
例如:
2.3、集群数据可视化
集群数据可视化(https://github.com/pingcap/tidb-vision):http://localhost:8010
如果启用了 tidb-vision,可以通过 http://localhost:8010 查看。
2.4、访问Spark Web UI
三、自定义集群
在完成快速部署后,以下组件已默认部署:3 个 PD,3 个 TiKV,1 个 TiDB 和监控组件 Prometheus,Pushgateway,Grafana 以及 tidb-vision。
如果想自定义集群,可以直接修改 docker-compose.yml
,但是手动修改比较繁琐而且容易出错,强烈建议使用 Helm 模板引擎生成 docker-compose.yml
文件。