使用 TiUP cluster 在单机上安装TiDB

时间:2021-05-04 16:12:19   收藏:0   阅读:0

TiUP 是 TiDB 4.0 版本引入的集群运维工具,TiUP cluster 是 TiUP 提供的使用 Golang 编写的集群管理组件,通过 TiUP cluster 组件就可以进行日常的运维工作,包括部署、启动、关闭、销毁、弹性扩缩容、升级 TiDB 集群,以及管理 TiDB 集群参数。

最小规模的 TiDB 集群拓扑:

实例 个数 IP 配置
TiKV 3 10.186.65.41 避免端口和目录冲突
TiDB 1 10.186.65.41 默认端口,全局目录配置
PD 1 10.186.65.41 默认端口,全局目录配置
TiFlash 1 10.186.65.41 默认端口,全局目录配置
Monitor 1 10.186.65.41 默认端口,全局目录配置

1、添加数据盘 EXT4 文件系统

生产环境部署,建议使用 EXT4 类型文件系统的 NVME 类型的 SSD 磁盘存储 TiKV 数据文件。这个配置方案为最佳实施方案,其可靠性、安全性、稳定性已经在大量线上场景中得到证实。

使用 root 用户登录目标机器,将部署目标机器数据盘格式化成 ext4 文件系统,挂载时添加 nodelalloc 和 noatime 挂载参数。nodelalloc 是必选参数,否则 TiUP 安装时检测无法通过;noatime 是可选建议参数。

注意:

如果你的数据盘已经格式化成 ext4 并挂载了磁盘,可先执行 umount /dev/vdb 命令卸载,从编辑 /etc/fstab 文件步骤开始执行,添加挂载参数重新挂载即可。

1.1 查看数据盘

fdisk -l

Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 sectors

1.2 创建分区

parted -s -a optimal /dev/vdb mklabel gpt -- mkpart primary ext4 1 -1

1.3 格式化文件系统

mkfs.ext4 /dev/vdb

1.4 使用 lsblk 命令查看分区的设备号及UUID:

[root@tidb01 ~]# lsblk -f
NAME   FSTYPE  LABEL   UUID                                 MOUNTPOINT
sr0    iso9660 CONTEXT 2021-04-30-09-59-46-00               
vda                                                         
└─vda1 xfs             de86ba8a-914b-4104-9fd8-f9de800452ea /
vdb    ext4            957bb4c8-68f7-40df-ab37-1de7a4b5ee5e 

1.5 编辑 /etc/fstab 文件,添加 nodelalloc 挂载参数

vi /etc/fstab

UUID=957bb4c8-68f7-40df-ab37-1de7a4b5ee5e /data ext4 defaults,nodelalloc,noatime 0 2

1.6 创建数据目录并挂载磁盘

mkdir -p /data && mount -a

1.7 检查文件系统是否挂载成功

执行以下命令,如果文件系统为 ext4,并且挂载参数中包含 nodelalloc,则表示已生效。

[root@tidb01 ~]# mount -t ext4
/dev/vdb on /data type ext4 (rw,noatime,nodelalloc,data=ordered)

2、安装步骤

2.1 下载并安装 TiUP:

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

2.2 安装 TiUP 的 cluster 组件:

tiup cluster

需要打开一个新的终端或重新加载source /root/.bash_profile文件才能执行tiup命令

2.3 如果机器已经安装 TiUP cluster,需要更新软件版本:

tiup update --self && tiup update cluster

2.4 调大 sshd 服务的连接数

由于模拟多机部署,需要通过 root 用户调大 sshd 服务的连接数限制:

  1. 修改 /etc/ssh/sshd_config 将 MaxSessions 调至 20。
  2. 重启 sshd 服务:
systemctl restart sshd.service

2.5 创建并启动集群

按下面的配置模板,编辑配置文件,命名为 topo.yaml,其中:

[root@tidb01 .tiup]# pwd
/root/.tiup

[root@tidb01 .tiup]# cat 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: "/data/tidb-deploy"
 data_dir: "/data/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: 10.186.65.41

tidb_servers:
 - host: 10.186.65.41

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

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

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

tiflash_servers:
 - host: 10.186.65.41

monitoring_servers:
 - host: 10.186.65.41

grafana_servers:
 - host: 10.186.65.41

2.6 执行集群安装命令:

tiup cluster deploy <cluster-name> <tidb-version> ./topo.yaml --user root -p
示例
tiup cluster deploy barlow 4.0.12 ./topo.yaml --user root -p

按照引导,输入”y”及 root 密码,来完成部署:

Do you want to continue? [y/N]:  y
Input SSH password:

成功安装会提示如下启动字样:

Cluster `barlow` deployed successfully, you can start it with command: `tiup cluster start barlow`

2.7 启动集群:

tiup cluster start barlow

tiup cluster start <cluster-name>

2.8 访问集群:

yum install -y mysql
mysql -uroot -p -h10.186.65.41 -P4000

通过 http://{grafana-ip}:3000 访问集群 Grafana 监控页面,默认用户名和密码均为 admin。
http://10.186.65.41:3000/

通过 http://{pd-ip}:2379/dashboard 访问集群 TiDB Dashboard 监控页面,默认用户名为 root,密码为空。
http://10.186.65.41:2379/dashboard

tiup cluster list
[root@tidb01 .tiup]# tiup cluster list
Starting component `cluster`: /root/.tiup/components/cluster/v1.4.2/tiup-cluster list
Name    User  Version  Path                                         PrivateKey
----    ----  -------  ----                                         ----------
barlow  tidb  v4.0.12  /root/.tiup/storage/cluster/clusters/barlow  /root/.tiup/storage/cluster/clusters/barlow/ssh/id_rsa
tiup cluster display <cluster-name>
[root@tidb01 .tiup]# tiup cluster display barlow
Starting component `cluster`: /root/.tiup/components/cluster/v1.4.2/tiup-cluster display barlow
Cluster type:       tidb
Cluster name:       barlow
Cluster version:    v4.0.12
SSH type:           builtin
Dashboard URL:      http://10.186.65.41:2379/dashboard
ID                  Role        Host          Ports                            OS/Arch       Status   Data Dir                         Deploy Dir
--                  ----        ----          -----                            -------       ------   --------                         ----------
10.186.65.41:3000   grafana     10.186.65.41  3000                             linux/x86_64  Up       -                                /data/tidb-deploy/grafana-3000
10.186.65.41:2379   pd          10.186.65.41  2379/2380                        linux/x86_64  Up|L|UI  /data/tidb-data/pd-2379          /data/tidb-deploy/pd-2379
10.186.65.41:9090   prometheus  10.186.65.41  9090                             linux/x86_64  Up       /data/tidb-data/prometheus-9090  /data/tidb-deploy/prometheus-9090
10.186.65.41:4000   tidb        10.186.65.41  4000/10080                       linux/x86_64  Up       -                                /data/tidb-deploy/tidb-4000
10.186.65.41:9000   tiflash     10.186.65.41  9000/8123/3930/20170/20292/8234  linux/x86_64  Up       /data/tidb-data/tiflash-9000     /data/tidb-deploy/tiflash-9000
10.186.65.41:20160  tikv        10.186.65.41  20160/20180                      linux/x86_64  Up       /data/tidb-data/tikv-20160       /data/tidb-deploy/tikv-20160
10.186.65.41:20161  tikv        10.186.65.41  20161/20181                      linux/x86_64  Up       /data/tidb-data/tikv-20161       /data/tidb-deploy/tikv-20161
10.186.65.41:20162  tikv        10.186.65.41  20162/20182                      linux/x86_64  Up       /data/tidb-data/tikv-20162       /data/tidb-deploy/tikv-20162
Total nodes: 8

因为有悔,所以披星戴月;因为有梦,所以奋不顾身! 个人博客首发:easydb.net 微信公众号:easydb 关注我,不走丢!

技术图片

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!