docker化離線安裝tidb
阿新 • • 發佈:2018-12-12
TiDB Docker 部署方案
下載需要的安裝包:
- Docker(17.06.0 及以上版本)— 儘量多往上幾個版本
- container-selinux
下載地址:
離線安裝docker:
[[email protected] tools]# ll /tools/
-rw-r--r-- 1 maintain 26888 Sep 10 15:00 container-selinux-2.9-4.el7.noarch.rpm
-rw-r--r-- 1 maintain 21649924 Sep 10 15:00 docker-ce-18.02.0.ce-1.el7.centos.x86_64.rpm
[ [email protected] tools]# rpm -ivh docker-ce-17.06.2.ce-1.el7.centos.x86_64.rpm
warning: docker-ce-17.06.2.ce-1.el7.centos.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
error: Failed dependencies:
container-selinux >= 2.9 is needed by docker-ce-17.06.2.ce-1.el7.centos.x86_64
[ [email protected] tools]# rpm -ivh container-selinux-2.9-4.el7.noarch.rpm
/etc/host.conf: line 3: bad command `nospoof on'
warning: container-selinux-2.9-4.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
policycoreutils-python is needed by container-selinux-2:2.9-4.el7.noarch
[ [email protected] tools]# yum install policycoreutils-python -y
啟動docker:
systemctl start docker
驗證安裝成功:
[[email protected] tools]# docker --version
Docker version 18.02.0-ce, build fc4de44
離線安裝需要的映象
docker化安裝需要的幾個映象:
- pingcap/tikv
- pingcap/tidb
- pingcap/pd
因為是離線安裝沒法聯網,需要找臺聯網的機器將需要的映象拉取下來,然後匯入到本地。
docker打包映象:
docker save -o pushgateway.tar prom/pushgateway
docker匯入本地映象:
docker load < pushgateway.tar
檢視映象:
[[email protected] tidb]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
pingcap/tikv latest 2137505c6458 32 hours ago 183MB
pingcap/tidb latest ecce6a8b587c 32 hours ago 57.2MB
pingcap/pd latest 4545a7c5fe00 3 days ago 72MB
安裝部署Tidb
測試環境,計劃部署單機的Tidb,一個tikv,一個tipd,一個tidb,資料盤掛載 /data
啟動順序:pd—>kv---->tidb
啟動pd
docker run -d --name pd \
-p 2379:2379 \
-p 2380:2380 \
-v /etc/localtime:/etc/localtime:ro \
-v /data:/data \
pingcap/pd:latest \
--name="pd" \
--data-dir="/data/pd" \
--client-urls="http://0.0.0.0:2379" \
--advertise-client-urls="http://192.168.7.79:2379" \
--peer-urls="http://0.0.0.0:2380" \
--advertise-peer-urls="http://192.168.7.79:2380" \
--initial-cluster="pd=http://192.168.79:2380"
啟動kv
docker run -d --name tikv \
-p 20160:20160 \
--ulimit nofile=1000000:1000000 \
-v /etc/localtime:/etc/localtime:ro \
-v /data:/data \
pingcap/tikv:latest \
--addr="0.0.0.0:20160" \
--advertise-addr="192.168.7.79:20160" \
--data-dir="/data/tikv" \
--pd="192.168.7.79:2379"
啟動tidb
docker run -d --name tidb \
-p 4000:4000 \
-p 10080:10080 \
-v /etc/localtime:/etc/localtime:ro \
pingcap/tidb:latest \
--store=tikv \
--path="192.168.7.79:2379"
檢視docker程序:
[[email protected] tools]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c6c7daac3959 pingcap/tidb:latest "/tidb-server --stor…" 3 hours ago Up 3 hours 0.0.0.0:4000->4000/tcp, 0.0.0.0:10080->10080/tcp tidb
7d5588363995 pingcap/tikv:latest "/tikv-server --addr…" 3 hours ago Up 3 hours 0.0.0.0:20160->20160/tcp tikv
d2dd696140d7 pingcap/pd:latest "/pd-server --name=p…" 3 hours ago Up 3 hours 0.0.0.0:2379-2380->2379-2380/tcp pd
status為up則正常
使用MySQL客戶端連線進行驗證:
[[email protected] tools]# 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.10-TiDB-v2.1.0-rc.1-73-g30ae420 MySQL Community Server (Apache License 2.0)
Copyright (c) 2000, 2017, 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 |
| PERFORMANCE_SCHEMA |
| mysql |
| test |
+--------------------+
5 rows in set (0.00 sec)
附 用到的r幾個docke命令:
- docker ps 檢視正在執行的容易,-a 是全部
- docker stop $(docker ps -a -q) // stop停止所有容器
- docker stop/start CONTAINER ID //停止/開啟 某一個容器
- docker rm $(docker ps -a -q) // remove刪除所有容器
- docker logs CONTAINER ID //獲取某個容器的日誌
- docker exec -it c6c7daac3959 sh //在執行的容器中執行命令
例:
/ # top
Mem: 20316448K used, 243535064K free, 103120K shrd, 437288K buff, 13737252K cac
CPU: 0% usr 0% sys 0% nic 100% idle 0% io 0% irq 0% sirq
Load average: 0.00 0.01 0.05 2/1020 109
PID PPID USER STAT VSZ %VSZ CPU %CPU COMMAND
1 0 root S 610m 0% 4 0% /tidb-server --store=tikv --path=1
103 0 root S 1580 0% 17 0% sh
109 103 root R 1512 0% 26 0% top
/ # exit