一、安装docker
1、安装docker
> sudo pacman -S docker
- 查看版本
[zls@archlinux tidb-docker-compose]$ sudo docker version
[sudo] zls 的密码:
Client:
Version: 18.09.3-ce
API version: 1.39
Go version: go1.12
Git commit: 774a1f4eee
Built: Thu Feb 28 20:38:40 2019
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.09.3-ce
API version: 1.39 (minimum version 1.12)
Go version: go1.12
Git commit: 774a1f4eee
Built: Thu Feb 28 20:37:49 2019
OS/Arch: linux/amd64
Experimental: false
2、启动docker
> sudo systemctl start docker
启动遇到的问题
- 错误:
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
- 查看错误:
systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: inactive (dead) (Result: exit-code) since Tue 2017-08-22 16:36:27 +03; 1s ago
Docs: https://docs.docker.com
Process: 2295 ExecStart=/usr/bin/dockerd -H fd:// (code=exited, status=1/FAILURE)
Main PID: 2295 (code=exited, status=1/FAILURE)Aug 22 16:36:27 devops systemd[1]: Failed to start Docker Application Container Engine.
Aug 22 16:36:27 devops systemd[1]: docker.service: Unit entered failed state.
Aug 22 16:36:27 devops systemd[1]: docker.service: Failed with result 'exit-code'.
Aug 22 16:36:27 devops systemd[1]: docker.service: Service hold-off time over, scheduling restart.
Aug 22 16:36:27 devops systemd[1]: Stopped Docker Application Container Engine.
Aug 22 16:36:27 devops systemd[1]: docker.service: Start request repeated too quickly.
Aug 22 16:36:27 devops systemd[1]: Failed to start Docker Application Container Engine
从上面可以看出, 在 docker 的启动入口文件中配置了 host 相关的信息, 而在 docker 的配置文件中也配置了 host 的信息, 所以发生了冲突。 解决办法:
- 建议将 docker 启动入口文件中的 -H fd:// 删除, 再重启 docker 服务即可
#ExecStart=/usr/bin/dockerd -H fd://
ExecStart=/usr/bin/dockerd
- 在 docker 启动入口中设置
当然你也可以在启动入口配置监听的端口和本地 socket 信息
> vim /lib/systemd/system/docker.service # Ubuntu的路径; CentOS 的路径为: /usr/lib/systemd/system/docker.service
#ExecStart=/usr/bin/dockerd -H fd://
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
#ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375
最下面两条配置是等价的, docker 默认的本地 socket 文件就在/var/run/docker.sock
3、开机启动docker
> sudo systemctl enable docker
4、关掉开机启动docker
> sudo systemclt disable docker
二、安装docker-compose
1、安装docker-compose
> sudo pacman -S docker-compose
- 查看版本
[zls@archlinux tidb-docker-compose]$ docker-compose version
docker-compose version 1.23.2, build unknown
docker-py version: 3.7.0
CPython version: 3.7.2
OpenSSL version: OpenSSL 1.1.1b 26 Feb 2019
三、安装TiDB
1、 进入工作目录
> cd work
2、创建tidb目录
> mkdir tidb
3、下载 tidb-docker-compose
> git clone https://github.com/pingcap/tidb-docker-compose.git
4、 创建集群
> cd tidb-docker-compose && docker-compose pull # Get the latest Docker images
[zls@archlinux tidb-docker-compose]$ sudo docker-compose pull
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
Pulling dashboard-installer ... done
5、启动集群
> docker-compose up -d
[zls@archlinux tidb-docker-compose]$ sudo docker-compose up -d
Creating tidb-docker-compose_prometheus_1 ... done
Creating tidb-docker-compose_grafana_1 ... done
Creating tidb-docker-compose_pd1_1 ... done
Creating tidb-docker-compose_pd0_1 ... done
Creating tidb-docker-compose_pd2_1 ... done
Creating tidb-docker-compose_dashboard-installer_1 ... done
Creating tidb-docker-compose_pushgateway_1 ... done
Creating tidb-docker-compose_tidb-vision_1 ... done
Creating tidb-docker-compose_tikv0_1 ... done
Creating tidb-docker-compose_tikv2_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
6、访问集群
> mysql -h 127.0.0.1 -P 4000 -u root
[zls@archlinux tidb-docker-compose]$ mysql -h 127.0.0.1 -P 4000 -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.7.10-TiDB-v3.0.0-beta-148-ge767c5b5b MySQL Community Server (Apache License 2.0)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| INFORMATION_SCHEMA |
| PERFORMANCE_SCHEMA |
| mysql |
| test |
+--------------------+
4 rows in set (0.001 sec)
访问集群 Grafana 监控页面:http://localhost:3000 默认用户名和密码均为 admin。