Recovering unassigned shards on elasticsearch 2.x——副本shard可以设置replica为0在设置回来

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
简介:

Recovering unassigned shards on elasticsearch 2.x

摘自:https://z0z0.me/recovering-unassigned-shards-on-elasticsearch/

I got accross the problem when decided to add a node to the elasticsearch cluster and that node was not able to replicate the indexes of the cluster. This issue is usually happens when there is not enough disk space available, or not available master or different elasticsearch version. While my servers had more than enough disk space and also the master was available with the help of the elasticsearch discuss I found out that the new node was having a different version than old nodes. Basically while installing on Debian jessie I just run apt-get install elasticsearch which ended up installing the latest available version. To install a specific version of the elasticsearch you prety much need to add ={version}.

#apt-get install elasticsearch={version}

Now that I have identified the reasons for unallocated shards and successfully downgraded the elasticsearch to the required version by running the command above after starting the node the cluster was still in red state with unassigned shards all over the place:

#curl http://localhost:9200/_cluster/health?pretty
 {
   "cluster_name" : "z0z0",
   "status" : "red",
   "timed_out" : false,
   "number_of_nodes" : 3,
   "number_of_data_nodes" : 3,
   "active_primary_shards" : 6,
   "active_shards" : 12,
   "relocating_shards" : 0,
   "initializing_shards" : 0,
   "unassigned_shards" : 8,
   "delayed_unassigned_shards" : 0,
   "number_of_pending_tasks" : 0,
   "number_of_in_flight_fetch" : 0,
   "task_max_waiting_in_queue_millis" : 0,
   "active_shards_percent_as_number" : 60.0
 }

#curl http://localhost:9200/_cat/shards
site-id      4 p UNASSIGNED                                                 
site-id      4 r UNASSIGNED                                                 
site-id      1 p UNASSIGNED                                                 
site-id      1 r UNASSIGNED                                                 
site-id      3 p STARTED    0 159b 10.0.0.6 node-2 
site-id      3 r STARTED    0 159b 10.0.0.7 node-3 
site-id      2 r STARTED    0 159b 10.0.0.6 node-2 
site-id      2 p STARTED    0 159b 10.0.0.7 node-3 
site-id      0 r STARTED    0 159b 10.0.0.6 node-2 
site-id      0 p STARTED    0 159b 10.0.0.7 node-3 
subscription 4 p UNASSIGNED                                                 
subscription 4 r UNASSIGNED                                                 
subscription 1 p UNASSIGNED                                                 
subscription 1 r UNASSIGNED                                                 
subscription 3 p STARTED    0 159b 10.0.0.6 node-2 
subscription 3 r STARTED    0 159b 10.0.0.7 node-3 
subscription 2 r STARTED    0 159b 10.0.0.6 node-2 
subscription 2 p STARTED    0 159b 10.0.0.7 node-3 
subscription 0 p STARTED    0 159b 10.0.0.6 node-2 
subscription 0 r STARTED    0 159b 10.0.0.7 node-3

At this point I was pretty desperate and whatever I tried it either did not do anything or ended up in all kind of failures. So I set the number_of_replicas to 0 by running the following query:

#curl -XPUT http://localhost:9200/_settings?pretty -d '
{
  "index" : {
    "number_of_replicas' : 0
  }
}'

and started to stop the nodes one by one until I was having only one live node. 
At this point I decided to start trying to reroute the unassigned shards and if it won't work I would just start over my cluster. So I did run the following:

#curl -XPOST -d '
{
  "commands" : [ {
    "allocate" : {
      "index" : "site-id",
      "shard" : 1,
      "node" : "node-3",
      "allow_primary" : true
    }
  } ]
}' http://localhost:9200/_cluster/reroute?pretty

I've seen that the rerouted shard became initialized then running so I did the same command on the rest of unassigned shards. 
Running curl http://localhost:9200/_cluster/health?pretty confirmed that I am on the good track to fix the cluster.

#curl http://localhost:9200/_cluster/health?pretty
{
  "cluster_name" : "z0z0",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 10,
  "active_shards" : 20,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}

So the cluster was green again but was running out of one node. So it was time to bring up the other nodes one by one. When all the nodes were up I set the number_of_replicas to 1 by running the following:

#curl -XPUT http://localhost:9200/_settings -d '
{
  "index" : {
    "number_of_replicas" : 1
  }
}'

So my elasticsearch cluster is back on running 3 nodes and still in green state. After alot of googling and wasted time I decided to write this article so that if anyone would come accross this issue would have a working example of how to fix it.













本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/7459391.html,如需转载请自行联系原作者


相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
2月前
|
API 索引
Elasticsearch Index Shard Allocation 索引分片分配策略
Elasticsearch Index Shard Allocation 索引分片分配策略
77 1
|
11月前
白话Elasticsearch66-针对集群重启时的shard恢复耗时过长问题定制的重要参数
白话Elasticsearch66-针对集群重启时的shard恢复耗时过长问题定制的重要参数
46 0
|
存储 算法 搜索推荐
ElasticSearch Shard
ElasticSearch 分片
104 0
|
存储 监控 Java
Elasticsearch索引监控之Indices Segments API与Indices Shard Stores
Elasticsearch索引监控之Indices Segments API与Indices Shard Stores
Elasticsearch索引监控之Indices Segments API与Indices Shard Stores
|
存储 Linux API
【Elastic Engineering】Elasticsearch:运用 shard 过滤器来控制索引分配给哪个节点
Elasticsearch:运用 shard 过滤器来控制索引分配给哪个节点
179 0
【Elastic Engineering】Elasticsearch:运用 shard 过滤器来控制索引分配给哪个节点
|
API 索引
【Elastic Engineering】Elasticsearch:通过 shrink API 减少 shard 数量来缩小 Elasticsearch 索引
Elasticsearch:通过 shrink API 减少 shard 数量来缩小 Elasticsearch 索引
243 0
|
存储 固态存储 Linux
【最佳实践】Elasticsearch 运用 shard filtering 实现冷热节点索引分配
在 Elasticsearch 的部署中,由于 node(节点)能力不同,会用来做不同的用途:运算能力较强的节点可以用来做 indexing(建立索引表格)的工作,而那些能力较差一点的节点,我们可以用来做搜索用途,这就是我们常说的 hot / warm 架构。
1368 0
【最佳实践】Elasticsearch 运用 shard filtering 实现冷热节点索引分配

热门文章

最新文章