作者: Acdante

**【前言】**由于近期有TiDB测试需求,刚好赶上8.1新版本发布前夕,在各群内咨询后,表妹提示马上发布8.1版本了,可以等等,于是本来计划5月23日先上5.7版本的,延后等到5月24日周五晚上,8.1新版本发布可下载了,第一时间就下载,进行测试环境集群部署。等待下载的过程中,刚好晚饭没吃,煎饺搞起来,那叫一个鲜美哦。

TiDB 8.1 测试集群规划:计划部署14节点包含主要组件的准生产集群。

TiDB 8.1.0 LTS 版本在性能、扩展性、稳定性、SQL和数据库管理等方面进行了显著的功能增强,具体TiDB 8.1- LTS版本的新特性和各种强大功能,详见https://tidb.net/blog/4efefe7b文章。接下来就展示一下整个搭建过程还是比较顺手。



0x00.TiDB 8.1部署前置条件


操作系统及平台要求

参照官方指导文档,TiDB 软件和硬件环境建议配置 | PingCAP 文档中心

在 v8.1 LTS 版本中,针对不同操作系统和 CPU 架构的组合,TiDB 提供不同级别质量标准的支持。

  • 在以下操作系统以及对应的 CPU 架构组合上,TiDB 可满足企业级生产质量的要求,产品特性经过全面且系统化的验证:ARM和通用x86均可部署。这里没看到阿里龙蜥操作系统的测试,后续有机会也想测试看看。

操作系统

支持的 CPU 架构

Red Hat Enterprise Linux 8.4 及以上的 8.x 版本

- x86_64

- ARM 64

- Red Hat Enterprise Linux 7.3 及以上的 7.x 版本

- CentOS 7.3 及以上的 7.x 版本

- x86_64

- ARM 64

Amazon Linux 2

- x86_64

- ARM 64

Rocky Linux 9.1 及以上的版本

- x86_64

- ARM 64

麒麟欧拉版 V10 SP1/SP2

- x86_64

- ARM 64

统信操作系统 (UOS) V20

- x86_64

- ARM 64

openEuler 22.03 LTS SP1/SP3

- x86_64

- ARM 64


0x01.TiDB 8.1集群节点规划

| | | | | | | | | | -- | ----------- | --- | -- | --- | ---- | ------------------ | ---- | | 序号 | 角色 | CPU | 内存 | 系统盘 | 数据盘 | 操作系统版本 | 部署类型 | | 1 | TiDB服务器 | 8 | 32 | 50 | 1T | OpenEuler22.03 SP3 | 虚拟机 | | 2 | TiDB服务器 | 8 | 32 | 50 | 1T | OpenEuler22.03 SP3 | 虚拟机 | | 3 | TiDB服务器 | 8 | 32 | 50 | 1T | OpenEuler22.03 SP3 | 虚拟机 | | 4 | TiKV服务器 | 8 | 16 | 50 | 300G | OpenEuler22.03 SP3 | 虚拟机 | | 5 | TiKV服务器 | 8 | 16 | 50 | 300G | OpenEuler22.03 SP3 | 虚拟机 | | 6 | TiKV服务器 | 8 | 16 | 50 | 300G | OpenEuler22.03 SP3 | 虚拟机 | | 7 | PD服务器 | 8 | 16 | 50 | 300G | OpenEuler22.03 SP3 | 虚拟机 | | 8 | PD服务器 | 8 | 16 | 50 | 300G | OpenEuler22.03 SP3 | 虚拟机 | | 9 | PD服务器 | 8 | 16 | 50 | 300G | OpenEuler22.03 SP3 | 虚拟机 | | 10 | TiFlash服务器 | 16 | 32 | 50 | 300G | OpenEuler22.03 SP3 | 虚拟机 | | 11 | TiFlash服务器 | 16 | 32 | 50 | 300G | OpenEuler22.03 SP3 | 虚拟机 | | 12 | TiDB集群监控服务器 | 8 | 16 | 50 | 300G | OpenEuler22.03 SP3 | 虚拟机 | | 13 | TICDC | 8 | 32 | 50 | 300G | OpenEuler22.03 SP3 | 虚拟机 | | 14 | TICDC | 8 | 32 | 50 | 300G | OpenEuler22.03 SP3 | 虚拟机 |



0x02.openeuler-22.03-SP3系统环境准备

部署服务器节点规划

测试环境,准备十四台虚拟机,均统一采用openeuler 22.03 SP3最新版本,最小化安装,关闭selinux/firewalld防火墙,配置NTP,关闭透明大页,关闭主要节点SWAP,同网段,磁盘分区统一GPT-EXT4,按要求挂载。操作系统部署过程略过,简单放两张图。

【注意】如果主机内存偏小,关闭系统 swap 可能会更容易触发 OOM 问题,可参考以如下方法将 swap 优先级调低,但不做永久关闭:

echo "vm.swappiness = 0">> /etc/sysctl.conf
sysctl -p

OS安装图1:

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_操作系统

OS安装完成图2:

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_管理面板_02

/data1数据盘挂载图3:

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_操作系统_03

其他系统要求按照规范操作即可

注意:最小化安装操作系统,确保tar命令、numactl命令正常安装



0x03.TiDB V8.1.0社区版下载

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_https_04

https://cn.pingcap.com/product-community/

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_tidb_05

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_操作系统_06

节点部署规划

序号

实例

个数

虚拟机机配置

IP

配置

1

TiDB

3

16 VCore 32GB * 1

192.168.XX.XX3192.168.XX.XX4192.168.XX.XX5

默认端口全局目录配置

2

PD

3

4 VCore 8GB * 1

192.168.XX.XX6192.168.XX.XX7192.168.XX.XX8

默认端口全局目录配置

3

TiKV

3

16 VCore 32GB 2TB (nvme ssd) * 1

192.168.XX.XX0192.168.XX.XX1192.168.XX.XX2

默认端口全局目录配置

4

TiFlash

2

16VCore 32G

192.168.XX.XX9192.168.XX.XX0

 

5

CDC

2

8 VCore 16GB * 1

192.168.XX.XX3192.168.XX.XX5

默认端口全局目录配置

6

Monitoring & Grafana

1

4 VCore 8GB * 1 500GB (ssd)

192.168.XX.XX2

默认端口全局目录配置


0x04.TiDB V8.1.0 集群Tiup离线部署

tar xzvf tidb-community-server-v8.1.0-linux-amd64.tar.gz && sh tidb-community-server-v8.1.0-linux-amd64/local_install.sh       

 && \

> sh tidb-community-server-v8.1.0-linux-amd64/local_install.sh && \

> source /home/tidb/.bash_profile

注意:解压目录如果在/tmp目录,需要修改系统默认删除tmp文件规则,或者直接放在非/tmp目录下解压,会影响到后续tiup等管理命令使用

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_操作系统_07

初始化结果:

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_https_08


0x05.配置TiDB Cluster集群拓扑文件

配置参考官方手册,修改了文件路径

注意:如需大小写敏感,需提前定义new_collation_enabled改为enable,如有后续调整需求,无法后续调整,只能重建迁移

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_https_09

# # 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: "/data1/tidb-deploy"
  data_dir: "/data1/tidb-data"

# # Monitored variables are applied to all the machines.
monitored:
  node_exporter_port: 9100
  blackbox_exporter_port: 9115
  # deploy_dir: "/data1/tidb-deploy/monitored-9100"
  # data_dir: "/data1/tidb-data/monitored-9100"
  # log_dir: "/data1/tidb-deploy/monitored-9100/log"

# # Server configs are used to specify the runtime configuration of TiDB components.
# # All configuration items can be found in TiDB docs:
# # - TiDB: https://docs.pingcap.com/zh/tidb/stable/tidb-configuration-file
# # - TiKV: https://docs.pingcap.com/zh/tidb/stable/tikv-configuration-file
# # - PD: https://docs.pingcap.com/zh/tidb/stable/pd-configuration-file
# # All configuration items use points to represent the hierarchy, e.g:
# #   readpool.storage.use-unified-pool
# #
# # You can overwrite this configuration via the instance-level `config` field.

server_configs:
  tidb:
    log.slow-threshold: 300
  tikv:
    # server.grpc-concurrency: 4
    # raftstore.apply-pool-size: 2
    # raftstore.store-pool-size: 2
    # rocksdb.max-sub-compactions: 1
    # storage.block-cache.capacity: "16GB"
    # readpool.unified.max-thread-count: 12
    readpool.storage.use-unified-pool: false
    readpool.coprocessor.use-unified-pool: true
  pd:
    schedule.leader-schedule-limit: 4
    schedule.region-schedule-limit: 2048
    schedule.replica-schedule-limit: 64
  cdc:
    # capture-session-ttl: 10
    # sorter.sort-dir: "/tmp/cdc_sort"
    # gc-ttl: 86400

pd_servers:
  - host: 192.XX.XX.X46
    # ssh_port: 22
    # name: "pd-1"
    # client_port: 2379
    # peer_port: 2380
    # deploy_dir: "/data1/tidb-deploy/pd-2379"
    # data_dir: "/data1/tidb-data/pd-2379"
    # log_dir: "/data1/tidb-deploy/pd-2379/log"
    # numa_node: "0,1"
    # # The following configs are used to overwrite the `server_configs.pd` values.
    # config:
    #   schedule.max-merge-region-size: 20
    #   schedule.max-merge-region-keys: 200000
  - host: 192.XX.XX.X47
  - host: 192.XX.XX.X48

tidb_servers:
  - host: 192.XX.XX.X43
    # ssh_port: 22
    # port: 4000
    # status_port: 10080
    # deploy_dir: "/data1/tidb-deploy/tidb-4000"
    # log_dir: "/data1/tidb-deploy/tidb-4000/log"
    # numa_node: "0,1"
    # # The following configs are used to overwrite the `server_configs.tidb` values.
    # config:
    #   log.slow-query-file: tidb-slow-overwrited.log
  - host: 192.XX.XX.X44
  - host: 192.XX.XX.X45

tikv_servers:
  - host: 192.XX.XX.X40
    # ssh_port: 22
    # port: 20160
    # status_port: 20180
    # deploy_dir: "/data1/tidb-deploy/tikv-20160"
    # data_dir: "/data1/tidb-data/tikv-20160"
    # log_dir: "/data1/tidb-deploy/tikv-20160/log"
    # numa_node: "0,1"
    # # The following configs are used to overwrite the `server_configs.tikv` values.
    # config:
    #   server.grpc-concurrency: 4
    #   server.labels: { zone: "zone1", dc: "dc1", host: "host1" }
  - host: 192.XX.XX.X41
  - host: 192.XX.XX.X42

tiflash_servers:
  - host: 192.XX.XX.X49
    data_dir: /data1/tidb-data/tiflash-9000
    deploy_dir: /data1/tidb-deploy/tiflash-9000
  - host: 192.XX.XX.X50
    data_dir: /data1/tidb-data/tiflash-9000
    deploy_dir: /data1/tidb-deploy/tiflash-9000

cdc_servers:
  - host: 192.XX.XX.X53
    port: 8300
    deploy_dir: "/data1/tidb-deploy/cdc-8300"
    data_dir: "/data1/tidb-data/cdc-8300"
    log_dir: "/data1/tidb-deploy/cdc-8300/log"
    # gc-ttl: 86400
    # ticdc_cluster_id: "cluster1"
  - host: 192.XX.XX.X54
    port: 8300
    deploy_dir: "/data1/tidb-deploy/cdc-8300"
    data_dir: "/data1/tidb-data/cdc-8300"
    log_dir: "/data1/tidb-deploy/cdc-8300/log"
    # gc-ttl: 86400
    # ticdc_cluster_id: "cluster2"

monitoring_servers:
  - host: 192.XX.XX.X52
    # ssh_port: 22
    # port: 9090
    # deploy_dir: "/data1/tidb-deploy/prometheus-8249"
    # data_dir: "/data1/tidb-data/prometheus-8249"
    # log_dir: "/data1/tidb-deploy/prometheus-8249/log"

grafana_servers:
  - host: 192.XX.XX.X52
    # port: 3000
    # deploy_dir: /data1/tidb-deploy/grafana-3000

alertmanager_servers:
  - host: 192.XX.XX.X52
    # ssh_port: 22
    # web_port: 9093
    # cluster_port: 9094
    # deploy_dir: "/data1/tidb-deploy/alertmanager-9093"
    # data_dir: "/data1/tidb-data/alertmanager-9093"
    # log_dir: "/data1/tidb-deploy/alertmanager-9093/log"


0x06.TiDB集群部署前预检查

执行集群部署前,先执行配置文件和前置条件检查

tiup cluster check ./topology.yaml --user root -p
可执行自动修复相关风险:
tiup cluster check ./topology.yaml --apply --user root [-p] [-i /home/root/.ssh/gcp_rsa]
修复日志:

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_tidb_10

检查通过日志:

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_tidb_11

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_操作系统_12


0x07.离线部署TiDB集群

部署命令

tiup cluster deploy tidb-cluster v8.1.0 ./topology.yaml --user root -p

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_https_13

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_tidb_14

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_操作系统_15

出现Cluster `tidb-cluster` deployed successfully, you can start it with command: `tiup cluster start tidb-cluster --init`

即表明TiDB 离线集群已经完成部署,下一步可进行集群启动

集群状态检查:

tiup cluster display tidb-cluster
可看到集群的各个角色组件status目前仍然为Down状态,需要进行集群安全启动

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_https_16


0x08.TiDB V8.1.0 集群启动

安全模式启动集群

[tidb@ticluster ~]$ tiup cluster start tidb-cluster --init

启动后,会有一个初始密码,需要记录。

。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。
Start 192.168.XX.XX3 success
        Start 192.168.XX.XX6 success
        Start 192.168.XX.XX2 success
        Start 192.168.XX.XX7 success
        Start 192.168.XX.XX1 success
        Start 192.168.XX.XX9 success
        Start 192.168.XX.XX4 success
        Start 192.168.XX.XX0 success
+ [ Serial ] - UpdateTopology: cluster=tidb-cluster
Started cluster `tidb-cluster` successfully
The root password of TiDB database has been changed.
The new password is: 'PASSWORD—******PASSWORD'.
Copy and record it to somewhere safe, it is only displayed once, and will not be stored.
The generated password can NOT be get and shown again.

验证集群状态

tiup cluster display tidb-cluster

可以看到PD、DB、KV等相关组件STATUS均已经变为UP状态,说明集群启动成功,可以进行连接,且可以看到TiDB集群的Dashboard URL和Grafana URL,可以通过两个管理平台,web可视化检查集群组件和相关性能监控信息。

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_操作系统_17


0x09.TiDB集群管理和监控面板

自带监控和web管理面板,这点我认为TiDB是做的不错的,免去了后续单独安装各类监控的步骤,对客户对DBA都是非常友好。


集群监控面板

监控面板:Grafana TRL:默认端口:http://Monitoring_Server_IP:3000

界面展示:

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_操作系统_18

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_管理面板_19


集群管理面板

集群管理面板:默认URL:默认端口:http://TiDB_PD_Role_IP:2379/dashboard

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_管理面板_20

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_操作系统_21

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_虚拟机_22


0x10.问题一、无tar命令

Error: stderr: bash: line 1: tar: command not found
: executor.ssh.execute_failed: Failed to execute command over SSH for 'root@192.168.XX.XX0:22' {ssh_stderr: bash: line 1: tar: command not found
, ssh_stdout: , ssh_command: export LANG=C; PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin; tar --no-same-owner -zxf /tmp/tiup/bin/insight-v0.4.2-linux-amd64.tar.gz -C /tmp/tiup/bin && rm /tmp/tiup/bin/insight-v0.4.2-linux-amd64.tar.gz}, cause: Process exited with status 127

Verbose debug logs has been written to /home/tidb/.tiup/logs/tiup-cluster-debug-2024-05-24-22-07-52.log.

以上报错原因为openEuler系统为最小化安装配置,无tar命令,无法正常执行tar命令,预检查失败,报错节点安装tar命令后正常通过检查


0x11.问题二、numactl命令不可用

TiDB 8.1 :国产 OS-openEuler22.03 SP3 集群离线部署体验_虚拟机_23

Fail为必须解决通过项,节点安装numactl即可