elasticsearch red status fix 红色状态修复,unassigned shards问题

1.问题描述:

spring cloud项目有用到elasticsearch,启动时进行健康校验,发现es一直是down的,导致在eureka显示也是down

问题定位:查看actuator源码发现,如果es状态为红色,健康状态就返回down,所以解决es状态为红就可以

查看es,发现主节点某个分片出现问题,变成Unassigned,例如下图dfy_index在node-1中的分片2会显示在unassigned那一排,集群状态为红色

解决方案:节点中分片出现分配问题可以使用allocate命令;文档: https://www.elastic.co/guide/en/elasticsearch/reference/2.3/cluster-reroute.html  

{"commands":[{"allocate":{"index":"dfy_index","shard":2,"node":"node-1","allow_primary":true}}]}

2.上图未分配分片数跟主节点分片数数量一致,es状态会显示为yellow,原因是:

索引的“number_of_replicas (备份数)”为1,而节点只有1个,所以备份出来的数据没有节点可分配

解决方案:增加节点或者把number_of_replicas设置为0

单个索引设置
curl -XPUT 'localhost:9200/<INDEX_NAME>/_settings' -d '{"number_of_replicas": 0}'
统一设置
curl -XPUT 'localhost:9200/_settings' -d ' { "index" : { "number_of_replicas" : 0 } }'
或者在配置文件中增加
index.number_of_replicas: 0

节点数和备份数应遵循: N >= R + 1, N为节点数,R为number_of_replicas设置的值

参考:https://www.datadoghq.com/blog/elasticsearch-unassigned-shards/#monitoring-for-unassigned-shards

原文地址:https://www.cnblogs.com/oyx305/p/8496278.html