ElasticSearch集群状态(shard unassigned排查)

事情起因很简单,相关同事报针对我写的一个索引报了个问题。处于学习目的排查下。 

常见的ES集群有三种状态,如下:

  • Green:主/副分片都已经分配好且可用;集群处于最健康的状态100%可用;
  • Yellow:主分片可用,但是副分片不可用。这种情况ES集群所有的主分片都是已经分配好了的,但是至少有一个副本是未分配的。这种情况下数据也是完整的;但是集群的高可用性会被弱化。
  • Red:存在不可用的主分片。此时只是部分数据可以查询,已经影响到了整体的读写,需要重点关注。这种情况ES集群至少一个主分片(以及它的全部副本)都缺失。

1、查看集群状态

如下图所示分别为green和red的样子。

GET /_cluster/health

   

对于上述red的情况。需要重点关注unassigned_shards没有正常分配的分片。

2、找到异常索引

方法一:查看所有索引状况,如下就是有问题的。右侧查找 red 关键词。

GET /_cat/indices

方法二:直接查看unassigned的shard。

查找 unassigned 关键词。

GET /_cat/shards

3、查看不分配原因

使用 Cluster Allocation Explain API ,返回集群为什么不分配分片的详细原因。
 

GET /_cluster/allocation/explain?pretty

curl -X GET "http://xxx.io:48888/_cluster/allocation/explain?pretty"

4、常见的unassigned原因

这里简单列一下:

(1)磁盘满

the node is above the high watermark cluster setting [cluster.routing.allocation.disk.watermark.high=95%], using more disk space than the maximum allowed [95.0%], actual free: [4.055101177689788%]

 解决:扩容磁盘或者删除数据

(2)分配文档超过最大限制

failure IllegalArgumentException[number of documents in the index cannot exceed 2147483519

解决:向新索引中写入数据,并合理设置分片大小。 

(3)主分片所在节点掉线

cannot allocate because a previous copy of the primary shard existed but can no longer be found on the nodes in the cluster

 解决:找到节点掉线的原因并重新其中节点加入集群,等待分片恢复。

(4)索引属性与节点属性不匹配

node does not match index setting [index.routing.allocation.require] filters [temperature:“warm”,_id:“comdNq4ZSd2Y6ycB9Oubsg”]

解决:重新设置索引的冷热属性,和节点保持一致;若要修改节点属性,则需要重启节点。 

(5)节点长时间掉线后再次加入集群,导致引入脏数据

cannot allocate because all found copies of the shard are either stale or corrupt

解决:使用 reroute API

(6)未分配的分片太多,导致达到了分片恢复的最大阈值,其他分片需要排队等待

reached the limit of incoming shard recoveries [2], cluster setting [cluster.routing.allocation.node_concurrent_incoming_recoveries=2] (can also be set via [cluster.routing.allocation.node_concurrent_recoveries])

解决:使用cluster/settings调大分片恢复的并发度和速度

Elasticsearch集群规划及性能优化实践(笔记)_ttldba的博客-CSDN博客

腾讯云Elasticsearch集群规划及性能优化实践_mb5fdb0a87e2fa1的技术博客_51CTO博客

5、节点冷热属性不匹配解决

(1)首先是查看节点冷热属性

GET _cat/nodeattrs?v&h=node,attr,value&s=attr:desc

curl -X GET "http://xxxx.io:48888/_cat/nodeattrs?v&h=node,attr,value&s=attr:desc"

 

总的来讲就是调整索引(或者模板)的setting里面的temperature属性,是在不行不设就好了。

猜你喜欢

转载自blog.csdn.net/mijichui2153/article/details/125374880
今日推荐