CentOS7 最小化单机安装部署 TiDB V8.0

CentOS7 最小化单机安装部署 TiDB V8.0
 
1.备份
  重要数据务必备份!!!
 
2.停止、卸载、删除日志、删除服务、环境变量、用户等
  # 使用 TiUP 停止集群(如果你是用 TiUP 部署的)
  tiup cluster stop tidb-test
  # 或者直接停止各个组件
  killall -9 tidb-server
  killall -9 tikv-server
  killall -9 pd-server
  killall -9 tiflash
  killall -9 pump
  killall -9 drainer
  # 删除集群
  tiup cluster destroy tidb-test
  # 删除数据目录(默认通常在 /tmp 或你指定的目录)
  rm -rf /tmp/tidb
  rm -rf /tmp/pd
  rm -rf /tmp/tikv
  rm -rf /tmp/tiflash
  # 删除日志文件
  rm -rf /var/log/tidb
  rm -rf /var/log/pd
  rm -rf /var/log/tikv
  rm -rf /var/log/tiflash
  # 卸载TIUP
  rm -rf ~/.tiup
  # 删除系统服务
  systemctl disable tidb
  systemctl disable tikv
  systemctl disable pd
  systemctl disable tiflash
  rm -f /etc/systemd/system/tidb.service
  rm -f /etc/systemd/system/tikv.service
  rm -f /etc/systemd/system/pd.service
  rm -f /etc/systemd/system/tiflash.service
  systemctl daemon-reload
  # 删除用户和组
  userdel tidb
  groupdel tidb
  # 检查是否有残留的 TiDB 相关进程:
  ps aux | grep -E 'tidb|tikv|pd|tiflash'
View Code

3.关闭防火墙、创建用户

    # 关闭防火墙
    systemctl stop firewalld.service
    #检验防火墙是否启动
    #firewall-cmd --state

    #创建tidb用户
    sudo useradd tidb -m
    # -m 选项表示同时创建用户的家目录 /home/tidb

    #设置密码
    sudo passwd tidb
    系统会提示你输入并确认新的密码。请设置一个强密码。

    #给予权限
    sudo chown -R tidb:tidb /home/tidb
View Code

4.安装TIUP组件采用在线部署

  切换到用户tidb下运行

    #执行如下命令安装 TiUP 工具:
    curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh

    #重新声明全局环境变量:
    source .bash_profile

    #确认 TiUP 工具是否安装:
    which tiup
    
    #安装 TiUP cluster 组件:
    tiup cluster

    #如果已经安装,则更新 TiUP cluster 组件至最新版本:
    tiup update --self && tiup update cluster
    #预期输出 “Update successfully!” 字样。

    #验证当前 TiUP cluster 版本信息。执行如下命令查看 TiUP cluster 组件版本:
    tiup --binary cluster
View Code

5.初始化集群配置文件

执行如下命令,生成集群初始化配置文件:

tiup cluster template > topology.yaml

说明:

针对两种常用的部署场景,也可以通过以下命令生成建议的拓扑模板:

混合部署场景:单台机器部署多个实例。

tiup cluster template --full > topology.yaml
跨机房部署场景:跨机房部署 TiDB 集群。

tiup cluster template --multi-dc > topology.yaml

详情参考官方文档:

https://docs-archive.pingcap.com/zh/tidb/v8.0/production-deployment-using-tiup/#%E7%AC%AC-3-%E6%AD%A5%E5%88%9D%E5%A7%8B%E5%8C%96%E9%9B%86%E7%BE%A4%E6%8B%93%E6%89%91%E6%96%87%E4%BB%B6

6.部署TIDB

     # 安装必要组件
    sudo yum install -y numact
    
    # 检查集群潜在风险(仅检查)
    tiup cluster check /home/tidb/topology.yaml --user root -p

    # 自动修复集群存在的潜在风险:
    tiup cluster check /home/tidb/topology.yaml --apply --user root -p

    # 执行部署集群命令
    tiup cluster deploy tidb-test v8.0.0 /home/tidb/topology.yaml --user root -p
View Code

7.验证部署、启动并初始化、验证集群运行状态

1.执行如下命令检查 tidb-test 集群情况:

tiup cluster display tidb-test

预期输出包括 tidb-test 集群中实例 ID、角色、主机、监听端口和状态(由于还未启动,所以状态为 Down/inactive)、目录信息。

2.安全启动 注意该操作会初始化集群

tiup cluster start tidb-test --init
3.普通启动
tiup cluster start tidb-test

4.验证集群运行状态
tiup cluster display tidb-test

5.停止集群

tiup cluster stop tidb-test

8.TiFlash 组件启动失败 排查步骤

# 使用 systemctl 查看 tiflash 服务状态(服务名通常是 tiup-<cluster-name>-tiflash-<port>)
systemctl status tiflash-9000.service

# 检查部署目录权限
ls -ld /home/tidb/tidb-deploy/tiflash-9000/
ls -la /home/tidb/tidb-deploy/tiflash-9000/conf/

# 检查数据目录权限
ls -ld /home/tidb/tidb-data/tiflash-9000/

# 如果权限不对,进行修正 (在正确的主机上以 root 身份执行)
sudo chown -R tidb:tidb /home/tidb/tidb-deploy/tiflash-9000
sudo chown -R tidb:tidb /home/tidb/tidb-data/tiflash-9000

# 切换到 tidb 用户 (如果当前不是)
su - tidb

# 进入 TiFlash 的部署目录
cd /home/tidb/tidb-deploy/tiflash-9000

# 直接运行启动脚本,查看实时输出和错误
bash -x scripts/run_tiflash.sh

 运行上述命令后会输出详细错误信息 注意
 本地部署出现的错误如下:
[tidb@localhost tiflash-9000]$ bash -x scripts/run_tiflash.sh
+ set -e
+ cd /home/tidb/tidb-deploy/tiflash-9000
+ export RUST_BACKTRACE=1
+ RUST_BACKTRACE=1
+ export TZ=/etc/localtime
+ TZ=/etc/localtime
+ export LD_LIBRARY_PATH=/home/tidb/tidb-deploy/tiflash-9000/bin/tiflash:
+ LD_LIBRARY_PATH=/home/tidb/tidb-deploy/tiflash-9000/bin/tiflash:
+ export MALLOC_CONF=prof:true,prof_active:false
+ MALLOC_CONF=prof:true,prof_active:false
+ '[' -f /proc/cpuinfo ']'
+ IFS_OLD=' 
'
+ IFS=' '
+ required_cpu_flags='avx2 popcnt movbe'
++ echo avx2 popcnt movbe
+ for flag in '$(echo $required_cpu_flags)'
+ grep -q avx2 /proc/cpuinfo
+ err_msg='Fail to check CPU flags: `avx2` not supported. Require `avx2 popcnt movbe`.'
+ echo Fail to check CPU flags: '`avx2`' not supported. Require '`avx2' popcnt 'movbe`.'
Fail to check CPU flags: `avx2` not supported. Require `avx2 popcnt movbe`.
+ echo Fail to check CPU flags: '`avx2`' not supported. Require '`avx2' popcnt 'movbe`.'
+ exit -1


--------------------------------------------------------------------
错误原因
您的 CPU 不支持 AVX2 指令集,但当前版本的 TiFlash 强制要求运行在支持 AVX2 的 CPU 上。启动脚本在检查 /proc/cpuinfo 时没有找到 avx2 这个标志,因此直接报错退出

验证您的 CPU 信息:

bash
# 查看 CPU 支持的指令集 flags
grep flags /proc/cpuinfo | head -1

# 或者使用更清晰的命令
cat /proc/cpuinfo | grep -m1 -o avx2 || echo "AVX2 not supported"
cat /proc/cpuinfo | grep -m1 -o avx || echo "AVX not supported"
View Code

9.使用不支持 AVX2 的特殊版本 TiFlash

1.修改拓扑文件 (topology.yaml):
添加 version 字段,指定使用 v7.5.0-noavx2 或类似的版本。

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"
   version: v7.5.0-noavx2  # <--- 在这里为所有 TiFlash 实例指定版本

# 注意:请确保这个版本与您集群中其他组件的版本兼容。

2.重新部署

10.完整配置文件

# # 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: "/home/tidb/tidb-deploy"
 data_dir: "/home/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"
   version: v7.5.0-noavx2  # <--- 在这里为所有 TiFlash 实例指定版本

pd_servers:
 - host: 192.168.20.31

tidb_servers:
 - host: 192.168.20.31

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

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

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

tiflash_servers:
 - host: 192.168.20.31

monitoring_servers:
 - host: 192.168.20.31

grafana_servers:
 - host: 192.168.20.31
View Code

11.修改密码

部署完成后数据库没有密码,默认端口4000

进入mysql数据库执行命令:

ALTER USER 'root'@'%' IDENTIFIED BY '你的新密码';

执行后需刷新权限:

FLUSH PRIVILEGES;

快捷启动:

tiup cluster start tidb-test

快捷停止:

tiup cluster stop tidb-test

 

posted @ 2025-08-20 15:05  不再_单纯  阅读(44)  评论(0)    收藏  举报