TiDB v7.5.4安装部署手册
1 安装部署计划
服务器名称 | ip | 角色 |
---|---|---|
hdp-01 | 172.16.4.121 | pd_servers、tidb_servers、tikv_servers |
hdp-02 | 172.16.4.122 | pd_servers、tidb_servers、tikv_servers |
hdp-03 | 172.16.4.123 | pd_servers、tidb_servers、tikv_servers |
hdp-04 | 172.16.4.124 | monitoring_servers、grafana_servers、alertmanager_servers |
2 相关参考信息
-
安装部署包下载地址
-
安装部署官方手册
3 安装部署TiDB
3.1 下载安装部署包
将tidb-community-server-v7.5.4-linux-arm64.tar.gz上传至hdp-01服务器上
mkdir /data/tidb
cd /data/tidb
wget https://download.pingcap.org/tidb-community-server-v7.5.4-linux-arm64.tar.gz
tar -xvf tidb-community-server-v7.5.4-linux-arm64.tar.gz
3.2 tidb用户
3.2.1 增加tidb用户及配置相关密码
#hdp-01、hdp-02、hdp-03、hdp-04
useraddr tidb
passwd tidb
3.2.2 tidb用户免密
#hdp-01
[tidb@hdp-01 ~]$ su - tidb
[tidb@hdp-01 ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/tidb/.ssh/id_rsa):
Created directory '/home/tidb/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/tidb/.ssh/id_rsa.
Your public key has been saved in /home/tidb/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:jpI7fXb+P79Gae0EFQnrNCtr6i+LLbFmJX4MVJO4ybg tidb@hdp-warehouse-001
The key's randomart image is:
+---[RSA 2048]----+
| . . ...o|
| . + ...|
| o + . + . |
| . = o + |
| o S . o .o|
| E * . o +o|
| o.o O o oo |
| .o.*=++ ...|
| ..o++B=o..o+o|
+----[SHA256]-----+
[tidb@hdp-01 ~]$ ssh-copy-id hdp-01
[tidb@hdp-01 ~]$ ssh-copy-id hdp-02
[tidb@hdp-01 ~]$ ssh-copy-id hdp-03
[tidb@hdp-01 ~]$ ssh-copy-id hdp-04
3.3.3 配置sudo权限
#hdp-01、hdp-02、hdp-03、hdp-04
# 在/etc/sudoers添加下列条目
tidb ALL=(ALL) NOPASSWD:ALL
3.3 部署TiUP环境
# hdp-01
[root@hdp-warehouse-001 tidb-community-server-v7.5.4-linux-arm64]# sh local_install.sh
Disable telemetry success
Successfully set mirror to /data/tidb/tidb-community-server-v7.5.4-linux-arm64
Detected shell: bash
Shell profile: /root/.bash_profile
/root/.bash_profile has been modified to to add tiup to PATH
open a new terminal or source /root/.bash_profile to use it
Installed path: /root/.tiup/bin/tiup
===============================================
1. source /root/.bash_profile
2. Have a try: tiup playground
# 刷新环境变量
[root@hdp-warehouse-001 tidb-community-server-v7.5.4-linux-arm64]# source /root/.bash_profile
# 确认环境变量生效
[root@hdp-warehouse-001 tidb-community-server-v7.5.4-linux-arm64]# which tiup
/root/.tiup/bin/tiup
3.4 修改配置文件
3.4.1 生成配置文件
# hdp-01
[root@hdp-warehouse-001 tidb-community-server-v7.5.4-linux-arm64]# tiup cluster template > topology.yaml
A new version of cluster is available: -> v1.16.0
To update this component: tiup update cluster
To update all components: tiup update --all
The component `cluster` version is not installed; downloading from repository.
3.4.2 修改配置文件topology.yaml
global:
user: "tidb"
ssh_port: 22
deploy_dir: "/data/tidb/tidb-deploy"
data_dir: "/data/tidb/tidb-data"
listen_host: 0.0.0.0
arch: "arm64"
server_configs:
tidb:
log.slow-threshold: 300
performance.txn-total-size-limit: 536870912
tikv:
readpool.storage.use-unified-pool: false
readpool.coprocessor.use-unified-pool: true
pd:
replication.enable-placement-rules: true
replication.location-labels: ["host"]
monitored:
node_exporter_port: 9100
blackbox_exporter_port: 9115
pd_servers:
- host: 172.16.4.121
- host: 172.16.4.122
- host: 172.16.4.123
tidb_servers:
- host: 172.16.4.121
- host: 172.16.4.122
- host: 172.16.4.123
tikv_servers:
- host: 172.16.4.121
- host: 172.16.4.122
- host: 172.16.4.123
monitoring_servers:
- host: 172.16.4.124
grafana_servers:
- host: 172.16.4.124
alertmanager_servers:
- host: 172.16.4.124
说明:以上配置文件为最简单配置文件,如果需要其他配置请参考https://docs.pingcap.com/zh/tidb/v7.5/tiup-cluster-topology-reference中内容进行相关配置
3.4.3 检查配置文件
[root@hdp-warehouse-001 tidb-community-server-v7.5.4-linux-arm64]# tiup cluster check ./topology.yaml
...........
Node Check Result Message
---- ----- ------ -------
172.16.4.124 timezone Pass time zone is the same as the first PD machine: Asia/Shanghai
172.16.4.124 network Pass network speed of enp1s0f1 is 10000MB
172.16.4.124 network Pass network speed of enp125s0f0 is 1000MB
172.16.4.124 network Pass network speed of enp125s0f1 is 1000MB
172.16.4.124 network Pass network speed of enp125s0f2 is 1000MB
172.16.4.124 network Pass network speed of enp125s0f3 is 1000MB
172.16.4.124 network Pass network speed of enp1s0f0 is 10000MB
172.16.4.124 selinux Fail SELinux is not disabled
172.16.4.124 thp Fail THP is enabled, please disable it for best performance
172.16.4.124 cpu-cores Pass number of CPU cores / threads: 64
172.16.4.124 cpu-governor Pass CPU frequency governor is performance
172.16.4.124 swap Warn swap is enabled, please disable it for best performance
172.16.4.124 limits Fail soft limit of 'nofile' for user 'tidb' is not set or too low
172.16.4.124 limits Fail hard limit of 'nofile' for user 'tidb' is not set or too low
172.16.4.124 limits Fail soft limit of 'stack' for user 'tidb' is not set or too low
172.16.4.124 sysctl Fail net.ipv4.tcp_syncookies = 1, should be 0
172.16.4.124 sysctl Fail vm.swappiness = 10, should be 0
172.16.4.124 sysctl Fail net.core.somaxconn = 128, should be greater than 32768
172.16.4.124 memory Pass memory size is 524288MB
172.16.4.124 disk Warn mount point /data does not have 'noatime' option set
172.16.4.124 os-version Pass OS is Kylin Linux Advanced Server V10 (Tercel)
172.16.4.124 disk Fail mount point /data does not have 'nodelalloc' option set
172.16.4.124 command Fail numactl not usable, bash: numactl: command not found
172.16.4.123 cpu-governor Pass CPU frequency governor is performance
172.16.4.123 swap Warn swap is enabled, please disable it for best performance
172.16.4.123 sysctl Fail vm.swappiness = 10, should be 0
172.16.4.123 sysctl Fail net.core.somaxconn = 128, should be greater than 32768
172.16.4.123 sysctl Fail net.ipv4.tcp_syncookies = 1, should be 0
172.16.4.123 selinux Fail SELinux is not disabled
172.16.4.123 network Pass network speed of enp1s0f1 is 10000MB
172.16.4.123 network Pass network speed of enp125s0f0 is 1000MB
172.16.4.123 network Pass network speed of enp125s0f1 is 1000MB
172.16.4.123 network Pass network speed of enp125s0f2 is 1000MB
172.16.4.123 network Pass network speed of enp125s0f3 is 1000MB
172.16.4.123 network Pass network speed of enp1s0f0 is 10000MB
172.16.4.123 disk Warn mount point /data does not have 'noatime' option set
172.16.4.123 command Fail numactl not usable, bash: numactl: command not found
172.16.4.123 os-version Pass OS is Kylin Linux Advanced Server V10 (Tercel)
172.16.4.123 cpu-cores Pass number of CPU cores / threads: 64
172.16.4.123 memory Pass memory size is 524288MB
172.16.4.123 disk Fail mount point /data does not have 'nodelalloc' option set
172.16.4.123 timezone Pass time zone is the same as the first PD machine: Asia/Shanghai
172.16.4.123 limits Fail soft limit of 'nofile' for user 'tidb' is not set or too low
172.16.4.123 limits Fail hard limit of 'nofile' for user 'tidb' is not set or too low
172.16.4.123 limits Fail soft limit of 'stack' for user 'tidb' is not set or too low
172.16.4.123 thp Fail THP is enabled, please disable it for best performance
172.16.4.123 listening-port Fail port 9090 is already in use
..................
3.4.3 自动修复错误
tiup cluster check topology.yaml --apply --user root -p
3.4.4 手动修复错误
numactl not usable, bash: numactl: command not found
修复方式:
yum install numactl -y
THP is enabled, please disable it for best performance
修复方式:
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
3.5 安装部署TiDB
3.5.1 安装TiDB
tiup cluster deploy <cluster-name> <version> <topology.yaml>
<cluster-name> 表示新集群的名字,不能和现有集群同名
<version> 为要部署的 TiDB 集群版本号,如 v4.0.9
<topology.yaml> 为事先编写好的拓扑文件
tiup cluster deploy sthj_dgp v7.5.4 ./topology.yaml
........................
Enable 172.16.4.124 success
Enable 172.16.4.123 success
Enable 172.16.4.122 success
Enable 172.16.4.121 success
Cluster `sthj_dgp` deployed successfully, you can start it with command: `tiup cluster start sthj_dgp --init`
3.5.2 初始化集群
tiup cluster start sthj_dgp --init
..........................
Starting component blackbox_exporter
Starting instance 172.16.4.122
Starting instance 172.16.4.121
Starting instance 172.16.4.123
Starting instance 172.16.4.123
Starting instance 172.16.4.123
Start 172.16.4.123 success
Start 172.16.4.123 success
Start 172.16.4.122 success
Start 172.16.4.123 success
Start 172.16.4.121 success
+ [ Serial ] - UpdateTopology: cluster=sthj_dgp
Started cluster `sthj_dgp` successfully
The root password of TiDB database has been changed.
The new password is: '@HC6bN*F90-r8m57+d'.
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.
3.6 配置TiDB
3.6.1 查看集群状态
[root@hdp-01 ~]# tiup cluster display sthj_dgp
Cluster type: tidb
Cluster name: sthj_dgp
Cluster version: v7.5.4
Deploy user: tidb
SSH type: builtin
Dashboard URL: http://172.16.4.121:2379/dashboard
Grafana URL: http://172.16.4.124:3000
ID Role Host Ports OS/Arch Status Data Dir Deploy Dir
-- ---- ---- ----- ------- ------ -------- ----------
172.16.4.124:9093 alertmanager 172.16.4.124 9093/9094 linux/aarch64 Up /data/tidb/tidb-data/alertmanager-9093 /data/tidb/tidb-deploy/alertmanager-9093
172.16.4.124:3000 grafana 172.16.4.124 3000 linux/aarch64 Up - /data/tidb/tidb-deploy/grafana-3000
172.16.4.121:2379 pd 172.16.4.121 2379/2380 linux/aarch64 Up|UI /data/tidb/tidb-data/pd-2379 /data/tidb/tidb-deploy/pd-2379
172.16.4.122:2379 pd 172.16.4.122 2379/2380 linux/aarch64 Up|L /data/tidb/tidb-data/pd-2379 /data/tidb/tidb-deploy/pd-2379
172.16.4.123:2379 pd 172.16.4.123 2379/2380 linux/aarch64 Up /data/tidb/tidb-data/pd-2379 /data/tidb/tidb-deploy/pd-2379
172.16.4.124:9090 prometheus 172.16.4.124 9090/12020 linux/aarch64 Up /data/tidb/tidb-data/prometheus-9090 /data/tidb/tidb-deploy/prometheus-9090
172.16.4.121:4000 tidb 172.16.4.121 4000/10080 linux/aarch64 Up - /data/tidb/tidb-deploy/tidb-4000
172.16.4.122:4000 tidb 172.16.4.122 4000/10080 linux/aarch64 Up - /data/tidb/tidb-deploy/tidb-4000
172.16.4.123:4000 tidb 172.16.4.123 4000/10080 linux/aarch64 Up - /data/tidb/tidb-deploy/tidb-4000
172.16.4.121:20160 tikv 172.16.4.121 20160/20180 linux/aarch64 Up /data/tidb/tidb-data/tikv-20160 /data/tidb/tidb-deploy/tikv-20160
172.16.4.122:20160 tikv 172.16.4.122 20160/20180 linux/aarch64 Up /data/tidb/tidb-data/tikv-20160 /data/tidb/tidb-deploy/tikv-20160
172.16.4.123:20160 tikv 172.16.4.123 20160/20180 linux/aarch64 Up /data/tidb/tidb-data/tikv-20160 /data/tidb/tidb-deploy/tikv-20160
Total nodes: 12
3.6.2 修改root用户密码
@HC6bN*F90-r8m57+d
[root@hdp-warehouse-005 ~]# mysql -h 172.16.4.121 -P4000 -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4057989126
Server version: 8.0.11-TiDB-v7.5.4 TiDB Server (Apache License 2.0) Community Edition, MySQL 8.0 compatible
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
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 |
| METRICS_SCHEMA |
| PERFORMANCE_SCHEMA |
| mysql |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> select user,host,authentication_string from mysql.user;
+------+------+-------------------------------------------+
| user | host | authentication_string |
+------+------+-------------------------------------------+
| root | % | *DBB11E52A20A1D2F9C0DCF9CF210BC37D059B17D |
+------+------+-------------------------------------------+
1 row in set (0.00 sec)
mysql> set password for 'root'@'%' = 'NEWPASSWORD';
Query OK, 0 rows affected (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
3.6.3创建dgp_user用户
mysql> create user dgp_user IDENTIFIED by 'NEWPASSWORD';
4 TiDB相关内容
4.1 常用命令
-
查看集群列表
tiup cluster list
-
查看集群状态
tiup cluster display <集群名称>
4.2 数据库WEB界面
4.2.1 监控web界面
http://172.16.4.121:2379/dashboard/
4.2.2 Pro界面
http://172.16.4.124:9090/graph
4.2.3 Grafana界面
http://172.16.4.124:3000/login
默认用户密码:admin/admin