0

离线部署Tidb集群环境部署实践(linux)

red_hope 2020-11-30
710

前言

前面测试了在线部署Tidb单机测试环境及单机集群环境(用单机模拟集群),在线部署对于测试学习人员确实很有帮助,简化了安装步骤,但实际安装中,离线部署较多,下面将离线部署方法进行测试。
注:本测试是在个人虚拟机上进行的测试。
本次测试,不再使用root安装,全程采用tidb用户进行安装,以求接近实战。

系统环境:

操作系统:Red Hat Enterprise Linux 7.8
HOST1:192.168.198.130
HOST1:192.168.198.130  
HOST3:192.168.198.133
#虚拟机机器数量不足,用同样一台来凑,但两台已足够说明集群配置的方法
目录:/u01/tidb
程序目录:tidb-deploy
数据目录:tidb-data

在生产中,有很多最佳实践,可以参考tidb官网。

一、下载软件版包

Tidb软件包有两种下载方式:
(1)从网站直接下载:https://pingcap.com/download-cn
(2)通过自己的测试环境下载(需联网,一般为自己的虚拟机或者dmz区环境),然后把安装包上传到生产环境中。这个环境我们叫 准备环境,需要在准备环境下下载安装包。
本文介绍第二种方法。

(1)在准备环境建tidb主机用户

建用户:
useradd  tidb 
修改密码:
passwd tidb

(2)在准备环境下载tiup

安装程序的打包,首先要用到tiup,因此需要在准备环境中先安装tiup
使用tidb主机用户下载tiup:

curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh

运行结果如下:

[tidb@eomsdr ~]$ curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 8606k  100 8606k    0     0  1212k      0  0:00:07  0:00:07 --:--:-- 1285k
WARN: adding root certificate via internet: https://tiup-mirrors.pingcap.com/root.json
You can revoke this by remove /home/tidb/.tiup/bin/7b8e153f2e2d0928.root.json
Set mirror to https://tiup-mirrors.pingcap.com success
Detected shell: bash
Shell profile:  /home/tidb/.bash_profile
/home/tidb/.bash_profile has been modified to add tiup to PATH
open a new terminal or source /home/tidb/.bash_profile to use it
Installed path: /home/tidb/.tiup/bin/tiup
===============================================
Have a try:     tiup playground
===============================================
[tidb@eomsdr ~]$
[tidb@eomsdr ~]$ which tiup
~/.tiup/bin/tiup

如果在下载过程中报:tiup-mirrors.pingcap.com 域名找不到,可以看一下上一篇文章在线部署Tidb单机测试环境及单机集群环境(用单机模拟集群)

(3)在准备环境中下载安装包

首先要确认下载的版本:
使用如下命令查看:
tiup list tidb

[tidb@eomsdr ~]$ tiup list tidb
Available versions for tidb:
Version        Installed  Release                              Platforms
-------        ---------  -------                              ---------
nightly                   2020-11-30T10:20:11+08:00            linux/amd64,linux/arm64,darwin/amd64
v3.0                      2020-04-16T16:58:06+08:00            linux/amd64,darwin/amd64
v3.0.0                    2020-04-16T14:03:31+08:00            linux/amd64,darwin/amd64
v3.0.1                    2020-04-27T19:38:36+08:00            linux/amd64,linux/arm64,darwin/amd64
v3.0.2                    2020-04-16T23:55:11+08:00            linux/amd64,darwin/amd64
v3.0.3                    2020-04-17T00:16:31+08:00            linux/amd64,darwin/amd64
v3.0.4                    2020-04-17T00:22:46+08:00            linux/amd64,darwin/amd64
v3.0.5                    2020-04-17T00:29:45+08:00            linux/amd64,darwin/amd64
v3.0.6                    2020-04-17T00:39:33+08:00            linux/amd64,darwin/amd64
v3.0.7                    2020-04-17T00:46:32+08:00            linux/amd64,darwin/amd64
v3.0.8                    2020-04-17T00:54:19+08:00            linux/amd64,darwin/amd64
v3.0.9                    2020-04-17T01:00:58+08:00            linux/amd64,darwin/amd64
v3.0.10                   2020-03-13T14:11:53.774527401+08:00  linux/amd64,darwin/amd64
v3.0.11                   2020-04-17T01:09:20+08:00            linux/amd64,darwin/amd64
v3.0.12                   2020-04-17T01:16:04+08:00            linux/amd64,darwin/amd64
v3.0.13                   2020-04-26T17:25:01+08:00            linux/amd64,darwin/amd64
v3.0.14                   2020-05-09T21:11:49+08:00            linux/amd64,linux/arm64,darwin/amd64
v3.0.15                   2020-06-05T16:57:59+08:00            linux/amd64,linux/arm64,darwin/amd64
v3.0.16                   2020-07-03T20:09:43+08:00            linux/amd64,linux/arm64,darwin/amd64
v3.0.17                   2020-08-03T15:34:18+08:00            linux/amd64,linux/arm64,darwin/amd64
v3.0.18                   2020-08-21T20:08:59+08:00            linux/amd64,linux/arm64,darwin/amd64
v3.0.19                   2020-09-25T18:27:32+08:00            linux/amd64,linux/arm64,darwin/amd64
v3.1.0-beta               2020-05-22T14:35:59+08:00            linux/amd64,linux/arm64,darwin/amd64
v3.1.0-beta.1             2020-05-22T15:22:30+08:00            linux/amd64,linux/arm64,darwin/amd64
v3.1.0-beta.2             2020-05-22T15:28:20+08:00            linux/amd64,linux/arm64,darwin/amd64
v3.1.0-rc                 2020-05-22T15:56:23+08:00            linux/amd64,linux/arm64,darwin/amd64
v3.1.0                    2020-05-22T15:34:33+08:00            linux/amd64,linux/arm64,darwin/amd64
v3.1.1                    2020-04-30T21:02:32+08:00            linux/amd64,linux/arm64,darwin/amd64
v3.1.2                    2020-06-04T17:57:09+08:00            linux/amd64,linux/arm64,darwin/amd64
v4.0.0-beta               2020-05-26T11:18:05+08:00            linux/amd64,linux/arm64,darwin/amd64
v4.0.0-beta.1             2020-05-26T11:42:48+08:00            linux/amd64,linux/arm64,darwin/amd64
v4.0.0-beta.2             2020-05-26T11:56:51+08:00            linux/amd64,linux/arm64,darwin/amd64
v4.0.0-rc                 2020-05-26T14:56:06+08:00            linux/amd64,linux/arm64,darwin/amd64
v4.0.0-rc.1               2020-04-29T01:03:31+08:00            linux/amd64,linux/arm64,darwin/amd64
v4.0.0-rc.2               2020-05-15T21:54:51+08:00            linux/amd64,linux/arm64,darwin/amd64
v4.0.0                    2020-05-28T20:10:10+08:00            linux/amd64,linux/arm64,darwin/amd64
v4.0.1                    2020-06-12T21:22:29+08:00            linux/amd64,linux/arm64,darwin/amd64
v4.0.2                    2020-07-01T20:01:44+08:00            linux/amd64,linux/arm64,darwin/amd64
v4.0.3                    2020-07-25T01:11:14+08:00            linux/amd64,linux/arm64,darwin/amd64
v4.0.4                    2020-07-31T16:52:24+08:00            linux/amd64,linux/arm64,darwin/amd64
v4.0.5                    2020-08-31T23:57:20+08:00            linux/amd64,linux/arm64,darwin/amd64
v4.0.6                    2020-09-15T22:17:45+08:00            linux/amd64,linux/arm64,darwin/amd64
v4.0.7                    2020-09-29T20:19:45+08:00            linux/amd64,linux/arm64,darwin/amd64
v4.0.8                    2020-10-30T19:36:32+08:00            linux/amd64,linux/arm64,darwin/amd64
[tidb@eomsdr ~]$ 

我们选择较新的v4.0.8下载,下载脚本如下:
tiup mirror clone tidb-community-server-v4.0.8-linux-amd64 v4.0.8 --os=linux --arch=amd64
其中,v4.0.8是版本信息,如果是其它版本,对应修改即可。
打包情况如下:

[tidb@eomsdr tidb]$ tiup mirror clone tidb-community-server-v4.0.8-linux-amd64 v4.0.8 --os=linux --arch=amd64
Start to clone mirror, targetDir is tidb-community-server-v4.0.8-linux-amd64, selectedVersions are [v4.0.8]
If this does not meet expectations, please abort this process, read `tiup mirror clone --help` and run again
Arch [amd64]
OS [linux]
download https://tiup-mirrors.pingcap.com/alertmanager-v0.17.0-linux-amd64.tar.gz 22.54 MiB / 22.54 MiB 100.00% 1.39 MiB p/s                                                                                                                 
download https://tiup-mirrors.pingcap.com/bench-v1.2.4-linux-amd64.tar.gz 6.65 MiB / 6.65 MiB 100.00% 1.46 MiB p/s                                                                                                                           
download https://tiup-mirrors.pingcap.com/blackbox_exporter-v0.12.0-linux-amd64.tar.gz 4.72 MiB / 4.72 MiB 100.00% 1.50 MiB p/s                                                                                                              
download https://tiup-mirrors.pingcap.com/br-v4.0.8-linux-amd64.tar.gz 34.04 MiB / 34.04 MiB 100.00% 1.21 MiB p/s                                                                                                                            
download https://tiup-mirrors.pingcap.com/cdc-v4.0.8-linux-amd64.tar.gz 38.06 MiB / 38.06 MiB 100.00% 1.28 MiB p/s                                                                                                                           
download https://tiup-mirrors.pingcap.com/client-v0.0.6-linux-amd64.tar.gz 7.84 MiB / 7.84 MiB 100.00% 1.30 MiB p/s                                                                                                                          
download https://tiup-mirrors.pingcap.com/cluster-v1.2.4-linux-amd64.tar.gz 9.99 MiB / 9.99 MiB 100.00% 1.36 MiB p/s                                                                                                                         
download https://tiup-mirrors.pingcap.com/ctl-v4.0.8-linux-amd64.tar.gz 169.83 MiB / 169.83 MiB 100.00% 1.21 MiB p/s                                                                                                                         
download https://tiup-mirrors.pingcap.com/dm-v1.2.4-linux-amd64.tar.gz 9.83 MiB / 9.83 MiB 100.00% 1.48 MiB p/s                                                                                                                              
download https://tiup-mirrors.pingcap.com/dm-master-v2.0.0-linux-amd64.tar.gz 29.83 MiB / 29.83 MiB 100.00% 1.60 MiB p/s                                                                                                                     
download https://tiup-mirrors.pingcap.com/dm-worker-v2.0.0-linux-amd64.tar.gz 40.86 MiB / 40.86 MiB 100.00% 1.28 MiB p/s                                                                                                                     
download https://tiup-mirrors.pingcap.com/dmctl-v2.0.0-linux-amd64.tar.gz 24.98 MiB / 24.98 MiB 100.00% 1.49 MiB p/s                                                                                                                         
download https://tiup-mirrors.pingcap.com/doc-v0.0.3-linux-amd64.tar.gz 2.26 MiB / 2.26 MiB 100.00% 1.58 MiB p/s                                                                                                                             
download https://tiup-mirrors.pingcap.com/drainer-v4.0.8-linux-amd64.tar.gz 21.22 MiB / 21.22 MiB 100.00% 1.24 MiB p/s                                                                                                                       
download https://tiup-mirrors.pingcap.com/dumpling-v4.0.8-linux-amd64.tar.gz 13.61 MiB / 13.61 MiB 100.00% 513.61 KiB p/s                                                                                                                    
download https://tiup-mirrors.pingcap.com/errdoc-v4.0.7-linux-amd64.tar.gz 10.10 MiB / 10.10 MiB 100.00% 573.43 KiB p/s                                                                                                                      
download https://tiup-mirrors.pingcap.com/grafana-v4.0.8-linux-amd64.tar.gz 54.25 MiB / 54.25 MiB 100.00% 1.17 MiB p/s                                                                                                                       
download https://tiup-mirrors.pingcap.com/insight-v0.3.1-linux-amd64.tar.gz 2.97 MiB / 2.97 MiB 100.00% 1.59 MiB p/s                                                                                                                         
download https://tiup-mirrors.pingcap.com/mirrors-v0.0.2-linux-amd64.tar.gz 5.27 MiB / 5.27 MiB 100.00% 1.03 MiB p/s                                                                                                                         
download https://tiup-mirrors.pingcap.com/node_exporter-v0.17.0-linux-amd64.tar.gz 6.69 MiB / 6.69 MiB 100.00% 1.32 MiB p/s                                                                                                                  
download https://tiup-mirrors.pingcap.com/package-v0.0.9-linux-amd64.tar.gz 5.55 MiB / 5.55 MiB 100.00% 1.54 MiB p/s                                                                                                                         
download https://tiup-mirrors.pingcap.com/pd-v4.0.8-linux-amd64.tar.gz 38.85 MiB / 38.85 MiB 100.00% 1.46 MiB p/s                                                                                                                            
download https://tiup-mirrors.pingcap.com/pd-recover-v4.0.8-linux-amd64.tar.gz 12.86 MiB / 12.86 MiB 100.00% 1.35 MiB p/s                                                                                                                    
download https://tiup-mirrors.pingcap.com/playground-v1.2.4-linux-amd64.tar.gz 8.28 MiB / 8.28 MiB 100.00% 1.03 MiB p/s                                                                                                                      
download https://tiup-mirrors.pingcap.com/prometheus-v4.0.8-linux-amd64.tar.gz 39.84 MiB / 39.84 MiB 100.00% 1.08 MiB p/s                                                                                                                    
download https://tiup-mirrors.pingcap.com/pump-v4.0.8-linux-amd64.tar.gz 14.78 MiB / 14.78 MiB 100.00% 1.49 MiB p/s                                                                                                                          
download https://tiup-mirrors.pingcap.com/pushgateway-v0.7.0-linux-amd64.tar.gz 6.25 MiB / 6.25 MiB 100.00% 1.48 MiB p/s                                                                                                                     
download https://tiup-mirrors.pingcap.com/server-v1.2.4-linux-amd64.tar.gz 3.64 MiB / 3.64 MiB 100.00% 1.53 MiB p/s                                                                                                                          
download https://tiup-mirrors.pingcap.com/spark-v2.4.3-any-any.tar.gz 219.33 MiB / 219.33 MiB 100.00% 1.17 MiB p/s                                                                                                                           
download https://tiup-mirrors.pingcap.com/tidb-v4.0.8-linux-amd64.tar.gz 39.16 MiB / 39.16 MiB 100.00% 1.08 MiB p/s                                                                                                                          
download https://tiup-mirrors.pingcap.com/tidb-lightning-v4.0.8-linux-amd64.tar.gz 27.49 MiB / 27.49 MiB 100.00% 1.23 MiB p/s                                                                                                                
download https://tiup-mirrors.pingcap.com/tiflash-v4.0.8-linux-amd64.tar.gz 360.61 MiB / 360.61 MiB 100.00% 1.21 MiB p/s                                                                                                                     
download https://tiup-mirrors.pingcap.com/tikv-v4.0.8-linux-amd64.tar.gz 135.46 MiB / 135.46 MiB 100.00% 1.19 MiB p/s                                                                                                                        
download https://tiup-mirrors.pingcap.com/tikv-importer-v4.0.2-linux-amd64.tar.gz 9.85 MiB / 9.85 MiB 100.00% 1.44 MiB p/s                                                                                                                   
download https://tiup-mirrors.pingcap.com/tispark-v2.3.10-any-any.tar.gz 21.32 MiB / 21.32 MiB 100.00% 1.36 MiB p/s                                                                                                                          
download https://tiup-mirrors.pingcap.com/tiup-v1.2.4-linux-amd64.tar.gz 8.41 MiB / 8.41 MiB 100.00% 1.29 MiB p/s                                                                                                                            
download https://tiup-mirrors.pingcap.com/tiup-linux-amd64.tar.gz 8.41 MiB / 8.41 MiB 100.00% 1.38 MiB p/s

下载过程中注意两点:
1、目标文件系统目录至少10G以上
2、宿主机剩余存储至少10G以上。
虽然软件本身只有1.5G,但在测试过程中,笔者发现,虽然宿主机剩余空间大于2G,虚拟机的文件系统剩余空间也大于2G,但下载总是失败,最后清理掉虚拟机及宿主机上的无用程序,空余出较多空间(大于10G)后才下载成功。这一点应是数据库都有剩余空间校验程序导致,在生产换件一般不宜发生,应用程序目录建议100G。

(4)将程序上传到生产环境(安装中控机:192.168.198.130)

先打包,

tar czvf tidb-community-server-v4.0.8-linux-amd64.tar.gz tidb-community-server-v4.0.8-linux-amd64

然后scp到生产环境:

 scp tidb-community-server-v4.0.8-linux-amd64.tar.gz tidb@192.168.198.130:/u01/tidb

传输完成后解压缩tidb-community-server-v4.0.8-linux-amd64.tar.gz,解压后/u01/tidb出现:tidb-community-server-v4.0.8-linux-amd64目录。

(5)生产环境安装tiup

运行 sh tidb-community-server-v4.0.8-linux-amd64/local_install.sh 安装tiup



[tidb@eoms01 tidb]$ sh tidb-community-server-v4.0.8-linux-amd64/local_install.sh
Set mirror to /u01/tidb/tidb-community-server-v4.0.8-linux-amd64 success
Detected shell: bash
Shell profile:  /home/tidb/.bash_profile
/home/tidb/.bash_profile has been modified to to add tiup to PATH
open a new terminal or source /home/tidb/.bash_profile to use it
Installed path: /home/tidb/.tiup/bin/tiup
===============================================
1. source /home/tidb/.bash_profile
2. Have a try:   tiup playground
===============================================

````language

``
注意,尽量不要修改解压后的tidb-community-server-v4.0.8-linux-amd64目录名称,该文件路径为默认镜像路径,如果修改了该文件名称,需要修改镜像路径:tiup mirror set 进行切换

(6)新建程序目录及数据目录

用tiup用户在/u01/tidb下新建目录tidb-data、tidb-deploy,所有主机都需要建:

[tidb@eoms01 tidb]$ ls -lrt
total 12
drwxr-xr-x 3 tidb tidb 4096 Nov 25 20:18 tidb-community-server-v4.0.8-linux-amd64
drwxrwxr-x 2 tidb tidb 4096 Nov 25 20:31 tidb-data
drwxrwxr-x 2 tidb tidb 4096 Nov 25 20:31 tidb-deploy

(7)手动配置 SSH 互信及 sudo 免密码

root用户:
visudo
最后一行加入:
tidb ALL=(ALL) NOPASSWD: ALL

tidb用户:
ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.198.133

如果没有/.ssh/id_rsa.pub,则新建/.ssh,用ssh-keygen命令生成。
测试是否可以直接在对端运行命令:
ssh 192.168.198.133 date

[tidb@eoms01 ~]$ ssh 192.168.198.133 date
Mon Nov 30 12:35:18 CST 2020
[tidb@eoms01 ~]$ 

如果可以直接运行,表示互信关系建立成功。

(8)编辑拓扑文件

编辑拓扑yaml文件:/topo.yaml ,该文件定义了每个组件所在的主机,部署目录,数据目录、程序端口等信息,现实环境下,不同组件需要跨机框、跨机架、跨冷仓,以实现硬件部署的高可用要求,保障系统安全性。topo.yaml如下:

[tidb@eoms01 tidb]$ vi topo.yaml 
# # 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: "/u01/tidb/tidb-deploy"
 data_dir: "/u01/tidb/tidb-data"

# # Monitored variables are applied to all the machines.
monitored:
 node_exporter_port: 9100
 blackbox_exporter_port: 9115

server_configs:
 tidb:
   log.slow-threshold: 300
 tikv:
   readpool.storage.use-unified-pool: false
   readpool.coprocessor.use-unified-pool: true
 pd:
   replication.enable-placement-rules: true
   replication.location-labels: ["host"]
 tiflash:
   logger.level: "info"

pd_servers:
 - host: 192.168.198.130

tidb_servers:
 - host: 192.168.198.130

tikv_servers:
 - host: 192.168.198.130
   port: 20160
   status_port: 20180
   config:
     server.labels: { host: "logic-host-1" }

 - host: 192.168.198.130
   port: 20161
   status_port: 20181
   config:
     server.labels: { host: "logic-host-2" }

 - host: 192.168.198.133
   port: 20162
   status_port: 20182
   config:
     server.labels: { host: "logic-host-3" }

tiflash_servers:
 - host: 192.168.198.130

monitoring_servers:
 - host: 192.168.198.130

grafana_servers:
 - host: 192.168.198.130
[tidb@eoms01 tidb]$ 

期中,tikv_servers 中设置了第二个机器:192.168.198.133,其它均用本机(192.168.198.130)代替。

(9)开始部署

用tidb用户在/u01/tidb目录下执行:
tiup cluster deploy tidb-yug v4.0.8 ./topo.yaml --user tidb,详细情况如下:

tidb@eoms01 tidb]$  tiup cluster deploy tidb-yug v4.0.8 ./topo.yaml --user tidb
Starting component `cluster`: /home/tidb/.tiup/components/cluster/v1.2.4/tiup-cluster deploy tidb-yug v4.0.8 ./topo.yaml --user tidb –p
Please confirm your topology:
Cluster type:    tidb
Cluster name:    tidb-yug
Cluster version: v4.0.8
Type        Host             Ports                            OS/Arch       Directories
----        ----             -----                            -------       -----------
pd          192.168.198.130  2379/2380                        linux/x86_64  /u01/tidb/tidb-deploy/pd-2379,/u01/tidb/tidb-data/pd-2379
tikv        192.168.198.130  20160/20180                      linux/x86_64  /u01/tidb/tidb-deploy/tikv-20160,/u01/tidb/tidb-data/tikv-20160
tikv        192.168.198.130  20161/20181                      linux/x86_64  /u01/tidb/tidb-deploy/tikv-20161,/u01/tidb/tidb-data/tikv-20161
tikv        192.168.198.133  20162/20182                      linux/x86_64  /u01/tidb/tidb-deploy/tikv-20162,/u01/tidb/tidb-data/tikv-20162
tidb        192.168.198.130  4000/10080                       linux/x86_64  /u01/tidb/tidb-deploy/tidb-4000
tiflash     192.168.198.130  9000/8123/3930/20170/20292/8234  linux/x86_64  /u01/tidb/tidb-deploy/tiflash-9000,/u01/tidb/tidb-data/tiflash-9000
prometheus  192.168.198.130  9090                             linux/x86_64  /u01/tidb/tidb-deploy/prometheus-9090,/u01/tidb/tidb-data/prometheus-9090
grafana     192.168.198.130  3000                             linux/x86_64  /u01/tidb/tidb-deploy/grafana-3000
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
+ Generate SSH keys ... Done
+ Download TiDB components
  - Download pd:v4.0.8 (linux/amd64) ... Done
  - Download tikv:v4.0.8 (linux/amd64) ... Done
  - Download tidb:v4.0.8 (linux/amd64) ... Done
  - Download tiflash:v4.0.8 (linux/amd64) ... Done
  - Download prometheus:v4.0.8 (linux/amd64) ... Done
  - Download grafana:v4.0.8 (linux/amd64) ... Done
  - Download node_exporter:v0.17.0 (linux/amd64) ... Done
  - Download blackbox_exporter:v0.12.0 (linux/amd64) ... Done
+ Initialize target host environments
  - Prepare 192.168.198.130:22 ... Done
  - Prepare 192.168.198.133:22 ... Done
+ Copy files
  - Copy pd -> 192.168.198.130 ... Done
  - Copy tikv -> 192.168.198.130 ... Done
  - Copy tikv -> 192.168.198.130 ... Done
  - Copy tikv -> 192.168.198.133 ... Done
  - Copy tidb -> 192.168.198.130 ... Done
  - Copy tiflash -> 192.168.198.130 ... Done
  - Copy prometheus -> 192.168.198.130 ... Done
  - Copy grafana -> 192.168.198.130 ... Done
  - Copy node_exporter -> 192.168.198.130 ... Done
  - Copy node_exporter -> 192.168.198.133 ... Done
  - Copy blackbox_exporter -> 192.168.198.130 ... Done
  - Copy blackbox_exporter -> 192.168.198.133 ... Done
+ Check status

Enabling component pd
+ Enable cluster
        Enable pd 192.168.198.130:2379 success
+ Enable cluster
+ Enable cluster
Enabling component tikv
        Enabling instance tikv 192.168.198.133:20162
        Enabling instance tikv 192.168.198.130:20160
+ Enable cluster
+ Enable cluster
+ Enable cluster
        Enable tikv 192.168.198.130:20160 success
+ Enable cluster
+ Enable cluster
Enabling component tidb
+ Enable cluster
        Enable tidb 192.168.198.130:4000 success
Enabling component tiflash
+ Enable cluster
        Enable tiflash 192.168.198.130:9000 success
Enabling component prometheus
+ Enable cluster
        Enable prometheus 192.168.198.130:9090 success
Enabling component grafana
+ Enable cluster
+ Enable cluster
Deployed cluster `tidb-yug` successfully, you can start the cluster via `tiup cluster start tidb-yug`

安装过程中会出现部分组件成功、部分组件超时安装的问题,尤其是scp大组件的时候,出现error的情况,在tidb官网上也有很多关于这方面的讨论,很少有明确的说法,其实ssh的默认超时参数足够了,最大的两个问题:
1、空间不够(并不是有空间就可以,建议剩余大于10G以上)
2、本机sudo没有配置、其它机器互信没有配置成功
如果从oracle转来的dba,2一般没啥问题,主要是第1个问题,在测试过程中要注意,否则莫名其妙,权限也对,剩余空间也大于2G,但是执行就是不成功。

另外,在安装过程中会出现:

  • Download TiDB components
    • Download pd:v4.0.8 (linux/amd64) … Done
    • Download tikv:v4.0.8 (linux/amd64) … Done
    • Download tidb:v4.0.8 (linux/amd64) … Done
    • Download tiflash:v4.0.8 (linux/amd64) … Done
    • Download prometheus:v4.0.8 (linux/amd64) … Done
    • Download grafana:v4.0.8 (linux/amd64) … Done
    • Download node_exporter:v0.17.0 (linux/amd64) … Done
    • Download blackbox_exporter:v0.12.0 (linux/amd64) … Done
      实际上是在校验镜像文件中是否有相关组件,自己测试的时候最好把网断掉,观察效果。

(10)启动集群

启动tiup cluster start tidb-yug

[tidb@eoms01 tidb]$ tiup cluster start tidb-yug
Starting component `cluster`: /home/tidb/.tiup/components/cluster/v1.2.4/tiup-cluster start tidb-yug
Starting cluster tidb-yug...
+ [ Serial ] - SSHKeySet: privateKey=/home/tidb/.tiup/storage/cluster/clusters/tidb-yug/ssh/id_rsa, publicKey=/home/tidb/.tiup/storage/cluster/clusters/tidb-yug/ssh/id_rsa.pub
+ [Parallel] - UserSSH: user=tidb, host=192.168.198.130
+ [Parallel] - UserSSH: user=tidb, host=192.168.198.130
+ [Parallel] - UserSSH: user=tidb, host=192.168.198.133
+ [Parallel] - UserSSH: user=tidb, host=192.168.198.130
+ [Parallel] - UserSSH: user=tidb, host=192.168.198.130
+ [Parallel] - UserSSH: user=tidb, host=192.168.198.130
+ [Parallel] - UserSSH: user=tidb, host=192.168.198.130
+ [Parallel] - UserSSH: user=tidb, host=192.168.198.130
+ [ Serial ] - StartCluster
Starting component pd
        Starting instance pd 192.168.198.130:2379
        Start pd 192.168.198.130:2379 success
Starting component node_exporter
        Starting instance 192.168.198.130
        Start 192.168.198.130 success
Starting component blackbox_exporter
        Starting instance 192.168.198.130
        Start 192.168.198.130 success
Starting component tikv
        Starting instance tikv 192.168.198.133:20162
        Starting instance tikv 192.168.198.130:20160
        Starting instance tikv 192.168.198.130:20161
        Start tikv 192.168.198.133:20162 success

        Start tikv 192.168.198.130:20161 success
        Start tikv 192.168.198.130:20160 success
Starting component node_exporter
        Starting instance 192.168.198.133
        Start 192.168.198.133 success
Starting component blackbox_exporter
        Starting instance 192.168.198.133
        Start 192.168.198.133 success
Starting component tidb
        Starting instance tidb 192.168.198.130:4000
        Start tidb 192.168.198.130:4000 success
Starting component tiflash
        Starting instance tiflash 192.168.198.130:9000
        Start tiflash 192.168.198.130:9000 success
Starting component prometheus
        Starting instance prometheus 192.168.198.130:9090
        Start prometheus 192.168.198.130:9090 success
Starting component grafana
        Starting instance grafana 192.168.198.130:3000
        Start grafana 192.168.198.130:3000 success
+ [ Serial ] - UpdateTopology: cluster=tidb-yug
Started cluster `tidb-yug` successfully


(11)查看集群状态

tiup cluster display tidb-yug
tidb-yug:是刚才建的集群的名称
通过该命令,可以看到每个节点上每种组件的状态及安装路径。


[tidb@eoms01 tidb]$ tiup cluster display tidb-yug
Starting component `cluster`: /home/tidb/.tiup/components/cluster/v1.2.4/tiup-cluster display tidb-yug
Cluster type:    tidb
Cluster name:    tidb-yug
Cluster version: v4.0.8
SSH type:        builtin
ID                     Role        Host             Ports                            OS/Arch       Status   Data Dir                             Deploy Dir
--                     ----        ----             -----                            -------       ------   --------                             ----------
192.168.198.130:3000   grafana     192.168.198.130  3000                             linux/x86_64  Up       -                                    /u01/tidb/tidb-deploy/grafana-3000
192.168.198.130:2379   pd          192.168.198.130  2379/2380                        linux/x86_64  Up|L|UI  /u01/tidb/tidb-data/pd-2379          /u01/tidb/tidb-deploy/pd-2379
192.168.198.130:9090   prometheus  192.168.198.130  9090                             linux/x86_64  Up       /u01/tidb/tidb-data/prometheus-9090  /u01/tidb/tidb-deploy/prometheus-9090
192.168.198.130:4000   tidb        192.168.198.130  4000/10080                       linux/x86_64  Up       -                                    /u01/tidb/tidb-deploy/tidb-4000
192.168.198.130:9000   tiflash     192.168.198.130  9000/8123/3930/20170/20292/8234  linux/x86_64  Up       /u01/tidb/tidb-data/tiflash-9000     /u01/tidb/tidb-deploy/tiflash-9000
192.168.198.130:20160  tikv        192.168.198.130  20160/20180                      linux/x86_64  Up       /u01/tidb/tidb-data/tikv-20160       /u01/tidb/tidb-deploy/tikv-20160
192.168.198.130:20161  tikv        192.168.198.130  20161/20181                      linux/x86_64  Up       /u01/tidb/tidb-data/tikv-20161       /u01/tidb/tidb-deploy/tikv-20161
192.168.198.133:20162  tikv        192.168.198.133  20162/20182                      linux/x86_64  Up       /u01/tidb/tidb-data/tikv-20162       /u01/tidb/tidb-deploy/tikv-20162
Total nodes: 8
[tidb@eoms01 tidb]$

(12)进入tidb数据库

使用mysql --host 192.168.198.130 --port 4000 -u root
如果没有mysql命令,建议用redhat的安装包安装mariadb,该软件安装后,同样有mysql的客户端,都是mysql命令,产品归属关系大不一样,mysql数据库,即使是开源的,也是oracle公司的向外提供的,mariadb则是操作系统原生的,通过操作系统自带rpm即可安装。

[tidb@eoms01 tidb]$ mysql --host 192.168.198.130 --port 4000 -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25-TiDB-v4.0.8 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible

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)]> 
MySQL [(none)]> 
MySQL [(none)]> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| INFORMATION_SCHEMA |
| METRICS_SCHEMA     |
| PERFORMANCE_SCHEMA |
| mysql              |
| test               |
+--------------------+
5 rows in set (0.02 sec)

create databse tidb-ftco;

MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| INFORMATION_SCHEMA |
| METRICS_SCHEMA     |
| PERFORMANCE_SCHEMA |
| mysql              |
| test               |
| tidb-ftco          |
+--------------------+
6 rows in set (0.00 sec)

MySQL [(none)]> use tidb-ftco

通过navicat来访问,注意端口不是mysql常用的的3306,而是4000
image.png

最后:Tidb与Mysql的兼容性

请参考与 MySQL 兼容性对比
https://docs.pingcap.com/zh/tidb/stable/mysql-compatibility

学习指导:https://docs.pingcap.com/zh/tidb/stable

最后修改时间:2020-11-30 17:07:18
「喜欢文章,快来给作者赞赏墨值吧」
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论