TiDB 集群 IP 變更快速指南(離線變更)

前言

TiDB 集群 IP 變更可以通過先擴(kuò)容再縮容的方式,實(shí)現(xiàn)在線的集群 IP 的遷移。

此文檔為離線變更操作手冊(cè)。

  • TiDB Server 作為一個(gè)無狀態(tài)服務(wù)。所以直接更換 IP 即可,同時(shí)修改 PD Server 地址。
  • TiKV Server 作為一個(gè) Mutil Raft Group,信息會(huì)在 PD Server 中注冊(cè),所以直接更換 IP 即可,同時(shí)修改 PD Server 地址。
  • PD Server 作為一個(gè)元數(shù)據(jù)管理節(jié)點(diǎn),更換 IP 后需要新建 PD 集群,然后進(jìn)行 PD Recover 操作,恢復(fù)原有 PD 集群信息。

收集需要的信息

新建 PD 集群后,現(xiàn)有的信息會(huì)丟失,因此需要些備份這些信息。

獲取 PD 中的設(shè)置
.../tidb-ansible/resource/bin/pd-ctl -u http://{pdip}:2379 -d config show all > pd.txt

其中常見的調(diào)整參數(shù)有 leader-scheduler-limit、region-scheduler-limit、leader-scheduler-limit 等。
如果沒有使用 pd-ctl 修改過默認(rèn)配置,此步驟可跳過。

獲取 Cluster ID

一般在 PD,TiKV 或 TiDB 的日志中都可以獲取 Cluster ID??梢詮闹锌貦C(jī)使用 ansible ad-hoc,也可以直接去服務(wù)器上翻日志。

從 pd 日志獲取 [info] cluster id

ansible -i inventory.ini pd_servers -m shell -a 'cat {{deploy_dir}}/log/pd.log | grep "init cluster id" | head -10'
10.0.1.13 | CHANGED | rc=0 >>
[2019/10/14 10:35:38.880 +00:00] [INFO] [server.go:212] ["init cluster id"] [cluster-id=6747551640615446306]
……
獲取 Alloc ID(TiKV StoreID)

在指定 alloc-id 時(shí)需指定一個(gè)比當(dāng)前最大的 Alloc ID 更大的值??梢詮闹锌貦C(jī)使用 ansible ad-hoc,也可以直接去服務(wù)器上翻日志。

從 pd 日志獲取 [info] allocates id

ansible -i inventory.ini pd_servers -m shell -a 'cat {{deploy_dir}}/log/pd* | grep "allocates" | head -10'
10.0.1.13 | CHANGED | rc=0 >>
[2019/10/15 03:15:05.824 +00:00] [INFO] [id.go:91] ["idAllocator allocates a new id"] [alloc-id=3000]
[2019/10/15 08:55:01.275 +00:00] [INFO] [id.go:91] ["idAllocator allocates a new id"] [alloc-id=4000]
……

集群 IP 地址變更

停止集群

停止現(xiàn)有集群

ansible-playbook stop.yml
變更集群服務(wù)器 ip 地址

編輯 inevntory.ini 文件

編輯 inventory.ini 文件,修改 host ip

cp inventory.ini inventory.ini.bak
vi inventory.ini
清除之前的 PD 數(shù)據(jù)

備份并清理原有 PD Server 的數(shù)據(jù)

ansible -i inventory.ini pd_servers -m shell -a 'mv {{deploy_dir}}/data.pd/ {{deploy_dir}}/data.pd.bak/'
ansible -i inventory.ini pd_servers -m shell -a 'rm -rf {{deploy_dir}}/data.pd'
部署新 IP 地址的集群
ansible-playbook deploy.yml
恢復(fù) PD 設(shè)置
.../tidb-ansible/resource/bin/pd-ctl -u http://{pdip}:2379 -d config set xxx xx

PD Recover 恢復(fù)舊集群信息

啟動(dòng)新 PD 集群
ansible-playbook start.yml --tags=pd
使用 pd-recover

使用 pd-recover 按照舊的 -cluster-id、-alloc-id 恢復(fù) pd 集群信息

./pd-recover -endpoints http://{pdip}:2379 -cluster-id 6747551640615446306 -alloc-id 10000
重啟 pd 集群
ansible-playbook rolling_update.yml --tags=pd

啟動(dòng)集群

啟動(dòng)剩余服務(wù)

ansible-playbook start.yml --skip-tags=pd

滾動(dòng)監(jiān)控

更新監(jiān)控信息

ansible-playbook rolling_update_monitor.yml --tags=prometheus




常見問題

獲取 Cluster ID 時(shí)發(fā)現(xiàn)有多個(gè)

新建 PD 集群時(shí),會(huì)生成新的 Cluster ID??梢酝ㄟ^日志判斷舊集群的 Cluster ID。

執(zhí)行 pd-recover 時(shí) dial tcp 10.0.1.13:2379: connect: connection refused

執(zhí)行 pd-recover 時(shí)需要 pd 提供服務(wù),請(qǐng)先部署并啟動(dòng) pd 集群。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容