Elasticsearch 7.8 memory locking requested for elasticsearch process but memory is not locked 的解决办法-程序旅途

Elasticsearch 生产环境中建议设置 bootstrap.memory_lock:true,原因是发生系统 swapping 的时候,ES 节点的性能会非常差,也会影响节点的稳定性。

在 /etc/elasticsearch/elastichsearch.yml 中可以取消 bootstrap.memory_lock:true 前的注释,然后重启 Elasticsearch 服务即可。

Elasticsearch 7.8 memory locking requested for elasticsearch process but memory is not locked 的解决办法-程序旅途

正常重启 Elasticsearch 后,通过下面的请求查看配置是否成功应用

GET _nodes?filter_path=**.mlockall

返回true,表示成功

Elasticsearch 7.8 memory locking requested for elasticsearch process but memory is not locked 的解决办法-程序旅途

但是一般会遇到 Elasticsearch 重启失败,journalctl -xe 查看原因,会显示报如下的错误

Jul 26 08:07:21 iZlyj863ko4v20Z systemd-entrypoint[28660]: ERROR: [1] bootstrap checks failed
Jul 26 08:07:21 iZlyj863ko4v20Z systemd-entrypoint[28660]: [1]: memory locking requested for elasticsearch process but memory is not locked
Jul 26 08:07:21 iZlyj863ko4v20Z systemd-entrypoint[28660]: ERROR: Elasticsearch did not exit normally - check the logs at /var/log/elasticsearch/elasticsearch.log
Jul 26 08:07:21 iZlyj863ko4v20Z systemd[1]: elasticsearch.service: main process exited, code=exited, status=78/n/a
Jul 26 08:07:21 iZlyj863ko4v20Z systemd[1]: Failed to start Elasticsearch.

重点在于 memory locking requested for elasticsearch process but memory is not locked

Elasticsearch 7.8 memory locking requested for elasticsearch process but memory is not locked 的解决办法-程序旅途

出现这个问题的大部分原因是没有权限

解决办法

在 /etc/security/limits.conf 最后添加

elasticsearch  -  nofile  65535

Elasticsearch 7.8 memory locking requested for elasticsearch process but memory is not locked 的解决办法-程序旅途

添加文件 /etc/systemd/system/elasticsearch.service.d/override.conf(或执行 systemctl edit elasticsearch),填写以下内容

[Service]
LimitMEMLOCK=infinity

重新加载服务配置

systemctl daemon-reload

再次启动 Elasticsearch 服务

systemctl start elasticsearch

成功解决!

参考链接

CentOS 8 安装 ElasticSearch 7.8

https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html#bootstrap-memory_lock

https://www.elastic.co/guide/en/elasticsearch/reference/7.8/setting-system-settings.html#sysconfig