從TiDBv4.0起,提供了包管理工具TiUP,負責管理TiDB、PD、TiKV等組件。用戶只需通過TiUP命令即可運行這些組件,顯著降低了管理難度。TiUP程序只包含少數幾個命令,用來下載、更新、卸載組件。TiUP通過各種組件來擴展其功能。組件是一個可以運行的程序或腳本,通過tiup 運行組件時,TiUP會添加一組環境變量,并為該程序創建好對應的數據目錄,然后運行該程序。
視頻講解如下 |
---|
【趙渝強老師】快速上手TiDB |
下面的步驟將在單機上快速部署一個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 rootWelcome 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 compatibleCopyright (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