美文网首页
elasticsearch申请内存不足导致启动失败的排查

elasticsearch申请内存不足导致启动失败的排查

作者: 天草二十六_简村人 | 来源:发表于2020-05-21 14:07 被阅读0次

一. 背景

swagger接口调用查询失败:

{
  "traceId": "1085abdf516fc7d8",
  "code": 500,
  "msg": "系统异常",
  "description": "NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{KjZgTtvCRcS13VwIuBpBxw}{192.168.5.57}{192.168.5.57:9300}]]"
}

es运行得好好的, 怎么突然挂了?
于是,我用es head查询,如果连接失败.


image.png

刚好我前些时间安装了一个elastic另外一个客户端工具, 尝试看看什么原因.


image.png

再次印证ES是挂了. 后面将讲述详细的排查过程, 以及解决思路.

二. 排查过程

es挂的原因在哪, 可能是硬件资源不足. 但是我们第一反应是去重启.

1.重启

既然要重启,就需要知道es安装在哪.
我们的操作系统是centos, 下载rpm包. elasticsearch-5.3.2.rpm

> service elasticsearch status
elasticsearch dead but pid file exists

> service elasticsearch start
Starting elasticsearch:                                    [  OK  ]

于是,我跟对接的开发说,可以了!!!

并且我验证swagger和es - head 确实ok了。

可谁知,对方说,还是不行~~~

于是,我表示不信,再次上去验证,呃................

2.看错误日志

找到错误日志 tailf /data/eslogs/es.log

心里想着错误快给我出来, 眼睛看着,就是找不到啊, 全tm是info级别的日志。

这条路行不通!!!

3. elasticHD监控

elasticHD.png

什么?内存不足?
我得去瞧一瞧机器的系统资源占用情况。。

4.linux机器性能工具上场

(1) top
cpu方面, 状态良好.
内存就不乐观了~

(2) free
总内存大小为8G, 剩余可用内存2G.

>  free
                   total        used          free             shared    buffers     cached
Mem:       8028328    5885320    2143008        140       9156     173384
-/+ buffers/cache:    5702780    2325548
Swap:            0          0          0

三、解决问题

知道了问题所在,要解决就容易了。
修改jvm的堆内存大小, es默认内存大小配置为1G, 调小堆内存空间由6G到4G.

> cd /etc/elasticsearch/
> ll
总用量 24
-rw-rw---- 1 elasticsearch elasticsearch  390 9月  20 2017 elasticsearch.yml
-rw-rw---- 1 elasticsearch elasticsearch 2851 9月  20 2017 elasticsearch.yml.bk
-rw-rw---- 1 elasticsearch elasticsearch 3117 5月  21 13:49 jvm.options
-rw-rw---- 1 elasticsearch elasticsearch 4456 4月  25 2017 log4j2.properties
drwxr-x--- 2 elasticsearch elasticsearch 4096 4月  25 2017 scripts

> vi jvm.options 

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms4g
-Xmx4g

重启, 让配置生效~

验证端口已启动成功.
>  netstat -anp |grep 9200
> ss -ntlp
image.png

当然, 以目前内存总大小才8G,还安装了许多其他应用的情况下, 设置为4G的堆内存, 也还是有问题, 待后期遇到问题再优化吧.

# free
                   total        used          free              shared    buffers     cached
Mem:       8028328    6179588    1848740        132      24036     474584
-/+ buffers/cache:    5680968    2347360
Swap:            0          0          0

四.es.yml配置

cluster.name: es-cluster
node.name: es-1
node.attr.rack: r1
path.data: /data/es
path.logs: /data/eslogs
bootstrap.memory_lock: false
network.host: 0.0.0.0
http.port: 9200
discovery.zen.ping.unicast.hosts: ["192.168.0.100"]
discovery.zen.minimum_master_nodes: 1
gateway.recover_after_nodes: 1
http.cors.enabled: true
http.cors.allow-origin: "*"
bootstrap.system_call_filter: false

相关文章

网友评论

      本文标题:elasticsearch申请内存不足导致启动失败的排查

      本文链接:https://www.haomeiwen.com/subject/nhmzohtx.html