ElasticSearch 常见故障解析与修复秘籍

文章目录

一、ElasticSearch启动服务提示无法使用root用户

问题现象:WARN o.e.b.ElasticSearchUncaughtExceptionHandler \[\] uncaught exception in thread main org.ElasticSearch.bootstrap.StartupException: java.lang.RuntimeException: can not run ElasticSearch as root

解决:由于ElasticSearch程序启动需要使用非root用户,比如添加es用户用于启动es服务使用

例子:

复制代码
# useradd es //添加es用户
# passwd es //设置es用户密码
# 的修改
# chown -R es:es 数据目录路径 //修改es数据存储路径权限
# su es //切换es用户
$ 启动ElasticSearch服务即可

二、ElasticSearch启动提示进程可拥有的虚拟内存少

问题现象:max virtual memory areas vm.max_map_count 65530 is too low, increase to at least 262144

解决 :

方法1(临时):切换用户root输入命令

复制代码
# sysctl -w vm.max_map_count=262144;

查看结果:# sysctl -a|grep vm.max_map_count

方法2:切换root用户修改配置文件sysctl.conf

复制代码
# vim /etc/sysctl.conf
添加内容:vm.max_map_count=655360
# sysctl -p //加载命令生效
注:需要重新启动ElasticSearch服务

三、ElasticSearch提示用户拥有的可创建文件描述符太少

问题现象:max file descriptors 4096 for ElasticSearch process is too low, increase to at least 65535

解决 :切换root用户修改配置文件

#/etc/security/limits.conf

添加如下内容

es hard nofile 65535

es soft nofile 65535

注:切换es用户重启ElasticSearch服务即可

四、ElasticSearch集群yellow状态分析

  1. es集群状态信息查看GET _cat/health,es状态有3种。

    green:所有分片都可用

    yellow:至少有一个副本不可用或者未分配从分片,但是所有主分片都可以用

    red:至少有一个主分片不可用,数据不完整

  2. 查看索引状态

    curl -s -XGET 'http://:9200/_cat/indices?v'

    curl -s -XGET 'http://:9200/_cluster/health?level=indices'

  3. 查询未分配的分片

    curl -s -XGET 'http://:9200/_cat/shards?v' | grep UNASSIGNED

    curl -s -XGET 'http://:9200/_cluster/health?level=shards'

  4. 索引副本设置不合理,如果索引副本数设置大于数据节点个数导致yellow状态,需要修改副本修复集群状态

    curl -XPUT http://:9200/unassigned_index/_settings -H 'Content-Type: application/json' -d '{ "index": { "number_of_replicas": replicasCount } }'

    注:# unassigned_index为未分配的分片索引 # replicasCount为新的索引副本数

  5. 正常情况下,未分配的从分片会自动得到分配,集群状态也会恢复 green。某些特殊情况可能需要手动分配掉未分配的从分片

    注:# unassigned_index为未分配的分片索引 # num为未分配的分片编号 # nodeName为节点名称,也可以为节点编号ID

    curl -XPOST http://:9200/_cluster/reroute -H 'Content-Type: application/json' -d '{ "commands": [{ "allocate_replica": { "index": "unassigned_index", "shard": num, "node": "nodeName" } }] }'

要删除一个索引

五、ElasticSearch节点磁盘使用率过高,read_only状态问题解决

问题现象:当磁盘使用率超过85%甚至到100%会导致es集群物业正常提供服务,进行索引请求时返回异常信息 org.ElasticSearch.cluster.block.ClusterBlockException: blocked by: FORBIDDEN/12/index read-only / allow delete (api) 集群进入只读模式或者删除操作

问题分析:由于磁盘使用率过高导致,数据节点的磁盘使用率存在三个水位线,超过水位线会影响ElasticSearch服务

  1. 当集群磁盘使用率超过85%,会导致新的分片无法分片
  2. 当集群磁盘使用率超过90%,es会尝试将对应的节点的分片迁移到其他磁盘使用率较低的数据节点中
  3. 当集群磁盘使用率超过95%,系统会对es集群中对应节点里每个索引强制设置read_only_allow_delete属性,该节点上所有索引无法写入数据,只能读取和删除对应索引

解决方法:

  1. 删除部分历史索引数据
  2. 扩大磁盘容量
  3. 添加新的节点

注:es磁盘分配默认是85%和90%,做好集群规划和容量评估。同时做好集群监控和系统层面监控

六、ElasticSearch分片数达上限

连接es 错误,查看 es 日志,发现有报

复制代码
In a future major version, this request will fail because this action would add [10] total shards, but this cluster currently has [1216]/[1000] maximum shards open. Before upgrading, reduce the number of shards in your cluster or adjust the cluster setting [cluster.max_shards_per_node].

解决办法:增大最大分片上限为 6万,根据es索引保留时长实际需要增大

复制代码
curl -XPUT -u elastic:你的密码 -H "Content-Type: application/json" http://172.17.0.1:9200/_cluste   
相关推荐
Elasticsearch2 小时前
从 137,306 行日志定位到一个故障副本:在 Kibana 中排查错误激增
elasticsearch
Elasticsearch6 小时前
State 即将弃用,由 cpu.mode 接替:在 Elastic 中迁移 OpenTelemetry 进程指标
elasticsearch
岳涛6 小时前
考古|ES 5.3 三条改动只提前打招呼,布尔宽松写法到 6.0 才真正拒绝
elasticsearch
Elasticsearch6 小时前
谁在发起请求?为 Amazon Bedrock AgentCore 智能体配置按用户划分的 Elasticsearch 访问权限
elasticsearch
Elasticsearch7 小时前
Elasticsearch 日志写入提速:用 3 项设置和 logsdb_columnar 从每秒 5.2 万行提升到 11.2 万行
elasticsearch
Elastic 中国社区官方博客9 小时前
Elastic 获得全新的 AWS 数据能力认证
大数据·人工智能·elasticsearch·搜索引擎·ai·云计算·aws
Elasticsearch1 天前
Elastic 获得全新的 AWS 数据能力认证
elasticsearch
Elasticsearch1 天前
Elastic 安全借助 NVIDIA Nemotron 为物理隔离的安全运营中心提供智能体人工智能
elasticsearch
Elasticsearch1 天前
NVIDIA Nemotron 现已在 Elastic 推理服务(EIS)中可用
elasticsearch