• 原文地址:http://www.wklken.me/posts/2015/05/23/elasticsearch-issues.html

今天惯例看统计报表, 才发现es集群悲剧了......昨天下午到今天早上, 持续报错, 写了1G的错误日志>_<#(暂无监控....)

当前状态: 单台机器, 单节点(空集群), 200W 数据, 500+shrads, 约3G大小

以下是几个问题的处理过程

大量unassigned shards

其实刚搭完运行时就是status: yellow(所有主分片可用,但存在不可用的从分片), 只有一个节点, 主分片启动并运行正常, 可以成功处理请求, 但是存在unassigned_shards, 即存在没有被分配到节点的从分片.(只有一个节点.....)

.当时数据量小, 就暂时没关注. 然后, 随着时间推移, 出现了大量unassigned shards

curl -XGET http://localhost:9200/_cluster/health\?pretty
{"cluster_name" : "elasticsearch","status" : "yellow","timed_out" : false,"number_of_nodes" : 2,"number_of_data_nodes" : 1,"active_primary_shards" : 538,"active_shards" : 538,"relocating_shards" : 0,"initializing_shards" : 0,"unassigned_shards" : 558,
"number_of_pending_tasks" : 0
}

处理方式: 找了台内网机器, 部署另一个节点(保证cluster.name一致即可, 自动发现, 赞一个). 当然, 如果你资源有限只有一台机器, 使用相同命令再启动一个es实例也行. 再次检查集群健康, 发现unassigned_shards减少, active_shards增多.

操作完后, 集群健康从yellow恢复到 green

status: red

集群健康恶化了......

这次检查发现是status: red(存在不可用的主要分片)

curl -XGET http://localhost:9200/_cluster/health\?pretty
{"cluster_name" : "elasticsearch","status" : "red",    // missing some primary shards"timed_out" : false,"number_of_nodes" : 4,"number_of_data_nodes" : 2,"active_primary_shards" : 538,"active_shards" : 1076,"relocating_shards" : 0,"initializing_shards" : 0,"unassigned_shards" : 20,  // where your lost primary shards are."number_of_pending_tasks" : 0
}

fix unassigned shards

开始着手修复

查看所有分片状态

curl -XGET http://localhost:9200/_cat/shards

找出UNASSIGNED分片

curl -s "http://localhost:9200/_cat/shards" | grep UNASSIGNED
pv-2015.05.22                 3 p UNASSIGNED
pv-2015.05.22                 3 r UNASSIGNED
pv-2015.05.22                 1 p UNASSIGNED
pv-2015.05.22                 1 r UNASSIGNED

查询得到master节点的唯一标识

curl 'localhost:9200/_nodes/process?pretty'{"cluster_name" : "elasticsearch","nodes" : {"AfUyuXmGTESHXpwi4OExxx" : {"name" : "Master",...."attributes" : {"master" : "true"},
.....

执行reroute(分多次, 变更shard的值为UNASSIGNED查询结果中编号, 上一步查询结果是1和3)

curl -XPOST 'localhost:9200/_cluster/reroute' -d '{"commands" : [ {"allocate" : {"index" : "pv-2015.05.22","shard" : 1,"node" : "AfUyuXmGTESHXpwi4OExxx","allow_primary" : true}}]}'

批量处理的脚本(当数量很多的话, 注意替换node的名字)

#!/bin/bashfor index in $(curl  -s 'http://localhost:9200/_cat/shards' | grep UNASSIGNED | awk '{print $1}' | sort | uniq); dofor shard in $(curl  -s 'http://localhost:9200/_cat/shards' | grep UNASSIGNED | grep $index | awk '{print $2}' | sort | uniq); doecho  $index $shardcurl -XPOST 'localhost:9200/_cluster/reroute' -d "{            'commands' : [ {                  'allocate' : {                      'index' : $index,
                      'shard' : $shard,
                      'node' : 'Master',
                      'allow_primary' : true
                  }
                }
            ]
        }"sleep 5done
done

“Too many open files”

发现日志中大量出现这个错误

执行

curl http://localhost:9200/_nodes/process\?pretty

可以看到

"max_file_descriptors" : 4096,

官方文档中

Make sure to increase the number of open files descriptors on the machine (or for the user running elasticsearch). Setting it to 32k or even 64k is recommended.

而此时, 可以在系统级做修改, 然后全局生效

最简单的做法, 在bin/elasticsearch文件开始的位置加入

ulimit -n 64000

然后重启es, 再次查询看到

"max_file_descriptors" : 64000,

问题解决

es大量unassigned shards相关推荐

  1. ES 的 unassigned shards 核心处理方案

    背景:管理过数百个集群,使用方式千变万化,出现过各种各样的shards分配不了的情况,趁此假期做一些unassigned处理方案的总结: 先总结一下:所有的unassigned都可以通过explain ...

  2. es unassigned shards 解决

    服务器宕机后,es出现unassigned shards,使用reroute 命令提示 shard has exceeded the maximum number of retries,即使加上 re ...

  3. [unassigned_shards]Fix issue: elasticsearch unassigned shards

    今天遇到了一个elasticsearch相关的坑[unassigned shards],蹚完了,记录一下(详细的解释在中下方,耐心看完). 1.先确保elasticsearch(后简称es)处于启动状 ...

  4. Elasticsearch unassigned shards的解决之道

    出现这种提示,说明你的集群状态是亚健康的,status是yellow,至少有一个副本分片没有成功创建,集群是能正常工作的,只是有丢失数据的风险. 一,问题定位 解决思路,首先查清楚问题所在,es提供一 ...

  5. How to resolve unassigned shards in Elasticsearch——写得非常好

    How to resolve unassigned shards in Elasticsearch 转自:https://www.datadoghq.com/blog/elasticsearch-un ...

  6. ES shard unassigned的解决方法汇总

    ES shard unassigned的解决方法汇总 参考文章: (1)ES shard unassigned的解决方法汇总 (2)https://www.cnblogs.com/bonelee/p/ ...

  7. Reroute Unassigned Shards——遇到主shard 出现的解决方法就是重新路由

    Red Cluster! 摘自:http://blog.kiyanpro.com/2016/03/06/elasticsearch/reroute-unassigned-shards/ There a ...

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

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

  9. Diagnose unassigned shards

    Diagnose unassigned shards Diagnose unassigned shards | Elasticsearch Guide [8.6] | Elastic

最新文章

  1. 助力隐私保护,Cashshuffle之后又一支柱Interwallet正式发布
  2. C语言基本语法——函数
  3. gdal获取像元的灰度值java_GDAL利用地理坐标读取图像像元值
  4. mysql账户最小授权_mysql 创建帐号并授权
  5. django http 收发_如何从一个django服务器发送请求到另一个服务器
  6. linux下安装Telnet服务器
  7. 前端打印功能实现及css设置
  8. caffe(CPU版本)配置 及MNIST调用
  9. C语言表上作业法运输问题,论运输问题表上作业法
  10. [编辑本段]【通古斯大爆炸六大热门假说】
  11. Beyong Compare4过期解决办法
  12. 人物志-丘吉尔 Success consists of going from failure to failure without loss of enthusiasm. —— Winston Chu
  13. 计算机突然关闭应用程序,应用程序无法正常启动(0xc000007b)。请单击“确定”关闭应用程序的解决方法...
  14. 伦敦银实时走势图决胜关键
  15. 如何制作网站的入门教程
  16. mysql cte递归_SQLSERVER中CTE语句结构及CTE递归查询
  17. [源码和文档分享]基于Android平台的个人理财软件的设计与实现
  18. 暴风TV携手科大讯飞,达成“百万人工智能”战略合作
  19. PHP企业级应用之常见缓存技术篇
  20. 区域医疗云his系统源码,具有可扩展、易共享、易协同的优势

热门文章

  1. const char*类型的实参与LPCTSTR类型的形参不兼容 MFC
  2. 代码随想录算法训练营第七天| 454.四数相加II 、383. 赎金信 、15. 三数之和 、18. 四数之和 。
  3. 免杀gh0st过瑞星
  4. 周边软件产业 - 拉私活的黑车该不该取缔?
  5. CF54C First Digit Law Solution
  6. pycharm zip函数_寒假整理3:Python的 zip函数 map函数 eval函数 的含义及应用实例
  7. [AHK]将字符转换成莫尔斯电码
  8. (抄袭自网络文摘)Ping使用方法大全
  9. 使用RSS reader订阅google group
  10. 主流时序数据库分析及选型