如何处理elastic search中的unassigned shards?

我们通过 GET _cat/allocation?v 可以查看每个节点分片的分配数量以及它们所使用的硬盘空间大小

发现其有51个shard是unassigned状态

再通过命令GET _cat/health?v:查看集群健康状态

可以看到其active_shards_percent为63.3%,原因就是其存在UNASSIGNED shards的情况,不过即使存在unassigned shard,也并不会影响es的使用的

产生unassigned shards的原因?

如果你只有一台机器,跑了es,但是你却在index中的settings中设置了replica为1,显然这个replica shard就会成为unassigned shards

而且你在查看原因的时候,其会显示

the shard cannot be allocated to the same node on which a copy of the shard already exists

即分片不能分配到已经存在分片副本的同一节点

如何解决呢?

首先精确定位unassigned shard的位置

GET _cat/shards?h=index,shard,prirep,state,unassigned.reason| grep UNASSIGNED

每行列出索引的名称,分片编号,是主分片p还是副本分片r,以及其未分配的原因

可以看到xxx-20180803的replica设置为1,而且是5个shards

 

可以通过以下语句查看具体原因:

GET _cluster/allocation/explain?pretty

如何解决呢?

1. 对于没有再使用价值的index,直接删除掉

DELETE test_index

2. 在使用中的,可以设置index的replica为0
 

PUT test_index/_settings
{
  "number_of_replica": 0
}

通过循环执行

GET _cluster/allocation/explain?pretty来获取存在unassigned shard的index name

以及
 

PUT indexName/_settings
{
  "number_of_replica": 0
}

来消除unassigned shards

参考:How to resolve unassigned shards in Elasticsearch

猜你喜欢

转载自blog.csdn.net/u013905744/article/details/81508029