首页 > 其他分享 >Recovering unassigned shards on elasticsearch 2.x——副本shard可以设置replica为0在设置回来

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

时间:2023-05-31 12:02:14浏览次数:45  
标签:node 10.0 Recovering 159b number shards cluster 设置

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.

标签:node,10.0,Recovering,159b,number,shards,cluster,设置
From: https://blog.51cto.com/u_11908275/6385884

相关文章

  • SqlServer2014管理工具创建用户并设置对应访问权限
     需求:创建一个具有访问权限登录的用户,用以访问指定数据库, 对其放开指定数据库的指定表  一、用户名创建以及设置1、首先使用管理员账号登陆到数据库,【安全性】-【登录名】-右键【新建登录名】 【服务器角色】页签中:用于向用户授予服务器范围内的安全特权 【用户映......
  • vant组件Popup 弹出层单独设置 van-overlay和van-popup样式
    <van-popupv-model="showInfoBox"position="top"class="top_">默认情况下会自带灰色蒙版如果一个页面的布局需要调用很多个弹框的话有的弹框不想要这个蒙版背景就需要通过这样设置相当于全局设置了.van-overlay{background-color:transparent;width......
  • Linux(Ubuntu)下设置开机自启shell脚本执行Java程序jar包
    Linux(Ubuntu)下设置开机自启shell脚本执行Java程序jar包 原创软件测试日常记录2023-01-1907:19:29博主文章分类:ubuntu©著作权文章标签ubuntujarlinuxJAVAjava文章分类运维阅读数122 经常需要在Linux服务器上设置开机启动jar包,首先编写一个启动jar包的脚本,这里以/......
  • 设置系统默认铃声
    PRODUCT_PROPERTY_OVERRIDES 属性用于定义新的系统变量 修改文档:获取系统默认铃声:adbshellgetpropro.config.ringtone通过此方式调试当前设备默认铃声是否正确 ......
  • 设置系统默认语言
    修改文档: device/mediateksample/k65v1_64_bsp/device.mk通常情况下,设置系统默认值,通常在对应项目的device.mk文件下修改系统默认属性即可 ......
  • idea项目设置鼠标右键点击文件夹通过IDEA打开
    每次打开idea项目是每次都要打开idea再手动选择项目,直接设置成右键打开会很方便。效果图:首先win+R输入regedit打开注册表打开注册表后找到如下路径:计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell右键->新建->项(k),命名为IDEA3. 在IDEA里,新建字符串值,起名......
  • idea项目设置鼠标右键点击文件夹通过IDEA打开
    每次打开idea项目是每次都要打开idea再手动选择项目,直接设置成右键打开会很方便。效果图:首先win+R输入regedit打开注册表打开注册表后找到如下路径:计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell右键->新建->项(k),命名为IDEA3. 在IDEA里,新建字符串值,起名......
  • idea项目设置鼠标右键点击文件夹通过IDEA打开
    每次打开idea项目是每次都要打开idea再手动选择项目,直接设置成右键打开会很方便。效果图: 1.首先win+R输入regedit打开注册表 2.打开注册表后找到如下路径:计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell 右键->新建->项(k),命名为IDEA 3.......
  • idea项目设置鼠标右键点击文件夹通过IDEA打开
    每次打开idea项目是每次都要打开idea再手动选择项目,直接设置成右键打开会很方便。效果图: 1.首先win+R输入regedit打开注册表 2.打开注册表后找到如下路径:计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell 右键->新建->项(k),命名为IDEA 3.......
  • vscode设置关键字高亮
    下载highlight-words插件在settings.json文件中添加以下代码路径:(文件>首选项>设置>打开设置(json)图标在右上角)"highlightwords.colors":[{"light":"#b3d9ff","dark":"cyan"},{"light":"#e6ffb3&......