从TiDBv4.0起,提供了包管理工具TiUP,负责管理TiDB、PD、TiKV等组件。用户只需通过TiUP命令即可运行这些组件,显著降低了管理难度。TiUP程序只包含少数几个命令,用来下载、更新、卸载组件。TiUP通过各种组件来扩展其功能。组件是一个可以运行的程序或脚本,通过tiup <component>运行组件时,TiUP会添加一组环境变量,并为该程序创建好对应的数据目录,然后运行该程序。
视频讲解如下:
https://www.bilibili.com/video/BV1tRRvYsEM4/?aid=114290119939...
下面的步骤将在单机上快速部署一个TiDB数据库集群。
(1)下载并安装TiUP
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
# 安装完成后会提示如下信息:
Successfully set mirror to https://tiup-mirrors.pingcap.com
Detected shell: bash
Shell profile: /root/.bash_profile
/root/.bash_profile has been modified to add tiup to PATH
open a new terminal or source /root/.bash_profile to use it
Installed path: /root/.tiup/bin/tiup
===============================================
Have a try: tiup playground
===============================================
(2)生效环境变量
source /root/.bash_profile
(3)由于模拟多机部署,需要通过root用户调大sshd服务的连接数限制。修改/etc/ssh/sshd_config将MaxSessions调至20。
(4)重启sshd服务
service sshd restart
(5)执行命令运行最新版本的TiDB集群,其中TiDB、TiKV、PD和TiFlash实例各1个。
tiup playground
# 如果这是第一次运行该命令,TiUP会下载最新版本的TiDB并启动集群。
(6)TiDB集群启动后,将输出下面的信息。
TiDB Playground Cluster is started, enjoy!
Connect TiDB: mysql --comments --host 127.0.0.1 --port 4000 -u root
TiDB Dashboard: http://127.0.0.1:2379/dashboard
Grafana: http://127.0.0.1:3000
(7)TiUP也可以指定TiDB版本以及各组件实例个数,例如:
tiup playground v8.5.1 --db 2 --pd 3 --kv 3
# 此时将启动2个TiDB、3个PD和3个TiKV。
(8)执行命令查看当前支持部署的所有TiDB版本。
tiup list tidb
# 输出信息如下:
......
v8.2.0 2024-07-11T08:28:29Z
v8.3.0 2024-08-22T04:35:09Z
v8.4.0 2024-11-11T05:51:14Z
v8.5.0 2024-12-19T06:05:34Z
v8.5.1 YES 2025-01-17T07:30:24Z
v9.0.0-alpha-nightly 2025-02-07T04:11:42Z
(9)使用TiUP client连接TiDB。
tiup client
# 也可以使用mysql命令行客户端进行连接
(10)登录成功后将输出下面的信息。
Starting component client:
/root/.tiup/components/client/v1.16.1/tiup-client
Connected with driver mysql (8.0.11-TiDB-v8.5.1)
Type "help" for help.
my:root@127.0.0.1:4000=>
(11)执行命令查看TiDB中已存在的数据库信息。
my:root@127.0.0.1:4000=> show databases;
Database
--------------------
INFORMATION_SCHEMA
METRICS_SCHEMA
PERFORMANCE_SCHEMA
mysql
sys
test
(6 rows)
(12)使用MySQL客户端连接TiDB。
mysql --host 127.0.0.1 --port 4000 -u root
(13)再次执行命令查看TiDB中已存在的数据库信息。
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| INFORMATION_SCHEMA |
| METRICS_SCHEMA |
| PERFORMANCE_SCHEMA |
| mysql |
| sys |
| test |
+--------------------+
6 rows in set (0.001 sec)
(14)为了方便操作TiDB,可以修改MySQL客户端的提示符。在/etc/my.cnf的配置文件中加入下面的配置信息:
[mysql]
prompt="tidb \h:\p>"
(15)重新使用MySQL客户端连接TiDB。
mysql --host 127.0.0.1 --port 4000 -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 2065694744
Server version: 8.0.11-TiDB-v8.5.1 TiDB Server
(Apache License 2.0) Community Edition, MySQL 8.0 compatible
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to
clear the current input statement.
tidb 127.0.0.1:4000>
(16)在TiUP的启动窗口中按下Control+C键停掉上述启用的TiDB数据库服务。
(17)等待服务退出操作完成后,执行以下命令清理创建的资源
tiup clean --all
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。