当前位置: 首页 > news >正文

Elasticsearch集群Yellow亚健康状态修复

Elasticsearch集群Yellow亚健康状态修复

  • 问题背景
  • 排查流程
  • 解决办法

问题背景

Elasticsearch集群健康状态为Yellow,涉及到多个索引。

排查流程

在浏览器打开Kibana Console进行问题排查,console地址为:

http://{Kibana_IP}:5601/app/dev_tools#/console

在console运行以下API命令来获取基本信息:

GET _cat/health?v
GET _cat/master?v
GET _cat/nodes?v
GET _cat/indices?vGET _cat/shards?v
# 输出中各列分别为:
# shard:分片名称;prirep:主分片或副本,
# state:分片状态,可以为 INITIALIZING | RELOCATING | STARTED | UNASSIGNED
# docs:分片中文档的数量;store:分片占用的磁盘空间GET _cat/allocation?v
# 获取分配到每个节点的分片数量以及所占用的磁盘空间

获取健康状态为Yellow的索引信息:

GET _cat/indices?v&health=yellow

输出中包含的列有health、status(索引状态)、index(索引名称)、uuid、pri(主分片数量)、rep(副本数量)、docs.count、docs.deleted、store.size、pro.store.size。

从上面拿到的异常状态索引中,任选一个(假设为ftimes_infra_migrad_2022-09)继续查看该索引的分片信息:

GET _cat/shards/ftimes_infra_migrad_2022-09?v

输出的列中包含index、shard(分片名称)、prirep(primary还是replica)、state、docs、store(分片大小)、ip、node(分片所在节点)。

观察目标索引的各个分片的分配情况。Yellow健康状态下一般这里可以看到有replica分片没有被正确分配,即prirep=r的行记录,对应的分片状态为state=UNASSIGNED

假设未被正确分配的replica分片名称为0,检查该分片分配失败的原因:

GET _cluster/allocation/explain
{"index": "ftimes_infra_migrad_2022-09","shard": 0,"primary": false
}

检查输出中的explanation部分:

...
"explanation": "shard has exceeded the maximum number of retries [5] on failed
allocation attempts - manually call [/_cluster/reroute?retry_failed=true] to retry,
..."

解决办法

下面我们尝试手动分配该replica分片。需要确保replica分片要分配的节点上有足够的磁盘空间,并且同一索引的primary分片和replica分片不在同一节点上。

# 查看分片的大小、主分片所在节点
GET _cat/shards/ftimes_infra_migrad_2022-09?v# 查看各节点的磁盘空间使用情况
GET _cat/allocation?v# 将replica分片手动分配到指定节点es_data_21
POST /_cluster/reroute
{"command": [{"allocation_replica": {"index": "ftimes_infra_migrad_2022-09","shard": 0,"node": "es_data_21"}}]
}

执行后收到下面的报错:

...
"type": "illegal_argument_exception",
"reason": "[allocation_replica] allocation of [ftimes_infra_migrad_2022-09][0] on
node {es_data_21}{...}{...} is not allowed, reason: [NO(shard has exceeded the 
maximum number of retries [5] on failed allocation attempts - manually call 
[/_cluster/reroute?retry_failed=true] to retry, ... )]"

根据错误提示执行以下命令:

POST /_cluster/reroute?retry_failed=true

ES集群就会自动重新分配之前分配出错的replica副本。

过一小段时间后,检查所有索引健康状态:

GET _cat/indices?v&health=yellow

🐟MORE …

在Kibana的console API命令中,可以使用s来对检索结果按指定的列排序,并使用通配符*来匹配任意字符串。

# 获取集群中所有索引信息,并按index列排序
GET _cat/indices?v&s=index# 获取集群中名称以ftimes开头的所有索引信息,并按index列排序
GET _cat/indices/ftimes*?v&s=index# 获取集群中名称以gzone开头的索引的所有分片信息
GET _cat/shards/gzone*
http://www.lryc.cn/news/18338.html

相关文章:

  • 第52讲:SQL优化之UPDATE更新操作的优化
  • logback 自定义日志输出到数据库
  • < elementUi 组件插件: el-table表格拖拽修改列宽及行高 及 使用注意事项 >
  • 微信小程序的分享朋友圈
  • 华为OD机试真题Python实现【 寻找路径】真题+解题思路+代码(20222023)
  • 九头蛇hydra爆破http示例
  • jQuery基本使用
  • 互联网企业如何进行数字化转型?业务需求迭代频繁的应对之策!
  • 前端学习日记——Vue之Vuex初识(一)
  • 【C++】Windows动态库【.DLL文件】制作方法总结
  • C 语言编程 — HelloWorld
  • 蓝桥杯入门即劝退(二十一)三数之和(梦破碎的地方)
  • element 下拉框支持搜索并输入
  • JVM详解——垃圾回收
  • spring之集成Mybatis
  • 【面试宝典】准备面试了~集合
  • 华为OD机试真题Python实现【GPU 调度】真题+解题思路+代码(20222023)
  • gcc编译C源程序
  • Tina_Linux_各平台多媒体格式_支持列表_new
  • 归并排序及其应用
  • 【PAT甲级题解记录】1007 Maximum Subsequence Sum (25 分)
  • 华为OD机试真题Python实现【 最小叶子节点】真题+解题思路+代码(20222023)
  • mars3d动态轨迹DynamicRoamLine,如何获取实时运⾏的经纬度
  • jvm常识
  • PHP部署、nginx与PHP的整合、PHP动态添加模块
  • SpringCloud与SpringBoot的版本对应
  • 华为OD机试题,用 Java 解【N 进制减法】问题
  • Linux->进程概念于基本创建
  • 【MySQL】5.7版本解压安装配置
  • c++类对象数据成员和虚函数的内存布局