如何处理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

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值