您当前的位置: 首页 >  ar

一一哥Sun

暂无认证

  • 4浏览

    0关注

    622博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Day16_05_ES教程之解决unassigned shards问题

一一哥Sun 发布时间:2019-07-06 22:54:05 ,浏览量:4

05_ES教程之解决unassigned shards问题

如何处理elastic search中的unassigned shards?

一. 查看节点分片信息
GET _cat/allocation?v

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

可能会发现其有5个shard是unassigned状态.

二. 查看集群健康状态 1. 查看健康状态
GET _cat/health?v

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

可以看到其active_shards_percent为87.8%,elasticsearch健康状态为yellow,原因就是其存在UNASSIGNED shards的情况,不过即使存在unassigned shard,也并不会影响es的使用的.

2. 产生原因

产生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

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

3. 首先精确定位unassigned shard的位置
GET _cat/shards?h=index,shard,prirep,state,unassigned.reason | grep UNASSIGNED

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

可以看到索引order的replica设置为1,而且是5个shards.

4. 可以通过以下语句查看具体原因
GET _cluster/allocation/explain?pretty

5. 如何解决? 5.1 (方案一)对于没有使用价值的index直接删除掉
DELETE order(索引名称)
5.2 对正在使用中的索引,可以设置index的replica为0
PUT order/_settings
{
  "number_of_replicas": 0
}
5.3 通过循环获取存在unassigned shard的index name
GET _cluster/allocation/explain?pretty
5.4 设置复制分片数量为0
PUT order/_settings
{
  "number_of_replicas": 0
}

来消除unassigned shards.

此时可以看到,我们的es节点健康状态为green,非常健康(绿绿更健康,?)!!!  

关注
打赏
1665624836
查看更多评论
立即登录/注册

微信扫码登录

0.0494s