1. 程式人生 > >tidb叢集新增新的tidb節點

tidb叢集新增新的tidb節點

參考文件:https://www.pingcap.com/docs-cn/QUICKSTART/#tidb-%e9%9b%86%e7%be%a4%e6%89%a9%e5%ae%b9%e7%bc%a9%e5%ae%b9%e6%96%b9%e6%a1%88

參考文件:https://pingcap.com/docs-cn/op-guide/ansible-deployment-scale/

 

TIDB官方文件手冊:https://www.pingcap.com/docs-cn/,當前操作tidb叢集版本是v2.1

1、準備機器

已經部署了tidb叢集,部署過程見以前的部落格文章,執行一段時間後,qps到達瓶頸,查了下問題出在tidb效能到瓶頸,需要擴容tidb節點。

在已有的新節點上,擴容tidb節點,伺服器新購買,所以需要一些統一標準,特別是初始化的配置,以及安裝環境準備等等。

準備資源配置檔案cleric_add.ini

 

hy3-tidb-[3:4].csdn.com

 

 

在ansible上面安裝tidb賬號,在csdndbtls上安裝(這是一臺能連通所有tidb節點的伺服器)

ansible -i cleric_add.ini all -m shell -a "useradd tidb" -b

 

準備公鑰

scp hy3-tipd-1.csdn.com:/tmp/id_rsa.pub .

 

1.2 建立tidb互通免祕鑰


準備好sudo.txt

%tidb ALL=(ALL) ALL
%tidb ALL=(ALL) NOPASSWD: ALL

 

在csdndbtls操作(這是一臺能通所有tidb叢集節點的中間伺服器),讓tidb能sudo到管理員進行各種安裝操作

在csdndbtls上面

cd /home/ansible/csdnhs/sms

ansible -i cleric_add.ini all -m copy -a "src=sudo.txt dest=/tmp/sudoers.1 mode=0644" -uansible -b

ansible -i cleric_add.ini all -m shell -a "cat /tmp/sudoers.1 >> /etc/sudoers" -uansible -b

 

設定tidb互通

將中控機的tidb的公鑰copy到csdndbtls上面,在csdndbtls上操作

ansible -i cleric_add.ini all -m copy -a "src=id_rsa.pub dest=/tmp/id_rsa.pub.1" -b

ansible -i cleric_add.ini all -m shell -a "mkdir -p /home/tidb/.ssh/" -b

ansible -i cleric_add.ini all -m shell -a "chown -R tidb.tidb /home/tidb" -b

ansible -i cleric_add.ini all -m shell -a "cat /tmp/id_rsa.pub.1 >> /home/tidb/.ssh/authorized_keys" -b

ansible -i cleric_add.ini all -m shell -a "chmod 600 /home/tidb/.ssh/authorized_keys" -b

ansible -i cleric_add.ini all -m shell -a "chown -R tidb.tidb /home/tidb" -b

ansible -i cleric_add.ini all -m shell -a "chown -R tidb.tidb /data0" -b

 

設定後,試下:

執行過程:

[[email protected]] ~$ ssh hy3-tidb-3.csdn.com
The authenticity of host 'hy3-tidb-3.csdn.com (172.20.96.167)' can't be established.
ECDSA key fingerprint is 22:49:b2:5c:7c:8f:73:56:89:29:8a:bd:56:49:74:66.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hy3-tidb-3.csdn.com,172.20.96.167' (ECDSA) to the list of known hosts.
[[email protected]] ~$ exit
logout
Connection to hy3-tidb-3.csdn.com closed.
[[email protected]] ~$ ssh hy3-tidb-4.csdn.com
The authenticity of host 'hy3-tidb-4.csdn.com (172.20.98.161)' can't be established.
ECDSA key fingerprint is 22:49:b2:5c:7c:8f:73:56:89:29:8a:bd:56:49:74:66.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hy3-tidb-4.csdn.com,172.20.98.161' (ECDSA) to the list of known hosts.
[[email protected]] ~$ exit

 

 

在csdndbtls上安裝ntp服務

安裝:ansible -i cleric_add.ini all -m shell -a "sudo yum install ntp ntpdate -y" -b

啟動:ansible -i cleric_add.ini  all -m shell -a "sudo systemctl start ntpd.service " -b

 

 

準備,生成h.txt,上面ansible命令的時候,會有所有的tidb節點域名地址日誌資訊,copy到1.log,然後 more 1.log |grep hy3 |awk '{print $1}' |sort >> h.txt 就生成了域名的檔案,之後再

  1. 因為就2個節點,所以下面的辦法沒有用到:

[[email protected]] ~/csdnhs/tidb$ more 1.log |grep hy3 |awk '{print $1}' |sort >> h.txt

[[email protected]] ~/csdnhs/tidb$ more h.txt
hy3-tidb-3.csdn.com
hy3-tidb-4.csdn.com
[[email protected]] ~/csdnhs/tidb$ more h.txt
hy3-tidb-3.csdn.com
hy3-tidb-4.csdn.com
[[email protected]] ~/csdnhs/tidb$ for h in `cat h.txt`;do echo `nslookup $h |grep 'Address: 10' |sed 's/Address: //'` $h;done
172.10.66.118 hy3-tidb-3.csdn.com
172.10.167.52 hy3-tidb-4.csdn.com
[[email protected]] ~/csdnhs/tidb$

 

 

2、開始部署

先去vim inventory.ini新增2個新節點

[tidb_servers]

172.10.66.118
172.10.167.52

 

[monitored_servers]

172.10.66.118
172.10.167.52

 

這個就是改一些引數和建目錄

 

  1. 初始化新增節點:

    ansible-playbook bootstrap.yml -l 172.10.66.118,172.10.167.52

     

  2. 部署新增節點:

    ansible-playbook deploy.yml -l 172.10.66.118,172.10.167.52

     

  3. 啟動新節點服務:

    ansible-playbook start.yml -l 172.10.66.118,172.10.167.52
     
  4. 更新 Prometheus 配置並重啟:

    ansible-playbook rolling_update_monitor.yml --tags=prometheus

 

測試使用新的tidb節點登陸,成功,如下:

[[email protected]] ~$ mysql -h 172.10.66.118 -uroot -p -P4000 hy3lt

Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.10-TiDB-v2.0.0-rc.4-214-g7fbbb1f MySQL Community Server (Apache License 2.0)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

root-172.10.66.118:4000:hy3lt 22:03:11>