TiUP 簡介
4.0版本引入的命令行管理工具(TiUP),用於支持TiDB、PD、TiKV 等組件運維管理工作。它大大降低維護管理成本。
工具語法
[root@progs tidb]# tiup --help
TiUP is a command-line component management tool that can help to download and install
TiDB platform components to the local system. You can run a specific version of a component via
"tiup <component>[:version]". If no version number is specified, the latest version installed
locally will be used. If the specified component does not have any version installed locally,
the latest stable version will be downloaded from the repository.
Usage:
tiup [flags] <command> [args...]
tiup [flags] <component> [args...]
Available Commands:
install Install a specific version of a component
list List the available TiDB components or versions
uninstall Uninstall components or versions of a component
update Update tiup components to the latest version
status List the status of instantiated components
clean Clean the data of instantiated components
mirror Manage a repository mirror for TiUP components
telemetry Controls things about telemetry
completion Output shell completion code for the specified shell (bash or zsh)
env Show the list of system environment variable that related to TiUP
help Help about any command or component
Components Manifest:
use "tiup list" to fetch the latest components manifest
Flags:
-B, --binary <component>[:version] Print binary path of a specific version of a component <component>[:version]
and the latest version installed will be selected if no version specified
--binpath string Specify the binary path of component instance
--help Help for this command
--skip-version-check Skip the strict version check, by default a version must be a valid SemVer string
-T, --tag string Specify a tag for component instance
-v, --version Print the version of tiup
Component instances with the same "tag" will share a data directory ($TIUP_HOME/data/$tag):
$ tiup --tag mycluster playground
Examples:
$ tiup playground # Quick start
$ tiup playground nightly # Start a playground with the latest nightly version
$ tiup install <component>[:version] # Install a component of specific version
$ tiup update --all # Update all installed components to the latest version
$ tiup update --nightly # Update all installed components to the nightly version
$ tiup update --self # Update the "tiup" to the latest version
$ tiup list # Fetch the latest supported components list
$ tiup status # Display all running/terminated instances
$ tiup clean <name> # Clean the data of running/terminated instance (Kill process if it's running)
$ tiup clean --all # Clean the data of all running/terminated instances
Use "tiup [command] --help" for more information about a command.
從上面,可以看到它支持2組(command|component)操作參數。
- command(命令)是TiUP 自帶輸入參數,用於進行包管理的操作。
- component(組件)通過包管理操作已安裝的獨立組件包。先檢查本地是否存在組件包,若本地沒有,則先從鏡像倉庫下載到本地,然后運行該組件包;
鏡像倉庫
TiUP 的所有組件都從鏡像倉庫(包含各個組件的 TAR 包以及對應的元信息[版本、入口啟動文件、校驗和])下載。TiUP 默認使用 PingCAP 官方的鏡像倉庫, 也可以通過 TIUP_MIRRORS
環境變量自定義鏡像倉庫。
指定鏡像倉庫
# 指定本地目錄作為經常倉庫
TIUP_MIRRORS=/path/to/local tiup list
# 恢復 PingCAP 官方的鏡像倉庫
TIUP_MIRRORS=/path/to/local
鏡像倉庫切換
# 執行 tiup mirror set <mirror-dir> 進行切換
tiup mirror set tidb-community-server-${version}-linux-amd64
# 切換到在線環境
tiup mirror set https://tiup-mirrors.pingcap.com
制作本地鏡像倉庫
tiup mirror --help
集群管理操作
集群啟動
使用 TiUP 啟動 TiDB 集群時,它按照 PD -> TiKV -> Pump -> TiDB -> TiFlash -> Drainer 的順序啟動整個 TiDB 集群所有組件(同時也會啟動監控組件)。
示例
- 啟動集群
tiup cluster start ${cluster-name}
- 通過
-R
和-N
參數來只啟動部分組件
# 只啟動 PD 組件
tiup cluster start ${cluster-name} -R pd
# 只啟動 1.2.3.4 和 1.2.3.5 這兩台機器上的 PD 組件
tiup cluster start ${cluster-name} -N 1.2.3.4:2379,1.2.3.5:2379
- 關閉集群
關閉集群操作會按 Drainer -> TiFlash -> TiDB -> Pump -> TiKV -> PD 的順序關閉整個 TiDB 集群所有組件(同時也會關閉監控組件)
tiup cluster stop ${cluster-name}
和 start
命令類似,stop
命令也支持通過 -R
和 -N
參數來只停止部分組件。
# 只停止 TiDB 組件
tiup cluster stop ${cluster-name} -R tidb
# 只停止指定機器上的 TiDB 組件
tiup cluster stop ${cluster-name} -N ${tidb-server1}:4000,${tidb-server1}:4000
- 查看集群狀態
tiup cluster list
tiup cluster display <cluster-name>
TiUP CTL組件
tiup 支持使用CTL組件對各自組件管理(命令行工具)
安裝CTL組件
tiup install ctl
使用方法
Usage:
tiup ctl {tidb/pd/tikv/binlog/etcd/cdc} [flags]
示例
# 檢查 pd 組件的健康情況
tiup ctl pd health