调整elasticsearch的jvm heap值

  • Post author:
  • Post category:其他

集群里有两台elasticsearch老是服务死机,报错大致如下:

Mar 26 08:19:47 es104 systemd[1]: Started Elasticsearch.
Mar 27 09:53:26 es104 systemd-entrypoint[8614]: [92045.788s][warning][gc,alloc] elasticsearch[nau-node-104][[syslog-fw-unicom-nat-20220327][0]: Lucene Merge Thread #325]: Retried waiting for GCLocker too often allocating 256 words
Mar 27 09:53:26 es104 systemd-entrypoint[8614]: [92045.796s][warning][gc,alloc] elasticsearch[nau-node-104][[syslog-fw-unicom-nat-20220327][0]: Lucene Merge Thread #325]: Retried waiting for GCLocker too often allocating 11 words
Mar 27 09:53:26 es104 systemd-entrypoint[8614]: java.lang.OutOfMemoryError: Java heap space
Mar 27 09:53:26 es104 systemd-entrypoint[8614]: Dumping heap to /var/lib/elasticsearch/java_pid8614.hprof ...
Mar 27 09:53:32 es104 systemd-entrypoint[8614]: Heap dump file created [1182309052 bytes in 5.955 secs]
Mar 27 09:53:32 es104 systemd-entrypoint[8614]: Terminating due to java.lang.OutOfMemoryError: Java heap space
Mar 27 09:53:33 es104 systemd[1]: elasticsearch.service: main process exited, code=exited, status=3/NOTIMPLEMENTED
Mar 27 09:53:33 es104 systemd[1]: Unit elasticsearch.service entered failed state.
Mar 27 09:53:33 es104 systemd[1]: elasticsearch.service failed.

感觉应该是heap值设置的有点小—默认是1g。

我的es版本是7.16.0,并且是rpm安装的,正确的调整heap值得方式如下:

进入/etc/elasticsearch/jvm.options.d目录,创建一个heap.options文件(文件后缀需要options即可)。

内容如下:

-Xms4g
-Xmx4g

也就是最大和最小都是4g,重启es即可。

然后我们发现heap就是4g了。


版权声明:本文为baalchina原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。