1、如果之前安裝過 TiUP,使用如下命令更新至最新版本即可:
tiup update cluster
注意: 如果 tiup --version 顯示 tiup 版本低於 v1.0.0,請在執行 tiup update cluster 之前先執行 tiup update --self 命令更新 tiup 版本。
2、滾動升級 TiDB 集羣
最新版本可以通過執行 tiup list tidb 來查看 TiUP 支持的版本
tiup list tidb
運行後可以看到相關的版本
Available versions for tidb:
Version Installed Release Platforms
------- --------- ------- ---------
nightly 2020-06-29T05:00:12+08:00 linux/amd64,darwin/amd64
……
v4.0.0-beta.1 2020-05-26T11:42:48+08:00 linux/amd64,linux/arm64,darwin/amd64
v4.0.0-beta.2 2020-05-26T11:56:51+08:00 linux/amd64,linux/arm64,darwin/amd64
v4.0.0-rc 2020-05-26T14:56:06+08:00 linux/amd64,linux/arm64,darwin/amd64
v4.0.0-rc.1 2020-04-29T01:03:31+08:00 linux/amd64,linux/arm64,darwin/amd64
v4.0.0-rc.2 2020-05-15T21:54:51+08:00 linux/amd64,linux/arm64,darwin/amd64
v4.0.0 2020-05-28T20:10:10+08:00 linux/amd64,linux/arm64,darwin/amd64
v4.0.1 2020-06-12T21:22:29+08:00 linux/amd64,linux/arm64,darwin/amd64
[tidb@dev29 ~]$
2.1、將集羣升級到指定版本
tiup cluster upgrade <cluster-name> <version>
以升級到 v4.0.0 版本爲例:
tiup cluster upgrade <cluster-name> v4.0.0
滾動升級會逐個升級所有的組件。升級 TiKV 期間,會逐個將 TiKV 上的所有 leader 切走再停止該 TiKV 實例。默認超時時間爲 5 分鐘,超過後會直接停止實例。
如果不希望驅逐 leader,而希望立刻升級,可以在上述命令中指定 --force,該方式會造成性能抖動,不會造成數據損失。但是對線上運行的集羣影響較大。
tiup cluster upgrade v4.0.0 --force
如果希望保持性能穩定,則需要保證 TiKV 上的所有 leader 驅逐完成後再停止該 TiKV 實例,可以指定 --transfer-timeout 爲一個超大值,如 --transfer-timeout 100000000,單位爲 s。
例:tiup cluster upgrade v4.0.0 --transfer-timeout 100000000
2.2、升級後驗證
tiup cluster display <cluster-name>
報錯:
Restarting component tiflash
Restarting instance 192.168.181.6
retry error: operation timed out after 1m0s
192.168.181.6 failed to restart: timed out waiting for port 9000 to be started after 1m0s
Error: failed to upgrade: failed to restart tiflash: 192.168.181.6 failed to restart: timed out waiting for port 9000 to be started after 1m0s: timed out waiting for port 9000 to be started after 1m0s
Verbose debug logs has been written to /home/tidb/logs/tiup-cluster-debug-2020-06-29-20-26-05.log.
Error: run `/home/tidb/.tiup/components/cluster/v1.0.7/tiup-cluster` (wd:/home/tidb/.tiup/data/S3IqRWN) failed: exit status 1
快速處理的話,可以先 scale-in tiflash 節點。升級成功後在擴容上去。
方案1:
1、使用 pd-ctl 的 store 命令在 PD 中查看該 TiFlash 節點對應的 store id。(pd-address——IP:prot)
tiup ctl pd -u <pd-address> store
2、在 pd-ctl 中下線該 TiFlash 節點。
tiup ctl pd -u <pd-address> store delete <store_id>
3、等待該 TiFlash 節點對應的 store 消失或者 state_name 變成 Tombstone 再關閉 TiFlash 進程。
如果等待較長時間後,該節點仍然無法正常消失或者狀態變成 Tombstone,可以考慮以下命令,把節點強制踢出集羣:
注意以下命令會直接丟棄該 TiFlash 節點上的副本,有可能導致查詢失敗
curl -X POST 'http://<pd-address>/pd/api/v1/store/<store_id>/state?state=Tombstone'
4、手動刪除 TiFlash 的數據文件,具體位置可查看在集羣拓撲配置文件中 TiFlash 配置部分下的 data_dir
目錄。
一般默認是:/tidb-data/tiflash-9000找到tiflash的機器刪除
5、手動更新 TiUP 的集羣配置文件,在編輯模式中手動刪除我們已經下線的 TiFlash 節點信息:
tiup cluster edit-config <cluster-name>
注意:
如果在集羣中所有的 TiFlash 節點停止運行之前,沒有取消所有同步到 TiFlash 的表,則需要手動在 PD 中清除同步規則,否則無法成功完成 TiFlash 節點的下線。
注1、查詢當前 PD 實例中所有與 TiFlash 相關的的數據同步規則。
curl http://<pd_ip>:<pd_port>/pd/api/v1/config/rules/group/tiflash
[
{
"group_id": "tiflash",
"id": "table-45-r",
"override": true,
"start_key": "7480000000000000FF2D5F720000000000FA",
"end_key": "7480000000000000FF2E00000000000000F8",
"role": "learner",
"count": 1,
"label_constraints": [
{
"key": "engine",
"op": "in",
"values": [
"tiflash"
]
}
]
}
]
注2、刪除所有與 TiFlash 相關的數據同步規則。以 id 爲 table-45-r 的規則爲例,通過以下命令可以刪除該規則。
curl -v -X DELETE http://<pd_ip>:<pd_port>/pd/api/v1/config/rule/tiflash/table-45-r
6、再次查看集羣狀態
tiup cluster display <cluster-name>
(完成)
方案2:執行 scale-in 命令來下線節點,獲得該節點名爲 10.0.1.4:9000
tiup cluster scale-in <cluster-name> --node 10.0.1.4:9000
tiup常用語法
啓動集羣
啓動集羣操作會按 PD -> TiKV -> Pump -> TiDB -> TiFlash -> Drainer 的順序啓動整個 TiDB 集羣所有組件(同時也會啓動監控組件):
tiup cluster start ${cluster-name}
注意:
你需要將 ${cluster-name} 替換成實際的集羣名字,若忘記集羣名字,可通過 tiup cluster list 查看。
該命令支持通過 -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
# 手動停止集羣
[tidb@test1 ~]$ tiup cluster stop tidb-test
# 銷燬集羣
[tidb@test1 ~]$ tiup cluster destroy tidb-test