tidb 扩容和缩容

张映 发表于 2021-09-14

分类目录: tidb

标签:, , ,

tidb的官方给出了单台机器的硬盘上限最多2T,量大的很快就会满,扩容就很重要。

1,扩容前的准备工作

参考:tidb 集群安装配置

因没有给tidb免密获取root权限导致以下错误

Error: Failed to initialize TiDB environment on remote host '10.0.54.6' (task.env_init.failed)
caused by: Failed to create '~/.ssh' directory for user 'tidb'

2,以扩容tikv为例

  1. $ cat add-tikv.yaml  
  2. tikv_servers:  
  3.   - host: 10.0.54.6  

3,查看集群信息

  1. # tiup cluster list   //查看集群列表  
  2. # tiup cluster display test_tidb //查看某一集群详细信息  

4,扩容tikv

  1. [tidb@testjian conf]$ tiup cluster scale-out test_tidb add-tikv.yaml  
  2. Found cluster newer version:  
  3.   
  4.     The latest version:         v1.5.6  
  5.     Local installed version:    v1.5.3  
  6.     Update current component:   tiup update cluster  
  7.     Update all components:      tiup update --all  
  8.   
  9. Starting component `cluster`: /home/tidb/.tiup/components/cluster/v1.5.3/tiup-cluster scale-out test_tidb add-tikv.yaml  
  10. Please confirm your topology:  
  11. Cluster type:    tidb  
  12. Cluster name:    test_tidb  
  13. Cluster version: v4.0.8  
  14. Role  Host       Ports        OS/Arch       Directories  
  15. ----  ----       -----        -------       -----------  
  16. tikv  10.0.54.6  20160/20180  linux/x86_64  /home/tidb/tidb-deploy/tikv-20160,/home/tidb/tidb-data/tikv-20160  
  17. Attention:  
  18.     1. If the topology is not what you expected, check your yaml file.  
  19.     2. Please confirm there is no port/directory conflicts in same host.  
  20. Do you want to continue? [y/N]: (default=N) y  
  21. + [ Serial ] - SSHKeySet: privateKey=/home/tidb/.tiup/storage/cluster/clusters/test_tidb/ssh/id_rsa, publicKey=/home/tidb/.tiup/storage/cluster/clusters/test_tidb/ssh/id_rsa.pub  
  22. ==================================省略==============================  
  23. + [ Serial ] - SystemCtl: host=10.0.10.23 action=reload prometheus-9090.service  
  24. + [ Serial ] - UpdateTopology: cluster=test_tidb  
  25. Scaled cluster `test_tidb` out successfully  
  26.   
  27. [tidb@testjian conf]$ tiup cluster display test_tidb  //查看是否添加成功  

新增的tikv,不会立马进行数据平衡,但是数据的增加会更加倾向于新增的机器。

扩容tikv

扩容tikv

5,缩容

  1. [tidb@testjian conf]$ tiup cluster scale-in test_tidb --node 10.0.54.17:4000 --force  
  2. Found cluster newer version:  
  3.   
  4.     The latest version:         v1.5.6  
  5.     Local installed version:    v1.5.3  
  6.     Update current component:   tiup update cluster  
  7.     Update all components:      tiup update --all  
  8.   
  9. Starting component `cluster`: /home/tidb/.tiup/components/cluster/v1.5.3/tiup-cluster scale-in test_tidb --node 10.0.54.17:4000 --force  
  10. Forcing scale in is unsafe and may result in data loss for stateful components.  
  11. The process is irreversible and could NOT be cancelled.  
  12. Only use `--force` when some of the servers are already permanently offline.  
  13. Are you sure to continue? [y/N]:(default=N) y  
  14. This operation will delete the 10.0.54.17:4000 nodes in `test_tidb` and all their data.  
  15. Do you want to continue? [y/N]:(default=N) y  
  16. Scale-in nodes...  
  17. + [ Serial ] - SSHKeySet: privateKey=/home/tidb/.tiup/storage/cluster/clusters/test_tidb/ssh/id_rsa, publicKey=/home/tidb/.tiup/storage/cluster/clusters/test_tidb/ssh/id_rsa.pub  
  18. + [Parallel] - UserSSH: user=tidb, host=10.0.10.23  
  19. + [Parallel] - UserSSH: user=tidb, host=10.0.55.16  
  20. + [Parallel] - UserSSH: user=tidb, host=10.0.55.16  
  21. + [Parallel] - UserSSH: user=tidb, host=10.0.10.23  
  22. + [Parallel] - UserSSH: user=tidb, host=10.0.55.17  
  23.   
  24. ==================================省略==============================  

--force慎用,特别是tikv,tiflash。



转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/tidb/2534.html