bootstrap check failure [1] of [1]: memory locking requested for elasticsearch process but memory is

濮阳旭东
2023-12-01

os: centos 7.6.1810
es: elasticsearch Version 7.12.0 (Build 778cc7261dfdd1)

三节点的es,第一次启动时报错,相关错误日志如下

[2021-04-15T15:15:28,247][WARN ][o.e.b.JNANatives         ] [esn1] Unable to lock JVM Memory: error=12, reason=Cannot allocate memory
[2021-04-15T15:15:28,249][WARN ][o.e.b.JNANatives         ] [esn1] This can result in part of the JVM being swapped out.
[2021-04-15T15:15:28,250][WARN ][o.e.b.JNANatives         ] [esn1] Increase RLIMIT_MEMLOCK, soft limit: 65536, hard limit: 65536
[2021-04-15T15:15:28,250][WARN ][o.e.b.JNANatives         ] [esn1] These can be adjusted by modifying /etc/security/limits.conf, for example: 
	# allow user 'elasticsearch' mlockall
	elasticsearch soft memlock unlimited
	elasticsearch hard memlock unlimited
[2021-04-15T15:15:28,251][WARN ][o.e.b.JNANatives         ] [esn1] If you are logged in interactively, you will have to re-login for the new limits to take effect.

[2021-04-15T15:15:38,710][INFO ][o.e.n.Node               ] [esn1] initialized
[2021-04-15T15:15:38,710][INFO ][o.e.n.Node               ] [esn1] starting ...
[2021-04-15T15:15:38,724][INFO ][o.e.x.s.c.PersistentCache] [esn1] persistent cache index loaded
[2021-04-15T15:15:38,811][INFO ][o.e.t.TransportService   ] [esn1] publish_address {192.168.56.221:9300}, bound_addresses {192.168.56.221:9300}
[2021-04-15T15:15:38,927][INFO ][o.e.b.BootstrapChecks    ] [esn1] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2021-04-15T15:15:38,931][ERROR][o.e.b.Bootstrap          ] [esn1] node validation exception
[1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch.
bootstrap check failure [1] of [1]: memory locking requested for elasticsearch process but memory is not locked
[2021-04-15T15:15:38,935][INFO ][o.e.n.Node               ] [esn1] stopping ...
[2021-04-15T15:15:38,951][INFO ][o.e.n.Node               ] [esn1] stopped
[2021-04-15T15:15:38,952][INFO ][o.e.n.Node               ] [esn1] closing ...
[2021-04-15T15:15:38,970][INFO ][o.e.n.Node               ] [esn1] closed
[2021-04-15T15:15:38,972][INFO ][o.e.x.m.p.NativeController] [esn1] Native controller process has stopped - no new native processes can be started

检查 memory_lock 参数

bootstrap.memory_lock: true

检查 /etc/security/limits.conf 参数,发现 memlock 参数已经设置

# cat /etc/security/limits.conf

* soft nofile  1024000 # The maximum number of open file descriptors
* hard nofile  1024000
* soft nproc   unlimited # The maximum number of processes available to a single user
* hard nproc   unlimited 
* soft memlock unlimited # The maximum size that may be locked into memory
* hard memlock unlimited
* soft core    unlimited # The maximum size of core files created
* hard core    unlimited
* soft stack   unlimited  
* hard stack   unlimited

按照提示,在尾部继续添加

# allow user 'elasticsearch' mlockall
elasticsearch soft memlock unlimited
elasticsearch hard memlock unlimited

同时移除 /etc/security/limits.d 下的文件

# mv /etc/security/limits.d/20-nproc.conf ~

再次启动 elasticsearch ,依旧报错。

网上搜后可以通过另外方式解决

局部修改

# systemctl edit elasticsearch

添加如下内容

[Service]
LimitMEMLOCK=infinity

此命令会创建 /etc/systemd/system/elasticsearch.service.d/override.conf 文件

# systemctl daemon-reload

再次启动没有再报错

# systemctl start elasticsearch

全局修改

# vi /etc/systemd/system.conf

DefaultLimitMEMLOCK=infinity

再次启动也没有报错

# systemctl start elasticsearch

困惑,为什么 /etc/security/limits.conf 的 memlock 参数没有生效?
其余参数是否也没有生效?

参考:
https://www.elastic.co/guide/en/elasticsearch/reference/7.12/setting-system-settings.html#systemd

 类似资料: