1. 首页 > 国产数据库教程 > TiDB教程 > 正文

tidb教程FG004-TiUP工具安装与集群管理

本文档详细介绍TiUP工具的安装与集群管理功能,包括TiUP的安装、组件管理、集群部署、扩缩容等操作。风哥教程参考TiDB官方文档TiUP相关内容,适合DBA和系统管理员使用。更多视频教程www.fgedu.net.cn

Part01-基础概念与理论知识

1.1 TiUP工具概念

TiUP是TiDB官方推出的集群管理工具,用于简化TiDB集群的部署、管理和运维。

  • 功能:集群部署、扩缩容、升级、备份恢复等
  • 特点:简单易用、功能强大、支持多版本管理
  • 架构:命令行工具 + 组件管理系统
TiUP的优势:

  • 统一的命令行接口
  • 组件版本管理
  • 配置管理和模板
  • 集群生命周期管理
  • 插件扩展机制

1.2 TiUP组件介绍

TiUP包含多个组件:

  • tiup cluster:集群管理组件
  • tiup playground:本地测试环境
  • tiup bench:性能测试组件
  • tiup mirror:镜像管理组件
  • tiup help:帮助信息

1.3 TiUP架构原理

TiUP的架构包括:

  • 核心组件:TiUP命令行工具
  • 组件管理:通过mirror管理组件版本
  • 集群管理:通过cluster组件管理集群
  • 配置管理:统一的配置模板和管理
风哥提示:TiUP是TiDB集群管理的核心工具,掌握TiUP的使用对于TiDB的部署和管理至关重要。学习交流加群风哥微信: itpux-com

Part02-生产环境规划与建议

2.1 安装要求

2.1.1 系统要求

# TiUP安装系统要求
– 操作系统:
– Linux:CentOS 7.3+ / RHEL 7.3+ / Ubuntu 16.04+
– macOS:10.13+风哥提示:
– Windows:WSL 2

– 硬件要求:
– CPU:至少2核
– 内存:至少4GB
– 存储:至少20GB可用空间

– 网络要求:
– 网络连接正常
– 可访问互联网(用于下载组件)

2.1.2 依赖软件

# 依赖软件
– curl:用于下载安装脚本
– tar:用于解压文件
– ssh:用于节点间通信
– sudo:用于权限管理
– python3:用于部分组件

# 安装依赖
# CentOS/RHEL
$ yum install -y curl tar openssh-clients sudo python3

# Ubuntu
$ apt install -y curl tar openssh-client sudo python3

2.2 环境准备

2.2.1 节点准备

# 节点准备

## 1. 主机名配置
$ hostnamectl set-hostname fgedu-tiup

## 2. 网络配置
$ cat >> /etc/hosts << EOF 192.168.1.101 fgedu-tidb-01.fgedu.net.cn 192.168.1.102 fgedu-tidb-02.fgedu.net.cn 192.168.1.103 fgedu-tikv-01.fgedu.net.cn 192.168.1.104 fgedu-tikv-02.fgedu.net.cn 192.168.1.105 fgedu-tikv-03.fgedu.net.cn 192.168.1.106 fgedu-pd-01.fgedu.net.cn 192.168.1.107 fgedu-pd-02.fgedu.net.cn 192.168.1.108 fgedu-pd-03.fgedu.net.cn EOF ## 3. SSH免密登录 $ ssh-keygen -t rsa -N "" $ for host in fgedu-tidb-01 fgedu-tidb-02 fgedu-tikv-01 fgedu-tikv-02 fgedu-tikv-03 fgedu-pd-01 fgedu-pd-02 fgedu-pd-03; do ssh-copy-id $host; done

2.2.2 防火墙配置

# 防火墙配置

## 关闭防火墙(生产环境建议配置规则)
$ systemctl stop firewalld
$ systemctl disable firewalld

## 或配置防火墙规则
$ firewall-cmd –permanent –add-port=22/tcp
$ firewall-cmd –permanent –add-port=4000/tcp
$ firewall-cmd –permanent –add-port=10080/tcp
$ firewall-cmd –permanent –add-port=2379/tcp
$ firewall-cmd –permanent –add-port=2380/tcp
$ firewall-cmd –permanent –add-port=20160/tcp
$ firewall-cmd –permanent –add-port=20180/tcp
$ firewall-cmd –reload

2.3 安全考虑

安全考虑因素:

  • 用户权限:使用普通用户部署,避免使用root
  • 密码管理:妥善保管TiDB root密码
  • 网络安全:限制网络访问范围
  • 镜像源:使用官方或可信的镜像源
生产环境建议:在生产环境中,应该使用非root用户部署TiDB集群,增强安全性。学习交流加群风哥QQ113257174

Part03-生产环境项目实施方案

3.1 TiUP安装

3.1.1 安装TiUP

# 安装TiUP
$ curl –proto ‘=https’ –tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh

# 重新加载环境变量
$ source ~/.bash_profile

# 验证安装学习交流加群风哥QQ113257174
$ tiup –version

# 输出示例
TiUP Version: 1.15.0
Git Commit Hash: abcdef1234
Git Branch: release-1.15
Build Time: 2026-04-01 00:00:00 +0000
Go Version: go1.20.0

3.1.2 配置TiUP

# 配置TiUP

## 设置镜像源(可选)
$ tiup mirror set https://tiup-mirrors.pingcap.com

## 查看当前镜像源
$ tiup mirror show

## 查看可用组件
$ tiup list

# 输出示例
Available components:
Name Version Platforms Description
—- ——- ——— ———–
bench v1.15.0 linux/amd64 Benchmark database with different workloads
cluster v1.15.0 linux/amd64 Deploy a TiDB cluster for production
playground v1.15.0 linux/amd64 Bootstrap a local TiDB cluster for testing
mirror v1.15.0 linux/amd64 Manage TiUP component mirror

3.2 集群管理操作

3.2.1 集群部署

# 集群部署

## 1. 创建拓扑文件
$ cat > topology.yaml << EOF global: user: "tidb" ssh_port: 22 deploy_dir: "/tidb/app" data_dir: "/tidb/fgdata" server_configs: tidb: log.level: "info" tikv: log.level: "info" pd: log.level: "info" pd_servers: - host: 192.168.1.106 - host: 192.168.1.107 - host: 192.168.1.108 tidb_servers: - host: 192.168.1.101 - host: 192.168.1.102 tikv_servers: - host: 192.168.1.103 - host: 192.168.1.104 - host: 192.168.1.105 tiflash_servers: - host: 192.168.1.109 - host: 192.168.1.110 EOF ## 2. 部署集群 $ tiup cluster deploy fgedu-tidb-cluster v7.5.0 topology.yaml --user root ## 3. 查看集群状态 $ tiup cluster display fgedu-tidb-cluster

3.2.2 集群启动与停止

# 集群启动与停止

## 启动集群
$ tiup cluster start fgedu-tidb-cluster

## 停止集群
$ tiup cluster stop fgedu-tidb-cluster

## 重启集群
$ tiup cluster restart fgedu-tidb-cluster

## 启动指定组件
$ tiup cluster start fgedu-tidb-cluster -R tidb

## 停止指定组件
$ tiup cluster stop fgedu-tidb-cluster -R tikv

3.2.3 集群扩缩容

# 集群扩缩容

## 扩容TiDB节点
$ cat > scale-out.yaml << EOF tidb_servers: - host: 192.168.1.111 EOF $ tiup cluster scale-out fgedu-tidb-cluster scale-out.yaml ## 扩容TiKV节点 $ cat > scale-out-tikv.yaml << EOF tikv_servers: - host: 192.168.1.112 EOF $ tiup cluster scale-out fgedu-tidb-cluster scale-out-tikv.yaml ## 缩容节点 $ tiup cluster scale-in fgedu-tidb-cluster --node 192.168.1.111:4000

3.3 配置管理

3.3.1 查看配置

# 查看配置

## 查看集群配置
$ tiup cluster config fgedu-tidb-cluster

## 查看指定组件配置
$ tiup cluster config fgedu-tidb-cluster –component tidb

## 查看指定节点配置
$ tiup cluster config fgedu-tidb-cluster –node 192.168.1.101:4000

3.3.2 修改配置

# 修改配置

## 修改TiDB配置
$ tiup cluster edit-config fgedu-tidb-cluster

# 在编辑器中修改配置
server_configs:
tidb:
performance.max-procs: 16
prepared-plan-cache.enable: true

## 应用配置变更
$ tiup cluster reload fgedu-tidb-cluster -R tidb

风哥提示:修改配置后,需要重新加载组件才能使配置生效。更多学习教程公众号风哥教程itpux_com

Part04-生产案例与实战讲解

4.1 安装实战案例

4.1.1 在CentOS 7上安装TiUP

# 在CentOS 7上安装TiUP

## 1. 系统准备
$ yum update -y
$ yum install -y curl tar openssh-clients sudo python3

## 2. 安装TiUP
$ curl –proto ‘=https’ –tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
$ source ~/.bash_profile

## 3. 验证安装
$ tiup –version

## 4. 安装cluster组件
$ tiup install cluster

## 5. 查看cluster组件版本
$ tiup cluster –version

4.1.2 部署生产集群

# 部署生产集群

## 1. 创建详细拓扑文件
$ cat > production-topology.yaml << EOF global: user: "tidb" ssh_port: 22 deploy_dir: "/tidb/app" data_dir: "/tidb/fgdata" arch: "amd64" server_configs: tidb: log.level: "info" performance.max-procs: 16 prepared-plan-cache.enable: true tikv: log.level: "info" performance.max-procs: 16 storage.scheduler-worker-pool-size: 4 pd: log.level: "info" replication.enable-placement-rules: true pd_servers: - host: 192.168.1.106 ssh_port: 22 port: 2379 client_port: 2379 peer_port: 2380 - host: 192.168.1.107 ssh_port: 22 port: 2379 client_port: 2379 peer_port: 2380 - host: 192.168.1.108 ssh_port: 22 port: 2379 client_port: 2379 peer_port: 2380 tidb_servers: - host: 192.168.1.101 ssh_port: 22 port: 4000 status_port: 10080 - host: 192.168.1.102 ssh_port: 22 port: 4000 status_port: 10080 tikv_servers: - host: 192.168.1.103 ssh_port: 22 port: 20160 status_port: 20180 - host: 192.168.1.104 ssh_port: 22 port: 20160 status_port: 20180 - host: 192.168.1.105 ssh_port: 22 port: 20160 status_port: 20180 tiflash_servers: - host: 192.168.1.109 ssh_port: 22 port: 3930 status_port: 20292 - host: 192.168.1.110 ssh_port: 22 port: 3930 status_port: 20292 EOF ## 2. 部署集群 $ tiup cluster deploy fgedu-prod-cluster v7.5.0 production-topology.yaml --user root ## 3. 启动集群 $ tiup cluster start fgedu-prod-cluster ## 4. 验证集群状态 $ tiup cluster display fgedu-prod-cluster

4.2 集群管理案例

4.2.1 集群升级

# 集群升级

## 1. 检查可用版本
$ tiup list tidb

## 2. 升级集群
$ tiup cluster upgrade fgedu-tidb-cluster v7.5.1

## 3. 验证升级结果
$ tiup cluster display fgedu-tidb-cluster

## 4. 回滚升级(如果需要)
$ tiup cluster rollback fgedu-tidb-cluster

4.2.2 集群备份

# 集群备份

## 1. 安装br组件
$ tiup install br

## 2. 执行全量备份
$ tiup cluster backup fgedu-tidb-cluster –storage s3://fgedu-backup –full

## 3. 执行增量备份
$ tiup cluster backup fgedu-tidb-cluster –storage s3://fgedu-backup –inc

## 4. 查看备份状态
$ tiup cluster backup list fgedu-tidb-cluster –storage s3://fgedu-backup

4.3 常见问题排查

4.3.1 部署失败

# 部署失败问题

## 问题现象
$ tiup cluster deploy fgedu-tidb-cluster v7.5.0 topology.yaml –user root
> Error: failed to connect to 192.168.1.101:22: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain

## 解决方案
1. 检查SSH连接
$ ssh root@192.168.1.101

2. 配置SSH免密登录
$ ssh-keygen -t rsa -N “”
$ ssh-copy-id root@192.168.1.101

3. 重新部署
$ tiup cluster deploy fgedu-tidb-cluster v7.5.0 topology.yaml –user root

4.3.2 集群启动失败

# 集群启动失败问题

## 问题现象
$ tiup cluster start fgedu-tidb-cluster
> Error: failed to start tidb-192.168.1.101:4000: timed out waiting for port 4000 to be ready

## 解决方案
1. 查看日志
$ tiup cluster logs fgedu-tidb-cluster -R tidb

2. 检查端口占用
$ ssh 192.168.1.101 “lsof -i :4000”

3. 检查配置文件
$ tiup cluster config fgedu-tidb-cluster –node 192.168.1.101:4000

4. 手动启动检查
$ ssh 192.168.1.101 “/tidb/app/tidb-7.5.0/bin/tidb-server –config /tidb/app/tidb-7.5.0/conf/tidb.toml”

生产环境建议:在遇到问题时,及时查看日志和配置文件,定位问题原因,然后采取相应的解决措施。from tidb视频:www.itpux.com

Part05-风哥经验总结与分享

5.1 最佳实践

TiUP工具使用最佳实践:

  • 版本管理:使用固定版本部署,避免版本混乱
  • 配置模板:使用标准化的配置模板
  • 备份策略:定期备份集群配置和数据
  • 权限管理:使用非root用户部署和管理
  • 监控集成:与监控系统集成
  • 文档记录:记录集群部署和管理过程

5.2 性能优化

# TiUP性能优化

## 1. 优化TiUP本身
$ tiup mirror set https://tiup-mirrors.pingcap.com –force
$ tiup update –self

## 2. 优化部署速度
$ tiup cluster deploy fgedu-tidb-cluster v7.5.0 topology.yaml –user root –parallel 10

## 3. 优化配置管理
$ tiup cluster edit-config fgedu-tidb-cluster
# 调整关键参数

## 4. 优化扩缩容速度
$ tiup cluster scale-out fgedu-tidb-cluster scale-out.yaml –parallel 5

5.3 使用场景

TiUP工具的使用场景:

  • 生产集群部署:部署多节点生产集群
  • 测试环境搭建:快速搭建测试环境
  • 集群维护:日常维护和管理
  • 版本升级:集群版本管理和升级
  • 灾难恢复:集群备份和恢复
  • 性能测试:使用bench组件进行性能测试
风哥提示:TiUP是TiDB生态系统中的核心工具,掌握TiUP的使用可以大大提高TiDB集群的管理效率和可靠性。

持续学习:TiUP工具在不断演进,建议定期查看官方文档,了解新特性和最佳实践。

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息