[关闭]
@zhangyy 2021-03-16T17:17:49.000000Z 字数 8025 阅读 252

ElasticSearch的水平扩容与缩容

ElasticSearch系列



一: ElasticSearch扩容

1.1 es 的扩容步骤

  1. 垂直扩容:
  2. 纵向扩容,买更好的服务器,增加CPU,内存,在一台机器上面增加节点。1+1=2
  3. 水平扩容:
  4. 横向扩容,买更多的服务器,一台机器一个节点 9:9 11:11
  5. 在线扩容
  6. 1. 备份 数据
  7. 2. 增加两台机器。
  8. 192.168.100.50 192.168.100.51 一般扩容扩数据节点。
  9. 3. 准备操作系统
  10. 4. ssh 无秘登录
  11. 5. 安装jdk 安装ES 软件
  12. 6. 配置ES 参数
  13. 7. 检查集群状态
  14. curl -XGET 'http://192.168.100.44:9200/_cat/health?pretty' -H 'Content-Type:application/json'
  15. 保证集群是green 状态

image_1euv4q8hl15hr1t4r1r2r1umi1edf9.png-78.7kB


  1. 8.停止外部数据写入
  2. 9. 停止分片重新分布
  3. 10. 启动新扩的节点。
  4. 11. 检查节点状态
  5. 12. 开启分片重新分布

二:es 的水平扩容

2.1 增加节点系统初始化:

  1. cat /etc/hosts
  2. ----
  3. 192.168.100.41 rhel01.flyfish.cn
  4. 192.168.100.42 rhel02.flyfish.cn
  5. 192.168.100.43 rhel03.flyfish.cn
  6. 192.168.100.44 rhel04.flyfish.cn
  7. 192.168.100.45 rhel05.flyfish.cn
  8. 192.168.100.46 rhel06.flyfish.cn
  9. 192.168.100.47 rhel07.flyfish.cn
  10. 192.168.100.48 rhel08.flyfish.cn
  11. 192.168.100.49 rhel09.flyfish.cn
  12. 192.168.100.50 rhel10.flyfish.cn
  13. 192.168.100.51 rhel11.flyfish.cn
  14. ----
  15. rhel10.flyfish.cn / rhel11.flyfish.cn 做为扩容节点

  1. 全部系统配置:
  2. 系统语言:
  3. echo "export LANG=en_US.UTF8" >> ~/.bash_profile
  4. cat ~/.bash_profile
  5. ---
  6. 分区:
  7. pvcreate /dev/sdb
  8. vgcreate esdatavg /dev/sdb
  9. lvcreate -n esdatalv -L 100000M esdatavg
  10. mkfs.xfs /dev/esdatavg/esdatalv
  11. ---
  12. vi /etc/fstab
  13. ---
  14. /dev/esdatavg/esdatalv /esdb xfs defaults 0 0
  15. ---
  16. mkdir /esdb
  17. mount /esdb

image_1euv5it1ro3t1u5a1dg41m4emc59.png-57.8kB

  1. mkdir -p /esdb/soft
  2. groupadd -g 60001 esadmin
  3. useradd -u 61001 -g esadmin esadmin
  4. chown -R esadmin:esadmin /esdb
  5. chmod -R 775 /esdb
  6. echo "esadmin" | passwd --stdin esadmin
  7. systemctl set-default multi-user.target
  8. chown esadmin:esadmin -R /esdb
  9. cat >> /etc/security/limits.conf << EOF
  10. root soft nofile 1048576
  11. root hard nofile 1048576
  12. esadmin soft nproc 1048576
  13. esadmin hard nproc 1048576
  14. esadmin soft nofile 1048576
  15. esadmin hard nofile 1048576
  16. esadmin soft stack 10240
  17. esadmin hard stack 32768
  18. esadmin hard memlock unlimited
  19. esadmin soft memlock unlimited
  20. EOF
  21. ---
  22. ---
  23. cat >> /etc/sysctl.conf << EOF
  24. fs.aio-max-nr = 1048576
  25. fs.file-max = 6815744
  26. net.ipv4.ip_local_port_range = 1024 65535
  27. net.ipv4.tcp_mem = 786432 2097152 3145728
  28. net.ipv4.tcp_rmem = 4096 4096 16777216
  29. net.ipv4.tcp_wmem = 4096 4096 16777216
  30. net.ipv4.tcp_tw_reuse = 1
  31. net.ipv4.tcp_tw_recycle = 1
  32. vm.swappiness=1
  33. vm.min_free_kbytes=204800
  34. vm.max_map_count=2048000
  35. kernel.pid_max=819200
  36. vm.zone_reclaim_mode=0
  37. #vm.nr_hugepages = 0
  38. EOF
  39. sysctl -p

  1. ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  2. hwclock
  3. echo "SELINUX=disabled" > /etc/selinux/config
  4. echo "#SELINUXTYPE=targeted " >> /etc/selinux/config
  5. cat /etc/selinux/config
  6. setenforce 0
  7. systemctl stop firewalld.service
  8. systemctl disable firewalld.service
  9. cat >> /home/esadmin/.vimrc << EOF
  10. map <F10>:set paste<CR>
  11. map <F11>:set nopaste<CR>
  12. EOF
  13. shutdown -r now

image_1euv5osjpvjk5lt15g0ui1tpim.png-148.4kB

image_1euv5q1g8hk81t08pa419691o1p13.png-200.3kB

  1. 做所有主机的无密钥登录:
  2. rm -rf /home/esadmin/.ssh/*
  3. ./fgssh -user esadmin -hosts "rhel01.flyfish.cn rhel02.flyfish.cn rhel03.flyfish.cn rhel04.flyfish.cn rhel05.flyfish.cn rhel06.flyfish.cn rhel07.flyfish.cn rhel08.flyfish.cnrhel09.flyfish.cn rhel10.flyfish.cn rhel11.flyfish.cn" -advanced -exverify -confirm
  4. chmod 600 /home/esadmin/.ssh/config

image_1euv677saukt1qjo1ttohvu1rdo1g.png-56.9kB

  1. 配置jdk
  2. su - esadmin
  3. cd /esdb/
  4. scp -r /esdb/jdk-14.0.2 esadmin@rhel10.flyfish.cn:/esdb/
  5. scp -r /esdb/jdk-14.0.2 esadmin@rhel11.flyfish.cn:/esdb/

  1. su - esadmin
  2. cat >> ~/.bash_profile << EOF
  3. export JAVA_HOME=/esdb/jdk-14.0.2
  4. export PATH=/esdb/jdk-14.0.2/bin:$PATH
  5. export LANG=en_US.UTF8
  6. EOF
  7. source ~/.bash_profile
  8. java -version

image_1euv6gsds1f8ddi16ju7896iv1t.png-76.9kB

  1. 同步esdb 安装目录
  2. scp -r /esdb/ esadmin@rhel10.flyfish.cn:/
  3. scp -r /esdb/ esadmin@rhel11.flyfish.cn:/
  4. rm -rf /esdb/esdata/esdata9200/*
  5. rm -rf /esdb/eslog/eslog9200/*

  1. 修改esyaml
  2. rhel10.flyfish.cn:
  3. vim /esdb/esapp/esapp9200/config/elasticsearch.yml
  4. ----
  5. cluster.name: flyfishescluster1
  6. node.name: 192.168.100.50
  7. network.host: 192.168.100.50
  8. http.port: 9200
  9. transport.tcp.port: 9300
  10. path.data: /esdb/esdata/esdata9200
  11. path.logs: /esdb/eslog/eslog9200
  12. node.master: false
  13. node.data: true
  14. cluster.remote.connect: false
  15. http.cors.enabled: true
  16. http.cors.allow-origin: "*"
  17. bootstrap.memory_lock: true
  18. bootstrap.system_call_filter: false
  19. cluster.initial_master_nodes: ["192.168.100.44:9300","192.168.100.45:9300","192.168.100.46:9300"]
  20. discovery.seed_hosts: ["192.168.100.44:9300", "192.168.100.45:9300", "192.168.100.46:9300"]
  21. discovery.zen.fd.ping_timeout: 60s
  22. discovery.zen.fd.ping_retries: 5
  23. ----
  24. rhel11.flyfish.cn:
  25. vim /esdb/esapp/esapp9200/config/elasticsearch.yml
  26. ----
  27. cluster.name: flyfishescluster1
  28. node.name: 192.168.100.51
  29. network.host: 192.168.100.51
  30. http.port: 9200
  31. transport.tcp.port: 9300
  32. path.data: /esdb/esdata/esdata9200
  33. path.logs: /esdb/eslog/eslog9200
  34. node.master: false
  35. node.data: true
  36. cluster.remote.connect: false
  37. http.cors.enabled: true
  38. http.cors.allow-origin: "*"
  39. bootstrap.memory_lock: true
  40. bootstrap.system_call_filter: false
  41. cluster.initial_master_nodes: ["192.168.100.44:9300","192.168.100.45:9300","192.168.100.46:9300"]
  42. discovery.seed_hosts: ["192.168.100.44:9300", "192.168.100.45:9300", "192.168.100.46:9300"]
  43. discovery.zen.fd.ping_timeout: 60s
  44. discovery.zen.fd.ping_retries: 5
  45. ----

  1. curl -XGET 'http://192.168.100.41:9200/_cat/health?pretty' -H 'Content-Type:
  2. application/json'

image_1euv78ote168fne9r3q4hp122l2a.png-39.2kB

  1. curl 'http://192.168.100.41:9200/_cat/shards?v'
  2. curl '192.168.100.44:9200/_cat/nodes?v'

image_1euv79rr5duj1e4mouf1btpub02n.png-109.6kB

image_1euv7c6n51nc9911fp19jt1r2b9.png-86.2kB


  1. curl -XPUT http://192.168.100.44:9200/_cluster/settings -H 'Content-Type:application/json' -d'{"transient":{"cluster.routing.allocation.enable":"none"}}'

image_1euv7oerb11kp1tsj1vku9je1nah9.png-82.4kB

  1. 启动增加的节点:
  2. rhel10.flyfish.cn:
  3. /esdb/esapp/esapp9200/bin/elasticsearch
  4. rhel11.flyfish.cn:
  5. /esdb/esapp/esapp9200/bin/elasticsearch

image_1euv7u208c9fsrnuoo150kejkm.png-213.4kB

  1. 后台启动:
  2. /esdb/esapp/esapp9200/bin/elasticsearch -d >/dev/null 2>&1 &

image_1euv82sj41runc6ojmc1c8n1ffs9.png-77.6kB

image_1euv83dqtgq418kk1b47e5s1u1um.png-63.8kB


  1. 查看节点状态:
  2. curl '192.168.100.44:9200/_cat/nodes?v'

image_1euv8r3d21856ugeshm1u671daq9.png-98.2kB


  1. 打开节点的路由平衡数据:
  2. curl -XPUT http://192.168.100.44:9200/_cluster/settings -H 'Content-Type:application/json' -d'{"transient":{"cluster.routing.allocation.enable":"all"}}'

image_1euv9s4md17u1b5p5ab1ltu1svcp.png-75.8kB

  1. 查看集群分片
  2. curl 'http://192.168.100.41:9200/_cat/shards?v'

image_1euva1bm11bj3vfelcfntjmp16.png-104.6kB

  1. 集群状态:
  2. curl -XGET 'http://192.168.100.41:9200/_cat/health?pretty' -H 'Content-Type:application/json'

image_1euva6dan1ut21jt8rra55djnt20.png-42kB

三: ES 集群的缩容

3.1 ES 的的缩容步骤

  1. 1. 监测集群状态
  2. curl -XGET 'http://192.168.100.41:9200/_cat/health?pretty' -H 'Content-Type:application/json'
  3. curl 'http://192.168.100.41:9200/_cat/shards?v'
  4. curl '192.168.100.44:9200/_cat/nodes?v'
  5. 保证集群是green 状态

  1. 2. 暂停数据写入
  2. 3. 有条件就备份数据
  3. 4. 禁用集群分片平衡
  4. curl -XPUT http://192.168.100.44:9200/_cluster/settings -H 'Content-Type:application/json' -d'{"transient":{"cluster.routing.allocation.enable":"none"}}'
  5. 5. 分片数据同步:
  6. curl http://192.168.100.41:9200/_flush/synced
  7. 6. 收缩节点
  8. 一个一个操作,不能同时关闭两个节点
  9. 先关192.168.100.50
  10. 7. 开启集群分片平衡
  11. curl -XPUT http://192.168.100.44:9200/_cluster/settings -H 'Content-Type:application/json' -d'{"transient":{"cluster.routing.allocation.enable":"all"}}'
  12. 8 查看集群状态:
  13. curl -XGET 'http://192.168.100.41:9200/_cat/health?pretty' -H 'Content-Type:application/json'
  14. curl 'http://192.168.100.41:9200/_cat/shards?v'
  15. curl '192.168.100.44:9200/_cat/nodes?v'
  16. 保证集群是green 状态
  17. 9.继续收缩其他节点。

  1. 第二种:排除集群节点方法:
  2. PUT _cluster/settings
  3. {
  4. "transient" : {
  5. "cluster.routing.allocation.exclude._ip" : "192.168.100.50"
  6. }
  7. }

  1. 下降:rhel10.flyfish.cn
  2. 先检查集群状态:
  3. curl -XGET 'http://192.168.100.41:9200/_cat/health?pretty' -H 'Content-Type:application/json'
  4. curl 'http://192.168.100.41:9200/_cat/shards?v'
  5. curl '192.168.100.44:9200/_cat/nodes?v'

image_1euvc7dqo1cfa1sp6ldkjhsoua9.png-181.5kB

  1. 禁用数据平衡
  2. curl -XPUT http://192.168.100.44:9200/_cluster/settings -H 'Content-Type:application/json' -d'{"transient":{"cluster.routing.allocation.enable":"none"}}'

image_1euvcamishms19i8dje19821i23m.png-72kB

  1. 停掉 rhel10.flyfish.cn 上面的 es
  2. kill -9 2993

  1. 查看集群状态:

image_1euvclut7n7j19pd10qm87hu0u13.png-36.5kB

image_1euvcmmm569kh2kmo66ee10se1g.png-106.7kB


  1. 重新平衡:

image_1euvcs9uk111ode81s2fc9b94n1t.png-68.6kB

  1. 查看集群状态

image_1euvctpvovs91fqt1iob1euc1tvh2a.png-180.6kB

image_1euvcvdes17uc1qk515c9feh1nnh2n.png-99.4kB

四: ES 的升级

  1. ES7+ 升级很方便
  2. 下载一个新版本
  3. copy 配置文件
  4. 启动
  5. 1.做好备份,
  6. 2. 下载新的版本安装
  7. 3. 集群停止分片平衡
  8. 4. copy 配置文件启动
  9. 5. 启动ES 分片平衡

  1. 停止数据平衡:
  2. curl -XPUT http://192.168.100.41:9200/_cluster/settings -H 'Content-Type:application/json' -d'{"transient":{"cluster.routing.allocation.enable":"none"}}'

image_1f0t2opva1jua1re41ur14c5aif9.png-66.7kB

  1. 停掉集群:
  2. ./es-stop.sh

image_1f0t2t2hi169s169cibuci8np8m.png-130.1kB


  1. cd /esdb/soft/
  2. tar -zxvf elasticsearch-7.9.1-linux-x86_64.tar.gz
  3. ---

  1. 备份原有所有主机:
  2. ---
  3. cd /esdb/esapp
  4. mv esapp9200/ esapp9200-7.9.0
  5. ---

image_1f0t36ip011ammtd7bjcl2n1433.png-72.5kB

image_1f0t38fck2klsdalfl34bvb03g.png-44.3kB

image_1f0t38tk4pptmor1qjebm1our3t.png-50.9kB


  1. cd /esdb/esapp/
  2. mkdir esapp9200

image_1f0t3dpua4s71h761il0jap1ifs4a.png-26.9kB

image_1f0t3ep3bmao15kjh1cv2k1fa64n.png-28kB

image_1f0t3f9hdjpp2srt361qo4uhb54.png-34.6kB

  1. cd /esdb/soft/elasticsearch-7.9.1
  2. cp -r * /esdb/esapp/esapp9200/
  3. scp -r /esdb/esapp/esapp9200/ esadmin@rhel02.flyfish.cn:/esdb/esapp/
  4. scp -r /esdb/esapp/esapp9200/ esadmin@rhel03.flyfish.cn:/esdb/esapp/

image_1f0t3nfrlc8lqksso10l8cvt61.png-83.7kB

  1. 复制每台机器的配置文件覆盖
  2. cd /esdb/esapp/esapp9200-7.9.0/config
  3. cp -p jvm.options ../../esapp9200/config/
  4. cp -p elasticsearch.yml ../../esapp9200/config/

image_1f0t48a12eks4a8b8g1gd0hcim.png-203kB

image_1f0t4795tri0je61sum19e71q4m9.png-168.4kB

image_1f0t4ardcp4516qih731li5kp1g.png-180.3kB


  1. 所有机器更改变量:
  2. vi /esdb/esapp/esapp9200/bin/elasticsearch-env
  3. ---
  4. export JAVA_HOME=/esdb/jdk-14.0.2
  5. export PATH=$JAVA_HOME/bin:$PATH
  6. ---

image_1f0t49eh45r117ia135712ts16bp13.png-32.7kB


  1. 启动es:
  2. /esdb/esapp/esapp9200/bin/elasticsearch

  1. 查看es的装态:
  2. curl '192.168.100.41:9200/_cat/nodes?v'
  3. curl 'http://192.168.100.41:9200/_cat/shards?v'
  4. 打开路由平衡:
  5. curl -XPUT http://192.168.100.41:9200/_cluster/settings -H 'Content-Type:application/json' -d'{"transient":{"cluster.routing.allocation.enable":"all"}}'

image_1f0t4p6q71hv7na13ndkbtv1u9.png-209.6kB

  1. 查看数据:
  2. curl -XPOST 'http://192.168.100.41:9200/itpuxdb/_search?pretty' -H 'Content-Type:application/json'

image_1f0t51mkc1s7o1cpe1l0eqdslsdm.png-109.6kB

  1. 集群状态:
  2. curl http://192.168.100.41:9200/_cat/health?pretty -H 'Content-Type: application/json'

image_1f0t50nr91jrolqp5qi12a316d29.png-39kB

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注