[Solved] ERROR: bootstrap checks failed memory locking requested for elasticsearch process but memory is not locked

Official website description:

The official website of elasticsearch suggests that bootstrap.memory should be set for the production environment_ lock: true

The official website explains that when system switching occurs, the performance of ES nodes will be very poor, which will also affect the stability of nodes. So avoid switching at all costs. Switching will cause the cycle delay of Java GC to deteriorate from milliseconds to minutes. What’s more, it will cause node response delay or even leave the cluster.

Therefore, it is better to limit the memory occupied by elastic search and use less swap

Error content:

Open bootstrap.memory_After lock: true , the following error will be reported when the elasticsearch cluster is started

ERROR: bootstrap checks failed memory locking requested for elasticsearch process but memory is not locked

When I use docker compose for deployment, the cluster keeps restarting and cycling between failures!


Option 1:

This scheme is applicable to Linux distributions that are not managed by SYSTEMd. CentOS 6 and below can be solved only through this scheme

Temporary solution:

ulimit -l unlimited

Permanent solution:

Edit/etc/security/limits.conf with root privileges

$ sudo vim /etc/security/limits.conf

Add the following contents, save and exit

* soft memlock unlimited
* hard memlock unlimited

The * here represents all user names and can be replaced with the specified user name

In addition, there is a hole here. If there is a configuration file in the /etc/security/limits. D folder, the file just modified will be overwritten, so please ensure that there are no other files in the directory. If so, please contact the operation and maintenance personnel to confirm deletion

Modify /etc/sysctl. Conf

sudo echo "vm.swappiness=0" >> /etc/sysctl.conf

The function of this parameter is to tell the Linux kernel to use as few swap partitions as possible, which does not mean to disable swap. It can improve performance by using less swap

Use sysctl - P if you want sysctl.conf to take effect immediately rather than after a reboot

Login again or restart the server to take effect

Option 2:

It is applicable to the distribution of SYSTEMd management. An article mentioned that CentOS 7 needs to use this scheme. I use Debian 9.9.0 to solve the problem. It is recommended to complete the above scheme before trying this scheme

The third step of the above method is recommended here. Use as few swap partitions as possible

In the centos7 system, system D is used instead of SYSV/ The configuration scope of the/etc/security/limits.conf file has been reduced/ The configuration of/etc/security/limits.conf is only applicable to the resource limit of users logged in through PAM authentication. It does not take effect on the resource limit of SYSTEMd services. Therefore, the restrictions on login users can be set through the files under/etc/security/limits.conf and/etc/security/limits. D.

For the resource settings of SYSTEMd service, you need to modify the global configuration. The global configuration files are placed in/etc/SYSTEMd/system.conf and/etc/SYSTEMd/user.conf. At the same time, all. Conf files/etc/SYSTEMd/system. Conf.d /. Conf and/etc/SYSTEMd/user. Conf.d /. Conf in the two corresponding directories will also be loaded. System.conf is used by the system instance and user.conf is used by the user instance.

Global effective method:

sudo vim /etc/systemd/system.conf

Bottom add


Save and restart the system

Of course, since I use the docker instead of the package manager, I give a global solution

Local effective method: (install elasticsearch for package manager)

sudo systemctl edit elasticsearch

This command creates the elasticsearch.service.d/override.conf file in/etc/SYSTEMd/system

Add the following


Save, exit, execute the following command to take effect

sudo systemctl daemon-reload

If it does not take effect, please try to restart the system

Compressed package version test

For using tar.gz package, specify the memory reference as shown in the figure

We follow the diagram and use the command es_ JAVA_ OPTS="-Xms512m -Xmx512m" ./bin/elasticsearch

If at this time there is
[2019-06-20T07:01:36,305][WARN ][o.e.b.JNANatives         ] [node-1] Unable to lock JVM Memory: error=12, reason=Cannot allocate memory
[2019-06-20T07:01:36,340][WARN ][o.e.b.JNANatives         ] [node-1] This can result in part of the JVM being swapped out.
[2019-06-20T07:01:36,343][WARN ][o.e.b.JNANatives         ] [node-1] Increase RLIMIT_MEMLOCK, soft limit: 16777216, hard limit: 16777216
[2019-06-20T07:01:36,343][WARN ][o.e.b.JNANatives         ] [node-1] These can be adjusted by modifying /etc/security/limits.conf, for example:
        # allow user 'hellxz' mlockall
        hellxz soft memlock unlimited
        hellxz hard memlock unlimited
Please try to add the first option again, and use both options together

These are the above contents, hoping to be helpful to readers

Similar Posts: