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

设置后,试下:

执行过程:

[tidb@hy3-tidb-pd-1] ~$ 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.
[tidb@hy3-tidb-3] ~$ exit
logout
Connection to hy3-tidb-3.csdn.com closed.
[tidb@hy3-tidb-pd-1] ~$ 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.
[tidb@hy3-tidb-4] ~$ 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个节点,所以下面的办法没有用到:

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

[ansible@csdndbtls] ~/csdnhs/tidb$ more h.txt
hy3-tidb-3.csdn.com
hy3-tidb-4.csdn.com
[ansible@csdndbtls] ~/csdnhs/tidb$ more h.txt
hy3-tidb-3.csdn.com
hy3-tidb-4.csdn.com
[ansible@csdndbtls] ~/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
[ansible@csdndbtls] ~/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节点登陆,成功,如下:

[csdnhy@hy1st] ~$ 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>

猜你喜欢

转载自blog.csdn.net/mchdba/article/details/84036200