Elasticsearch集群运维

1、ES滚动重启:

#准备工作:
##提前打开如下信息,有些API是需要观察的各项指标(出现问题则停止重启),其余是配合检查的API:
##查看集群UNASSIGEN shards 原因
curl http://0.0.0.0:9200/_cluster/allocation/explain?pretty

###集群配置
curl http://0.0.0.0:9200/_cluster/settings?pretty

###pending-tasks
curl http://0.0.0.0:9200/_cluster/pending_tasks?pretty

###集群健康
curl http://0.0.0.0:9200/_cluster/health?pretty


#重启client-node组节点
#start
步骤1:关闭其中一个client节点
步骤2:重启节点
步骤3:检查节点是否加入集群
步骤4:重复步骤2-3重启其他节点
#end

#重启mater-node节点
#start
步骤1:明确master节点IP
步骤2:关闭master-node组的一个非master节点
步骤3:重启节点
步骤4:检查节点是否加入集群(确保已经加入集群)
步骤5:重复步骤2-4,重启另外的master-node组的一个非master节点
步骤6:关闭master节点
步骤7:重启master节点
##在master节点选举过程中,集群功能不可用(包括了:索引功能、search功能,API功能堵塞等),集群并不会立即选举出master节点(默认进行选举的时间为3s, 由于网络的问题,往往将master选举的时间延长)
步骤8:检查集群装填,检查节点是否加入集群。
##当master选举出来,集群功能将全部正常。
#end

#重启data-node节点
#start
步骤1:禁用分片分配
curl -X PUT http://0.0.0.0:9200/_cluster/settings?pretty -d '{"transient": {"cluster.routing.allocation.enable": "new_primaries"}}'
##禁用分片分配期间,集群新建索引将无法分配副本分片,允许新建索引主分片的分配
步骤2:执行同步刷新
curl -XPOST "http://0.0.0.0:9200/_flush/synced?pretty"
##对于在此刻不在更新的索引,此操作将通过synced值来确认主副分片是否数据一致(加快了分片加入集群的时间);对于在此刻索引发生变化的分片,此操作对节点加入集群的索引恢复没有作用
步骤3:关闭一个data-node节点
步骤4:重启节点
步骤5:检查节点是否加入集群
步骤6:启用分片分配
curl -X PUT http://0.0.0.0:9200/_cluster/settings?pretty -d '{"transient": {"cluster.routing.allocation.enable": "all"}}'
步骤7:检查集群状态是否为green
##在启用了分片分配后,UNASSIGEN shards会瞬间减少(不会瞬间减少为0,因为在大的ES集群中,每个节点都会有在更新的索引分片);之后会出现一些initializing shards,这部分分片会需要等待一段时间才会减少为0(分片同步过程中)
步骤8:重复步骤3-7,重启其他节点
步骤9:节点全部重启完毕后,检查集群配置,确保没有禁用分片分配
#end
参考资料:

ES官方重启教程 https://www.elastic.co/guide/en/elasticsearch/reference/1.4/cluster-nodes-shutdown.html#_rolling_restart_of_nodes_full_cluster_restart

 

2、ES index常用设置:
ES index的settings:

curl -XPUT http://<domain>:<port>/<index>/settings

{"index":{"refresh_interval":"30s"}}
调整刷新间隔为30s,减少segment的数量

{"index":{"number_of_replicas":0}}
调整副本数为0

 

3、ES cluster常用设置:
ES cluster的settings:

curl -XPUT http://<domain>:<port>/_cluster/settings

{"persistent":{"cluster.routing.allocation.node_concurrent_recoveries": 8}}
允许在节点上并发分片恢复的个数(写和读),只控制“恢复”过程的并发数,对集群“重平衡”和其他情况下的并发数没有影响。

{"persistent":{"cluster.routing.allocation.node_initial_primaries_recoveries": 16}}
控制节点重启后有多少并发数从本地恢复未分配的主分片。

{"persistent":{"indices.recovery.max_bytes_per_sec": "200mb"}}
设置索引恢复时每秒字节数。

{"transient":{"cluster.routing.allocation.cluster_concurrent_rebalance": 4}}
允许在集群上并发分片重平衡的个数,只控制“重平衡”过程的并发数,对集群“恢复”和其他情况下的并发数没有影响。

 

{"transient":{"cluster.routing.allocation.cluster_concurrent_rebalance": 0}}
禁用集群“rebalance”

{"transient":{"cluster.routing.allocation.cluster_concurrent_rebalance": null}}
启用集群“rebalance”


#调整集群恢复并发数为4
curl -XPUT http://<domain>:<port>/_cluster/settings?pretty -d'{"transient":{"cluster.routing.allocation.node_concurrent_recoveries": 4}}'
#取消设置,集群恢复并发数为默认
curl -XPUT http://<domain>:<port>/_cluster/settings?pretty -d'{"transient":{"cluster.routing.allocation.node_concurrent_recoveries": null}}'


#通过IP,排除集群中的某个节点:节点IP:10.100.0.11
curl -XPUT http://<domain>:<port>/_cluster/settings?pretty -d '{"transient":{"cluster.routing.allocation.exclude._ip":"10.100.0.11"}}'
#通过IP,排除集群中的多个节点:节点IP:10.10.0.11,10.100.0.12
curl -XPUT http://<domain>:<port>/_cluster/settings?pretty -d '{"transient":{"cluster.routing.allocation.exclude._ip":"10.100.0.11,10.100.0.12"}}'
#取消节点排除的限制
curl -XPUT http://<domain>:<port>/_cluster/settings?pretty -d '{"transient":{"cluster.routing.allocation.exclude._ip": null}}'


#调整数据节点的低水位值为600gb
curl -XPUT http://<domain>:<port>/_cluster/settings?pretty -d '{"transient":{"cluster.routing.allocation.disk.watermark.low":"600gb"}}'
#调整数据节点的高水位值为300gb
curl -XPUT http://<domain>:<port>/_cluster/settings?pretty -d '{"transient":{"cluster.routing.allocation.disk.watermark.high":"300gb"}}'
#取消用户设置,集群恢复这一项的默认配置
curl -XPUT http://<domain>:<port>/_cluster/settings?pretty -d '{"transient":{"cluster.routing.allocation.disk.watermark.low": null}}'
curl -XPUT http://<domain>:<port>/_cluster/settings?pretty -d '{"transient":{"cluster.routing.allocation.disk.watermark.low": null}}'

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值