首页 文章 精选 留言 我的

精选列表

搜索[运维安全中心(堡垒机)],共10000篇文章
优秀的个人博客,低调大师

TiDB集群运维之扩缩容

2 --> TiDB 集群可以在不中断线上服务的情况下进行扩容和缩容。本文使用 TiUP 扩容缩容集群中的 TiDB、TiKV、PD、TiCDC 或者 TiFlash 节点。 1、扩容前集群状态 [root@bcm01 ~]# tiup cluster display tidbcluster Starting component `cluster`: /root/.tiup/components/cluster/v1.5.2/tiup-cluster display tidbcluster Cluster type: tidb Cluster name: tidbcluster Cluster version: v5.1.0 Deploy user: tidb SSH type: builtin Dashboard URL: http://192.168.120.201:2379/dashboard ID Role Host Ports OS/Arch Status Data Dir Deploy Dir -- ---- ---- ----- ------- ------ -------- ---------- 192.168.120.202:8300 cdc 192.168.120.202 8300 linux/x86_64 Up /u01/tidb/tidb-data/cdc-8300 /u01/tidb/tidb-deploy/cdc-8300 192.168.120.203:8300 cdc 192.168.120.203 8300 linux/x86_64 Up /u01/tidb/tidb-data/cdc-8300 /u01/tidb/tidb-deploy/cdc-8300 192.168.120.203:3000 grafana 192.168.120.203 3000 linux/x86_64 Up - /u01/tidb/tidb-deploy/grafana-3000 192.168.120.201:2379 pd 192.168.120.201 2379/2380 linux/x86_64 Up|L|UI /u01/tidb/tidb-data/pd-2379 /u01/tidb/tidb-deploy/pd-2379 192.168.120.203:2379 pd 192.168.120.203 2379/2380 linux/x86_64 Up /u01/tidb/tidb-data/pd-2379 /u01/tidb/tidb-deploy/pd-2379 192.168.120.202:9090 prometheus 192.168.120.202 9090 linux/x86_64 Up /u01/tidb/tidb-data/prometheus-9090 /u01/tidb/tidb-deploy/prometheus-9090 192.168.120.201:4000 tidb 192.168.120.201 4000/10080 linux/x86_64 Up - /u01/tidb/tidb-deploy/tidb-4000 192.168.120.202:4000 tidb 192.168.120.202 4000/10080 linux/x86_64 Up - /u01/tidb/tidb-deploy/tidb-4000 192.168.120.201:9000 tiflash 192.168.120.201 9000/8123/3930/20170/20292/8234 linux/x86_64 Up /u01/tidb/tidb-data/tiflash-9000 /u01/tidb/tidb-deploy/tiflash-9000 192.168.120.201:20160 tikv 192.168.120.201 20160/20180 linux/x86_64 Up /u01/tidb/tidb-data/tikv-20160 /u01/tidb/tidb-deploy/tikv-20160 192.168.120.202:20161 tikv 192.168.120.202 20161/20181 linux/x86_64 Up /u01/tidb/tidb-data/tikv-20161 /u01/tidb/tidb-deploy/tikv-20161 192.168.120.203:20162 tikv 192.168.120.203 20162/20182 linux/x86_64 Up /u01/tidb/tidb-data/tikv-20162 /u01/tidb/tidb-deploy/tikv-20162 2、创建scale-out.yaml文件 这里新加一个节点204,并在上面部署tidb、cdc以及pd服务,如下: [root@bcm01 ~]# vi scale-out.yaml tidb_servers: - host: 192.168.120.204 ssh_port: 22 port: 4000 status_port: 10080 deploy_dir: /u01/tidb/tidb-deploy/tidb-4000 log_dir: /u01/tidb/tidb-deploy/tidb-4000/log cdc_servers: - host: 192.168.120.204 pd_servers: - host: 192.168.120.204 ssh_port: 22 name: pd-192.168.120.204-2379 client_port: 2379 peer_port: 2380 deploy_dir: /u01/tidb/tidb-deploy/pd-2379 data_dir: /u01/tidb/tidb-data/pd-2379 log_dir: /u01/tidb/tidb-deploy/pd-2379/log 3、执行tiup命令进行扩容 [root@bcm01 ~]# tiup cluster scale-out tidbcluster scale-out.yaml Starting component `cluster`: /root/.tiup/components/cluster/v1.5.2/tiup-cluster scale-out tidbcluster scale-out.yaml Please confirm your topology: Cluster type: tidb Cluster name: tidbcluster Cluster version: v5.1.0 Role Host Ports OS/Arch Directories ---- ---- ----- ------- ----------- pd 192.168.120.204 2379/2380 linux/x86_64 /u01/tidb/tidb-deploy/pd-2379,/u01/tidb/tidb-data/pd-2379 tidb 192.168.120.204 4000/10080 linux/x86_64 /u01/tidb/tidb-deploy/tidb-4000 cdc 192.168.120.204 8300 linux/x86_64 /u01/tidb/tidb-deploy/cdc-8300,/u01/tidb/tidb-data/cdc-8300 Attention: 1. If the topology is not what you expected, check your yaml file. 2. Please confirm there is no port/directory conflicts in same host. Do you want to continue? [y/N]: (default=N) y + [ Serial ] - SSHKeySet: privateKey=/root/.tiup/storage/cluster/clusters/tidbcluster/ssh/id_rsa, publicKey=/root/.tiup/storage/cluster/clusters/tidbcluster/ssh/id_rsa.pub - Download tidb:v5.1.0 (linux/amd64) ... Done + [ Serial ] - RootSSH: user=root, host=192.168.120.204, port=22, key=/root/.ssh/id_rsa + [ Serial ] - EnvInit: user=tidb, host=192.168.120.204 + [ Serial ] - Mkdir: host=192.168.120.204, directories='/u01/tidb/tidb-deploy','/u01/tidb/tidb-data' + [Parallel] - UserSSH: user=tidb, host=192.168.120.203 + [Parallel] - UserSSH: user=tidb, host=192.168.120.201 + [Parallel] - UserSSH: user=tidb, host=192.168.120.202 + [Parallel] - UserSSH: user=tidb, host=192.168.120.202 + [Parallel] - UserSSH: user=tidb, host=192.168.120.203 + [Parallel] - UserSSH: user=tidb, host=192.168.120.203 + [Parallel] - UserSSH: user=tidb, host=192.168.120.201 + [Parallel] - UserSSH: user=tidb, host=192.168.120.201 + [Parallel] - UserSSH: user=tidb, host=192.168.120.202 + [Parallel] - UserSSH: user=tidb, host=192.168.120.202 + [Parallel] - UserSSH: user=tidb, host=192.168.120.201 + [Parallel] - UserSSH: user=tidb, host=192.168.120.203 + [ Serial ] - UserSSH: user=tidb, host=192.168.120.204 + [ Serial ] - UserSSH: user=tidb, host=192.168.120.204 + [ Serial ] - Mkdir: host=192.168.120.204, directories='/u01/tidb/tidb-deploy/cdc-8300','/u01/tidb/tidb-deploy/cdc-8300/bin','/u01/tidb/tidb-deploy/cdc-8300/conf','/u01/tidb/tidb-deploy/cdc-8300/scripts' + [ Serial ] - Mkdir: host=192.168.120.204, directories='/u01/tidb/tidb-deploy/tidb-4000','/u01/tidb/tidb-deploy/tidb-4000/bin','/u01/tidb/tidb-deploy/tidb-4000/conf','/u01/tidb/tidb-deploy/tidb-4000/scripts' + [ Serial ] - UserSSH: user=tidb, host=192.168.120.204 + [ Serial ] - Mkdir: host=192.168.120.204, directories='/u01/tidb/tidb-deploy/pd-2379','/u01/tidb/tidb-deploy/pd-2379/bin','/u01/tidb/tidb-deploy/pd-2379/conf','/u01/tidb/tidb-deploy/pd-2379/scripts' - Copy node_exporter -> 192.168.120.204 ... ⠦ Mkdir: host=192.168.120.204, directories='/u01/tidb/tidb-deploy/monitor-9100','/u01/tidb/tidb-data/monitor-9100','/u01/tidb/tidb-deploy... + [ Serial ] - Mkdir: host=192.168.120.204, directories='' - Copy node_exporter -> 192.168.120.204 ... ⠧ Mkdir: host=192.168.120.204, directories='/u01/tidb/tidb-deploy/monitor-9100','/u01/tidb/tidb-data/monitor-9100','/u01/tidb/tidb-deploy... - Copy blackbox_exporter -> 192.168.120.204 ... ⠇ Mkdir: host=192.168.120.204, directories='/u01/tidb/tidb-deploy/monitor-9100','/u01/tidb/tidb-data/monitor-9100','/u01/tidb/tidb-de... - Copy node_exporter -> 192.168.120.204 ... ⠏ Mkdir: host=192.168.120.204, directories='/u01/tidb/tidb-deploy/monitor-9100','/u01/tidb/tidb-data/monitor-9100','/u01/tidb/tidb-deploy... - Copy node_exporter -> 192.168.120.204 ... ⠋ Mkdir: host=192.168.120.204, directories='/u01/tidb/tidb-deploy/monitor-9100','/u01/tidb/tidb-data/monitor-9100','/u01/tidb/tidb-deploy... - Copy node_exporter -> 192.168.120.204 ... ⠙ Mkdir: host=192.168.120.204, directories='/u01/tidb/tidb-deploy/monitor-9100','/u01/tidb/tidb-data/monitor-9100','/u01/tidb/tidb-deploy... - Copy node_exporter -> 192.168.120.204 ... ⠇ Mkdir: host=192.168.120.204, directories='/u01/tidb/tidb-deploy/monitor-9100','/u01/tidb/tidb-data/monitor-9100','/u01/tidb/tidb-deploy... - Copy node_exporter -> 192.168.120.204 ... ⠏ CopyComponent: component=node_exporter, version=, remote=192.168.120.204:/u01/tidb/tidb-deploy/monitor-9100 os=linux, arch=amd64 - Copy node_exporter -> 192.168.120.204 ... Done + [ Serial ] - ScaleConfig: cluster=tidbcluster, user=tidb, host=192.168.120.204, service=tidb-4000.service, deploy_dir=/u01/tidb/tidb-deploy/tidb-4000, data_dir=[], log_dir=/u01/tidb/tidb-deploy/tidb-4000/log, cache_dir= + [ Serial ] - ScaleConfig: cluster=tidbcluster, user=tidb, host=192.168.120.204, service=pd-2379.service, deploy_dir=/u01/tidb/tidb-deploy/pd-2379, data_dir=[/u01/tidb/tidb-data/pd-2379], log_dir=/u01/tidb/tidb-deploy/pd-2379/log, cache_dir= + [ Serial ] - ScaleConfig: cluster=tidbcluster, user=tidb, host=192.168.120.204, service=cdc-8300.service, deploy_dir=/u01/tidb/tidb-deploy/cdc-8300, data_dir=[/u01/tidb/tidb-data/cdc-8300], log_dir=/u01/tidb/tidb-deploy/cdc-8300/log, cache_dir= script path: /root/.tiup/storage/cluster/clusters/tidbcluster/config-cache/run_pd_192.168.120.204_2379.sh + Check status Enabling component pd Enabling instance 192.168.120.204:2379 Enable instance 192.168.120.204:2379 success Enabling component tidb Enabling instance 192.168.120.204:4000 Enable instance 192.168.120.204:4000 success Enabling component cdc Enabling instance 192.168.120.204:8300 Enable instance 192.168.120.204:8300 success Enabling component node_exporter Enabling instance 192.168.120.204 Enable 192.168.120.204 success Enabling component blackbox_exporter Enabling instance 192.168.120.204 Enable 192.168.120.204 success + [Parallel] - UserSSH: user=tidb, host=192.168.120.204 + [Parallel] - UserSSH: user=tidb, host=192.168.120.204 + [Parallel] - UserSSH: user=tidb, host=192.168.120.204 + [ Serial ] - Save meta + [ Serial ] - StartCluster Starting component pd Starting instance 192.168.120.204:2379 Start instance 192.168.120.204:2379 success Starting component tidb Starting instance 192.168.120.204:4000 Start instance 192.168.120.204:4000 success Starting component cdc Starting instance 192.168.120.204:8300 Start instance 192.168.120.204:8300 success Starting component node_exporter Starting instance 192.168.120.204 Start 192.168.120.204 success Starting component blackbox_exporter Starting instance 192.168.120.204 Start 192.168.120.204 success + [ Serial ] - InitConfig: cluster=tidbcluster, user=tidb, host=192.168.120.203, path=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache/grafana-3000.service, deploy_dir=/u01/tidb/tidb-deploy/grafana-3000, data_dir=[], log_dir=/u01/tidb/tidb-deploy/grafana-3000/log, cache_dir=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache + [ Serial ] - InitConfig: cluster=tidbcluster, user=tidb, host=192.168.120.204, path=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache/pd-2379.service, deploy_dir=/u01/tidb/tidb-deploy/pd-2379, data_dir=[/u01/tidb/tidb-data/pd-2379], log_dir=/u01/tidb/tidb-deploy/pd-2379/log, cache_dir=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache + [ Serial ] - InitConfig: cluster=tidbcluster, user=tidb, host=192.168.120.204, path=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache/tidb-4000.service, deploy_dir=/u01/tidb/tidb-deploy/tidb-4000, data_dir=[], log_dir=/u01/tidb/tidb-deploy/tidb-4000/log, cache_dir=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache + [ Serial ] - InitConfig: cluster=tidbcluster, user=tidb, host=192.168.120.203, path=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache/cdc-8300.service, deploy_dir=/u01/tidb/tidb-deploy/cdc-8300, data_dir=[/u01/tidb/tidb-data/cdc-8300], log_dir=/u01/tidb/tidb-deploy/cdc-8300/log, cache_dir=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache + [ Serial ] - InitConfig: cluster=tidbcluster, user=tidb, host=192.168.120.204, path=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache/cdc-8300.service, deploy_dir=/u01/tidb/tidb-deploy/cdc-8300, data_dir=[/u01/tidb/tidb-data/cdc-8300], log_dir=/u01/tidb/tidb-deploy/cdc-8300/log, cache_dir=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache + [ Serial ] - InitConfig: cluster=tidbcluster, user=tidb, host=192.168.120.201, path=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache/pd-2379.service, deploy_dir=/u01/tidb/tidb-deploy/pd-2379, data_dir=[/u01/tidb/tidb-data/pd-2379], log_dir=/u01/tidb/tidb-deploy/pd-2379/log, cache_dir=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache + [ Serial ] - InitConfig: cluster=tidbcluster, user=tidb, host=192.168.120.201, path=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache/tiflash-9000.service, deploy_dir=/u01/tidb/tidb-deploy/tiflash-9000, data_dir=[/u01/tidb/tidb-data/tiflash-9000], log_dir=/u01/tidb/tidb-deploy/tiflash-9000/log, cache_dir=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache + [ Serial ] - InitConfig: cluster=tidbcluster, user=tidb, host=192.168.120.201, path=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache/tikv-20160.service, deploy_dir=/u01/tidb/tidb-deploy/tikv-20160, data_dir=[/u01/tidb/tidb-data/tikv-20160], log_dir=/u01/tidb/tidb-deploy/tikv-20160/log, cache_dir=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache + [ Serial ] - InitConfig: cluster=tidbcluster, user=tidb, host=192.168.120.202, path=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache/prometheus-9090.service, deploy_dir=/u01/tidb/tidb-deploy/prometheus-9090, data_dir=[/u01/tidb/tidb-data/prometheus-9090], log_dir=/u01/tidb/tidb-deploy/prometheus-9090/log, cache_dir=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache + [ Serial ] - InitConfig: cluster=tidbcluster, user=tidb, host=192.168.120.202, path=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache/cdc-8300.service, deploy_dir=/u01/tidb/tidb-deploy/cdc-8300, data_dir=[/u01/tidb/tidb-data/cdc-8300], log_dir=/u01/tidb/tidb-deploy/cdc-8300/log, cache_dir=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache + [ Serial ] - InitConfig: cluster=tidbcluster, user=tidb, host=192.168.120.203, path=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache/pd-2379.service, deploy_dir=/u01/tidb/tidb-deploy/pd-2379, data_dir=[/u01/tidb/tidb-data/pd-2379], log_dir=/u01/tidb/tidb-deploy/pd-2379/log, cache_dir=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache + [ Serial ] - InitConfig: cluster=tidbcluster, user=tidb, host=192.168.120.201, path=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache/tidb-4000.service, deploy_dir=/u01/tidb/tidb-deploy/tidb-4000, data_dir=[], log_dir=/u01/tidb/tidb-deploy/tidb-4000/log, cache_dir=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache + [ Serial ] - InitConfig: cluster=tidbcluster, user=tidb, host=192.168.120.202, path=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache/tikv-20161.service, deploy_dir=/u01/tidb/tidb-deploy/tikv-20161, data_dir=[/u01/tidb/tidb-data/tikv-20161], log_dir=/u01/tidb/tidb-deploy/tikv-20161/log, cache_dir=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache + [ Serial ] - InitConfig: cluster=tidbcluster, user=tidb, host=192.168.120.203, path=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache/tikv-20162.service, deploy_dir=/u01/tidb/tidb-deploy/tikv-20162, data_dir=[/u01/tidb/tidb-data/tikv-20162], log_dir=/u01/tidb/tidb-deploy/tikv-20162/log, cache_dir=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache + [ Serial ] - InitConfig: cluster=tidbcluster, user=tidb, host=192.168.120.202, path=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache/tidb-4000.service, deploy_dir=/u01/tidb/tidb-deploy/tidb-4000, data_dir=[], log_dir=/u01/tidb/tidb-deploy/tidb-4000/log, cache_dir=/root/.tiup/storage/cluster/clusters/tidbcluster/config-cache + [ Serial ] - SystemCtl: host=192.168.120.202 action=reload prometheus-9090.service + [ Serial ] - UpdateTopology: cluster=tidbcluster Scaled cluster `tidbcluster` out successfully 结果验证如下: [root@bcm01 ~]# tiup cluster display tidbcluster Starting component `cluster`: /root/.tiup/components/cluster/v1.5.2/tiup-cluster display tidbcluster Cluster type: tidb Cluster name: tidbcluster Cluster version: v5.1.0 Deploy user: tidb SSH type: builtin Dashboard URL: http://192.168.120.201:2379/dashboard ID Role Host Ports OS/Arch Status Data Dir Deploy Dir -- ---- ---- ----- ------- ------ -------- ---------- 192.168.120.202:8300 cdc 192.168.120.202 8300 linux/x86_64 Up /u01/tidb/tidb-data/cdc-8300 /u01/tidb/tidb-deploy/cdc-8300 192.168.120.203:8300 cdc 192.168.120.203 8300 linux/x86_64 Up /u01/tidb/tidb-data/cdc-8300 /u01/tidb/tidb-deploy/cdc-8300 192.168.120.204:8300 cdc 192.168.120.204 8300 linux/x86_64 Up /u01/tidb/tidb-data/cdc-8300 /u01/tidb/tidb-deploy/cdc-8300 192.168.120.203:3000 grafana 192.168.120.203 3000 linux/x86_64 Up - /u01/tidb/tidb-deploy/grafana-3000 192.168.120.201:2379 pd 192.168.120.201 2379/2380 linux/x86_64 Up|L|UI /u01/tidb/tidb-data/pd-2379 /u01/tidb/tidb-deploy/pd-2379 192.168.120.203:2379 pd 192.168.120.203 2379/2380 linux/x86_64 Up /u01/tidb/tidb-data/pd-2379 /u01/tidb/tidb-deploy/pd-2379 192.168.120.204:2379 pd 192.168.120.204 2379/2380 linux/x86_64 Up /u01/tidb/tidb-data/pd-2379 /u01/tidb/tidb-deploy/pd-2379 192.168.120.202:9090 prometheus 192.168.120.202 9090 linux/x86_64 Up /u01/tidb/tidb-data/prometheus-9090 /u01/tidb/tidb-deploy/prometheus-9090 192.168.120.201:4000 tidb 192.168.120.201 4000/10080 linux/x86_64 Up - /u01/tidb/tidb-deploy/tidb-4000 192.168.120.202:4000 tidb 192.168.120.202 4000/10080 linux/x86_64 Up - /u01/tidb/tidb-deploy/tidb-4000 192.168.120.204:4000 tidb 192.168.120.204 4000/10080 linux/x86_64 Up - /u01/tidb/tidb-deploy/tidb-4000 192.168.120.201:9000 tiflash 192.168.120.201 9000/8123/3930/20170/20292/8234 linux/x86_64 Up /u01/tidb/tidb-data/tiflash-9000 /u01/tidb/tidb-deploy/tiflash-9000 192.168.120.201:20160 tikv 192.168.120.201 20160/20180 linux/x86_64 Up /u01/tidb/tidb-data/tikv-20160 /u01/tidb/tidb-deploy/tikv-20160 192.168.120.202:20161 tikv 192.168.120.202 20161/20181 linux/x86_64 Up /u01/tidb/tidb-data/tikv-20161 /u01/tidb/tidb-deploy/tikv-20161 192.168.120.203:20162 tikv 192.168.120.203 20162/20182 linux/x86_64 Up /u01/tidb/tidb-data/tikv-20162 /u01/tidb/tidb-deploy/tikv-20162 Total nodes: 15 4、执行tiup命令进行缩容 缩容很简单,这里将204上的所有服务全部删除掉,如下: [root@bcm01 ~]# tiup cluster scale-in tidbcluster --node 192.168.120.204:8300 --node 192.168.120.204:2379 --node 192.168.120.204:4000 Starting component `cluster`: /root/.tiup/components/cluster/v1.5.2/tiup-cluster scale-in tidbcluster --node 192.168.120.204:8300 --node 192.168.120.204:2379 --node 192.168.120.204:4000 This operation will delete the 192.168.120.204:8300,192.168.120.204:2379,192.168.120.204:4000 nodes in `tidbcluster` and all their data. Do you want to continue? [y/N]:(default=N) y Scale-in nodes... + [ Serial ] - SSHKeySet: privateKey=/root/.tiup/storage/cluster/clusters/tidbcluster/ssh/id_rsa, publicKey=/root/.tiup/storage/cluster/clusters/tidbcluster/ssh/id_rsa.pub + [Parallel] - UserSSH: user=tidb, host=192.168.120.201 + [Parallel] - UserSSH: user=tidb, host=192.168.120.203 + [Parallel] - UserSSH: user=tidb, host=192.168.120.202 + [Parallel] - UserSSH: user=tidb, host=192.168.120.201 + [Parallel] - UserSSH: user=tidb, host=192.168.120.203 + [Parallel] - UserSSH: user=tidb, host=192.168.120.203 + [Parallel] - UserSSH: user=tidb, host=192.168.120.201 + [Parallel] - UserSSH: user=tidb, host=192.168.120.204 + [Parallel] - UserSSH: user=tidb, host=192.168.120.204 + [Parallel] - UserSSH: user=tidb, host=192.168.120.202 + [Parallel] - UserSSH: user=tidb, host=192.168.120.202 + [Parallel] - UserSSH: user=tidb, host=192.168.120.201 + [Parallel] - UserSSH: user=tidb, host=192.168.120.202 + [Parallel] - UserSSH: user=tidb, host=192.168.120.203 + [Parallel] - UserSSH: user=tidb, host=192.168.120.204 + [ Serial ] - ClusterOperate: operation=ScaleInOperation, options={Roles:[] Nodes:[192.168.120.204:8300 192.168.120.204:2379 192.168.120.204:4000] Force:false SSHTimeout:5 OptTimeout:120 APITimeout:300 IgnoreConfigCheck:false NativeSSH:false SSHType: CleanupData:false CleanupLog:false RetainDataRoles:[] RetainDataNodes:[] ShowUptime:false JSON:false Operation:StartOperation} Stopping component pd Stopping instance 192.168.120.204 Stop pd 192.168.120.204:2379 success Destroying component pd Destroying instance 192.168.120.204 Destroy 192.168.120.204 success - Destroy pd paths: [/u01/tidb/tidb-data/pd-2379 /u01/tidb/tidb-deploy/pd-2379/log /u01/tidb/tidb-deploy/pd-2379 /etc/systemd/system/pd-2379.service] Stopping component tidb Stopping instance 192.168.120.204 Stop tidb 192.168.120.204:4000 success Destroying component tidb Destroying instance 192.168.120.204 Destroy 192.168.120.204 success - Destroy tidb paths: [/u01/tidb/tidb-deploy/tidb-4000/log /u01/tidb/tidb-deploy/tidb-4000 /etc/systemd/system/tidb-4000.service] Stopping component cdc Stopping instance 192.168.120.204 Stop cdc 192.168.120.204:8300 success Destroying component cdc Destroying instance 192.168.120.204 Destroy 192.168.120.204 success - Destroy cdc paths: [/u01/tidb/tidb-data/cdc-8300 /u01/tidb/tidb-deploy/cdc-8300/log /u01/tidb/tidb-deploy/cdc-8300 /etc/systemd/system/cdc-8300.service] Stopping component node_exporter Stopping instance 192.168.120.204 Stop 192.168.120.204 success Stopping component blackbox_exporter Stopping instance 192.168.120.204 Stop 192.168.120.204 success Destroying monitored 192.168.120.204 Destroying instance 192.168.120.204 Destroy monitored on 192.168.120.204 success Delete public key 192.168.120.204 Delete public key 192.168.120.204 success + [ Serial ] - UpdateMeta: cluster=tidbcluster, deleted=`'192.168.120.204:2379','192.168.120.204:4000','192.168.120.204:8300'` + [ Serial ] - UpdateTopology: cluster=tidbcluster + Refresh instance configs - Regenerate config pd -> 192.168.120.201:2379 ... Done - Regenerate config pd -> 192.168.120.203:2379 ... Done - Regenerate config tikv -> 192.168.120.201:20160 ... Done - Regenerate config tikv -> 192.168.120.202:20161 ... Done - Regenerate config tikv -> 192.168.120.203:20162 ... Done - Regenerate config tidb -> 192.168.120.201:4000 ... Done - Regenerate config tidb -> 192.168.120.202:4000 ... Done - Regenerate config tiflash -> 192.168.120.201:9000 ... Done - Regenerate config cdc -> 192.168.120.202:8300 ... Done - Regenerate config cdc -> 192.168.120.203:8300 ... Done - Regenerate config prometheus -> 192.168.120.202:9090 ... Done - Regenerate config grafana -> 192.168.120.203:3000 ... Done + [ Serial ] - SystemCtl: host=192.168.120.202 action=reload prometheus-9090.service Scaled cluster `tidbcluster` in successfully 5、使用Tiup部署DM集群服务 [root@bcm01 ~]# vi dm.yaml --- global: user: "tidb" ssh_port: 22 deploy_dir: "/u01/tidb/dm/deploy" data_dir: "/u01/tidb/dm/data" master_servers: - host: 192.168.120.201 - host: 192.168.120.202 - host: 192.168.120.203 worker_servers: - host: 192.168.120.201 - host: 192.168.120.202 - host: 192.168.120.203 monitoring_servers: - host: 192.168.120.201 grafana_servers: - host: 192.168.120.201 alertmanager_servers: - host: 192.168.120.201 [root@bcm01 ~]# tiup dm deploy dmcluster v2.0.4 ./dm.yaml --user root [root@bcm01 ~]# tiup dm display dmcluster Starting component `dm`: /root/.tiup/components/dm/v1.5.2/tiup-dm display dmcluster Cluster type: dm Cluster name: dmcluster Cluster version: v2.0.4 Deploy user: tidb SSH type: builtin ID Role Host Ports OS/Arch Status Data Dir Deploy Dir -- ---- ---- ----- ------- ------ -------- ---------- 192.168.120.201:9093 alertmanager 192.168.120.201 9093/9094 linux/x86_64 Up /u01/tidb/dm/data/alertmanager-9093 /u01/tidb/dm/deploy/alertmanager-9093 192.168.120.201:8261 dm-master 192.168.120.201 8261/8291 linux/x86_64 Healthy|L /u01/tidb/dm/data/dm-master-8261 /u01/tidb/dm/deploy/dm-master-8261 192.168.120.202:8261 dm-master 192.168.120.202 8261/8291 linux/x86_64 Healthy /u01/tidb/dm/data/dm-master-8261 /u01/tidb/dm/deploy/dm-master-8261 192.168.120.203:8261 dm-master 192.168.120.203 8261/8291 linux/x86_64 Healthy /u01/tidb/dm/data/dm-master-8261 /u01/tidb/dm/deploy/dm-master-8261 192.168.120.201:8262 dm-worker 192.168.120.201 8262 linux/x86_64 Free /u01/tidb/dm/data/dm-worker-8262 /u01/tidb/dm/deploy/dm-worker-8262 192.168.120.202:8262 dm-worker 192.168.120.202 8262 linux/x86_64 Free /u01/tidb/dm/data/dm-worker-8262 /u01/tidb/dm/deploy/dm-worker-8262 192.168.120.203:8262 dm-worker 192.168.120.203 8262 linux/x86_64 Free /u01/tidb/dm/data/dm-worker-8262 /u01/tidb/dm/deploy/dm-worker-8262 192.168.120.201:3000 grafana 192.168.120.201 3000 linux/x86_64 Up - /u01/tidb/dm/deploy/grafana-3000 192.168.120.201:9090 prometheus 192.168.120.201 9090 linux/x86_64 Up /u01/tidb/dm/data/prometheus-9090 /u01/tidb/dm/deploy/prometheus-9090

优秀的个人博客,低调大师

400+ 节点的 Elasticsearch 集群运维

目录: 数据量 版本 节点配置 索引结构 性能 Meltwater每天要处理数百万量级的帖子数据,因此需要一种能处理该量级数据的存储和检索技术。 从0.11.X 版本开始我们就已经是Elasticsearch的忠实用户了。在经历了一些波折之后,最终我们认为做出了正确的技术选型。 Elasticsearch 用于支持我们的主要媒体监控应用,客户通过该应用可以检索和分析媒体数据,比如新闻文章、(公开的)Facebook帖子、Instagram帖子、博客和微博。我们通过使用一个混合API来收集这些内容,并爬取和稍作加工,使得它们可被 Elasticsearch 检索到。 本文将分享我们所学到的经验、如何调优 Elasticsearch,以及要绕过的一些陷阱。 如果想了解更多关于我们在Elasticsearch方面的点滴,可参考之前博文中的 numad issues 和 batch percolator。 1.数据量 每天都有数量相当庞大的新闻和微博产生;在高峰期需要索引大约300多万社论文章,和近1亿条社交帖子数据。其中社论数据长期保存以供检索(可回溯到2009年),社交帖子数据保存近15个月的。当前的主分片数据使用了大约200 TB的磁盘空间,副本数据大约600 TB。 我们的业务每分钟有3千次请求。所有的请求通过一个叫做 “search-service” 的服务,该服务会依次完成所有与 Elasticsearch 集群的交互。大部分检索规则比较复杂,包括在面板和新闻流中。比如,一个客户可能对 Tesla 和 Elon Musk 感兴趣,但希望排除所有关于 SpaceX 或 PayPal 的信息。用户可以使用一种与 Lucene 查询语法类似的灵活语法,如下: Tesla AND "Elon Musk" NOT (SpaceX OR PayPal) 我们最长的此类查询有60多页。重点是:除了每分钟3千次请求以外,没有一个查询是像在 Google 里查询 “Barack Obama” 这么简单的;这简直就是可怕的野兽,但ES节点必须努力找出一个匹配的文档集。 2.版本 我们运行的是一个基于 Elasticsearch 1.7.6 的定制版本。该版本与1.7.6 主干版本的唯一区别是,我们向后移植(backport)了 roaring bitsets/bitmaps 作为缓存。该功能是从 Lucene 5 移植到 Lucene 4 的,对应移植到了 ES 1.X 版本。Elasticsearch 1.X 中使用默认的 bitset 作为缓存,对于稀疏结果来说开销非常大,不过在 Elasticsearch 2.X 中已经做了优化。 为何不使用较新版本的 Elasticsearch 呢?主要原因是升级困难。在主版本间滚动升级只适用于从ES 5到6(从ES 2到5应该也支持滚动升级,但没有试过)。因此,我们只能通过重启整个集群来升级。宕机对我们来说几乎不可接受,但或许可以应对一次重启所带来的大约30-60分钟宕机时间;而真正令人担心的,是一旦发生故障并没有真正的回滚过程。 截止目前我们选择了不升级集群。当然我们希望可以升级,但目前有更为紧迫的任务。实际上该如何实施升级尚未有定论,很可能选择创建另一个新的集群,而不是升级现有的。 3.节点配置 我们自2017年6月开始在AWS上运行主集群,使用i3.2xlarge实例作为数据节点。之前我们在COLO(Co-located Data Center)里运行集群,但后续迁移到了AWS云,以便在新机器宕机时能赢得时间,使得我们在扩容和缩容时更加弹性。 我们在不同的可用区运行3个候选 master 节点,并设置 discovery.zen.minimum_master_nodes 为2。这是避免脑裂问题 split-brain problem 非常通用的策略。 我们的数据集在存储方面,要求80%容量和3个以上的副本,这使得我们运行了430个数据节点。起初打算使用不同层级的数据,在较慢的磁盘上存储较旧的数据,但是由于我们只有相关的较低量级旧于15个月的数据(只有编辑数据,因为我们丢弃了旧的社交数据),然而这并未奏效。每个月的硬件开销远大于运行在COLO中,但是云服务支持扩容集群到2倍,而几乎不用花费多少时间。 你可能会问,为何选择自己管理维护ES集群。其实我们考虑过托管方案,但最后还是选择自己安装,理由是: AWS Elasticsearch Service 暴露给用户的可控性太差了,Elastic Cloud 的成本比直接在EC2上运行集群要高2-3倍。 为了在某个可用区宕机时保护我们自身,节点分散于eu-west-1的所有3个可用区。我们使用 AWS plugin 来完成该项配置。它提供了一个叫做aws_availability_zone 的节点属性,我们把 cluster.routing.allocation.awareness.attributes 设置为 aws_availability_zone。这保证了ES的副本尽可能地存储在不同的可用区,而查询尽可能被路由到相同可用区的节点。 这些实例运行的是 Amazon Linux,临时挂载为 ext4,有约64GB的内存。我们分配了26GB用于ES节点的堆内存,剩下的用于磁盘缓存。为何是26GB?因为 JVM 是在一个黑魔法之上构建的 。 我们同时使用 Terraform 自动扩容组来提供实例,并使用 Puppet 完成一切安装配置。 4.索引结构 因为我们的数据和查询都是基于时间序列的,所以使用了 time-based indexing ,类似于ELK (elasticsearch, logstash, kibana) stack。同时也让不同类型的数据保存在不同的索引库中,以便诸如社论文档和社交文档类数据最终位于不同的每日索引库中。这样可以在需要的时候只丢弃社交索引,并增加一些查询优化。每个日索引运行在两个分片中的一个。 该项设置产生了大量的分片(接近40k)。有了这么多的分片和节点,集群操作有时变得更特殊。比如,删除索引似乎成为集群master的能力瓶颈,它需要把集群状态信息推送给所有节点。我们的集群状态数据约100 MB,但通过TCP压缩可减少到3 MB(可以通过 curl localhost:9200/_cluster/state/_all 查看你自己集群的状态数据)。Master 节点仍然需要在每次变更时推送1.3 GB数据(430 节点 x 3 MB 状态大小)。除了这1.3 GB数据外,还有约860 MB必须在可用区(比如 最基本的通过公共互联网)之间传输。这会比较耗时,尤其是在删除数百个索引时。我们希望新版本的 Elasticsearch 能优化这一点,首先从 ES 2.0支持仅发送集群状态的差分数据 这一特性开始。 5.性能 如前所述,我们的ES集群为了满足客户的检索需求,需要处理一些非常复杂的查询。 为应对查询负载,过去几年我们在性能方面做了大量的工作。我们必须尝试公平分享ES集群的性能测试,从下列引文就可以看出。 不幸的是,当集群宕机的时候,不到三分之一的查询能成功完成。我们相信测试本身导致了集群宕机。—— 摘录自使用真实查询在新ES集群平台上的第一次性能测试 为了控制查询执行过程,我们开发了一个插件,实现了一系列自定义查询类型。通过使用这些查询类型来提供Elasticsearch官方版本不支持的功能和性能优化。比如,我们实现了 phrases 中的 wildcard 查询,支持在 SpanNear 查询中执行;另一个优化是支持“*”代替 match-all-query ;还有其他一系列特性。 Elasticsearch 和 Lucene 的性能高度依赖于具体的查询和数据,没有银弹。即便如此,仍可给出一些从基础到进阶的参考: 限制你的检索范围,仅涉及相关数据。比如,对于每日索引库,只按相关日期范围检索。对于检索范围中间的索引,避免使用范围查询/过滤器。 使用wildcards时忽略前缀wildcards - 除非你能对term建立倒排索引。双端wildcards难以优化。 关注资源消耗的相关迹象 数据节点的CPU占用持续飙高吗?IQ等待走高吗?看看GC统计。这些可以从profilers工具或者通过 JMX 代理获得。如果 ParNewGC 消耗了超过15%的时间,去检查下内存日志。如果有任何的 SerialGC 停顿,你可能真的遇到问题了。不太了解这些内容? 没关系,这个系列博文很好地介绍了JVM性能 。记住,ES和G1垃圾回收器一起并非最佳 。 如果遇到垃圾回收问题,请不要尝试调整GC设置。这一点经常发生,因为默认设置已经很合理了。相反,应该聚焦在减少内存分配上。具体怎么做?参考下文。 如果遇到内存问题,但没有时间解决,可考虑查询Azul Zing。这是一个很贵的产品,但仅仅使用它们的JVM就可以提升2倍的吞吐量。不过最终我们并没有使用它,因为我们无法证明物有所值。 考虑使用缓存,包括 Elasticsearch 外缓存和 Lucene 级别的缓存。在 Elasticsearch 1.X 中可以通过使用 filter 来控制缓存。之后的版本中看起来更难一些,但貌似可以实现自己用于缓存的查询类型。我们在未来升级到2.X的时候可能会做类似的工作。 查看是否有热点数据(比如某个节点承担了所有的负载)。可以尝试均衡负载,使用分片分配过滤策略 shard allocation filtering ,或者尝试通过集群重新路由 cluster rerouting 来自行迁移分片。我们已经使用线性优化自动重新路由,但使用简单的自动化策略也大有帮助。 搭建测试环境(我更喜欢笔记本)可从线上环境加载一部分代表性的数据(建议至少有一个分片)。使用线上的查询回放加压(较难)。使用本地设置来测试请求的资源消耗。 综合以上各点,在 Elasticsearch 进程上启用一个 profiler。这是本列表中最重要的一条。 我们同时通过Java Mission Control 和 VisualVM 使用飞行记录器。在性能问题上尝试投机(包括付费顾问/技术支持)的人是在浪费他们(以及你自己)的时间。排查下 JVM 哪部分消耗了时间和内存,然后探索下 Elasticsearch/Lucene 源代码,检查是哪部分代码在执行或者分配内存。 一旦搞清楚是请求的哪一部分导致了响应变慢,你就可以通过尝试修改请求来优化(比如,修改term聚合的执行提示 ,或者切换查询类型)。修改查询类型或者查询顺序,可以有较大影响。如果不凑效,还可以尝试优化 ES/Lucene 代码。这看起来太夸张,却可以为我们降低3到4倍的CPU消耗和4到8倍的内存使用。某些修改很细微(比如 indices query ),但其他人可能要求我们完全重写查询执行。最终的代码严重依赖于我们的查询模式,所以可能适合也可能不适合他人使用。因此目前为止我们并没有开源这部分代码。不过这可能是下一篇博文的好素材。 图表说明:响应时间。有/没有 重写 Lucene 查询执行。同时也表明不再有节点每天多次发生内存不足。 顺便说明下,因为我知道会面临一个问题:从上一次性能测试我们知道通过升级到 ES 2.X 能小幅提升性能,但是并不能改变什么。话虽如此,但如果你已经从 ES 1.X 集群迁移到了 ES 2.X,我们很乐意听取关于你如何完成迁移的实践经验。 如果读到了这里,说明你对 Elasticsearch 是真爱啊(或者至少你是真的需要它)。我们很乐意学习你的经验,以及任何可以分享的内容。欢迎在评论区分享你的反馈和问题。 英文原文链接:http://underthehood.meltwater.com/blog/2018/02/06/running-a-400+-node-es-cluster/ 本文首发于InfoQ https://www.infoq.cn/article/1sm0Mq5LyY_021HGuXer作者:Anton Hägerstrand翻译:杨振涛

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册