Elasticsearch: Max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
Asked Answered
T

22

274

I have an issue with a systemd config for ElasticSearch.

[Unit]
Description=platform-elasticsearch
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
User={{ app_user }}
Group={{ app_group }}
Environment=ES_PATH_CONF=/platform/opt/elasticsearch-{{ elasticsearch.version }}/config
Environment=JAVA_HOME=/platform/opt/jdk{{ jdk.major_version }}_{{ jdk.minor_version }}
LimitAS=infinity
LimitRSS=infinity
LimitCORE=infinity
LimitNOFILE=100000
LimitMEMLOCK=100000
StandardOutput=syslog
StandardError=syslog
WorkingDirectory=/platform/var/app/elasticsearch
ExecStart=/platform/opt/elasticsearch-{{ elasticsearch.version }}/bin/elasticsearch
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s -TERM $MAINPID
TimeoutStopSec=60
# When a JVM receives a SIGTERM signal it exits with code 143
SuccessExitStatus=143 0
Type=simple
Restart=on-failure
RestartSec=10
PIDFile=/platform/var/run/elasticsearch.pid

[Install]
WantedBy=multi-user.target

This does not seem to let me configure the vm.max_map_count setting.

Jul 20 14:53:46 scratchpad elasticsearch: [2018-07-20T14:53:46,359][INFO ][o.e.b.BootstrapChecks    ] [1oQJNUK] bound or publishing to a non-loopback     address, enforcing bootstrap checks
Jul 20 14:53:46 scratchpad elasticsearch: ERROR: [1] bootstrap checks failed
Jul 20 14:53:46 scratchpad elasticsearch: [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
Jul 20 14:53:46 scratchpad elasticsearch: [2018-07-20T14:53:46,376][INFO ][o.e.n.Node               ] [1oQJNUK] stopping ...
Jul 20 14:53:46 scratchpad elasticsearch: [2018-07-20T14:53:46,414][INFO ][o.e.n.Node               ] [1oQJNUK] stopped
Jul 20 14:53:46 scratchpad elasticsearch: [2018-07-20T14:53:46,414][INFO ][o.e.n.Node               ] [1oQJNUK] closing ...
Jul 20 14:53:46 scratchpad elasticsearch: [2018-07-20T14:53:46,445][INFO ][o.e.n.Node               ] [1oQJNUK] closed
Jul 20 14:53:46 scratchpad systemd: platform-elasticsearch.service: main process exited, code=exited, status=78/n/a

The specific issue is the following:

Jul 20 14:53:46 scratchpad elasticsearch: [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

I have been able to start elastic search on the commandline with the following:

sudo su -c 'echo 262144 > "/proc/sys/vm/max_map_count"' && \ 
export JAVA_HOME=/platform/opt/jdk1.8.0_181 && \
export ES_PATH_CONF=/platform/opt/elasticsearch-6.3.1/config && \
/platform/opt/elasticsearch-6.3.1/bin/elasticsearch 

can anyone tell me why LimitMEMLOCK=100000 does not work, and how I can effectively set max_map_count from within systemd.

I have also tried to set the following:

cat /etc/security/limits.d/30_elastic_limits.conf

vagrant       hard    nofile     500000
vagrant       hard    memlock     262144

but this seems to be totally ignored by systemd.

Tutu answered 20/7, 2018 at 15:26 Comment(0)
W
369

Vivek's answer

sysctl -w vm.max_map_count=262144

is correct, however, the setting will only last for the duration of the session. If the host reboots, the setting will be reset to the original value.

If you want to set this permanently, you need to edit /etc/sysctl.conf and set vm.max_map_count to 262144.

When the host reboots, you can verify that the setting is still correct by running sysctl vm.max_map_count

Weinstock answered 20/7, 2018 at 18:52 Comment(7)
Do not forget to reboot or: sysctl --systemEriha
note that if you restart the machine that configuration will be gone, so this method is not permanent.Jessjessa
This answer, and variations on it, seems to be the most popular answer, but what I don't see is WHERE this command should be executed. I'm trying this in Windows with WSL, and I get the error "sysctl: cannot stat /proc/sys/vm/max_map_count: No such file or directory", as if this argument is being treated like a file or command path, not a parameter being set to a value. I've also tried editing /etc/sysctl.conf in the WSL environment, and using a .wslconfig file in my Windows home directory with kernelCommandLine = "sysctl.vm.max_map_count=262144".Kerguelen
@Kerguelen this is a Linux-only configurationWeinstock
@Val,mI know it's a Linux config, but it's still needed for some Linux environment on Windows that runs under WSL. The question is how to invoke the right Linux environment in which to make this change.Kerguelen
@Kerguelen does this help: https://mcmap.net/q/110462/-elasticsearch-in-windows-docker-image-vm-max-map-count ?Weinstock
@Val, yes, it was the wsl -d docker-desktop that I needed. For some reason that didn't work the first time I tried it, but it does now. Thanks.Kerguelen
B
208

For MS Windows users, using wsl subsystem

Open powershell, run

wsl -d docker-desktop

then

sysctl -w vm.max_map_count=262144
Brunelle answered 9/3, 2021 at 13:26 Comment(8)
This worked for me on Windows 10 machine. Last step would be to enter exit in order to kick out of wsl.Derision
worked just fine, thank you very much! pitty I had to copy the command to power shellGerminate
This doesn't seem to be a "sticky" change in Docker Desktop -- you have to run the command every time you restart Docker, which is really obnoxious.Excel
To persist the change, you can add vm.max_map_count = 262144 to /etc/sysctl.confLindsey
This solution works. It is also the official solution from Elastic. Thank you!Walt
Persisting the change in /etc/sysctl.conf doesn't seem to work long-term, but https://mcmap.net/q/108236/-elasticsearch-max-virtual-memory-areas-vm-max_map_count-65530-is-too-low-increase-to-at-least-262144 does.Proulx
that's great but how to make change in docker-compose?Unitary
@Unitary its a host setting, not a container setting.Jiggerypokery
W
117

Insert the new entry into the /etc/sysctl.conf file with the required parameter:

vm.max_map_count = 262144

it make changes permanent.

Also run:

sysctl -w vm.max_map_count=262144

change current state of kernel.

If you use docker to take effect you should restart it:

systemctl restart docker
Wolfson answered 10/12, 2019 at 12:43 Comment(4)
if you are not root user you should make sure you have sudo right and use sudo before execute above.Obed
if you use docker-compose to run containers on host, you can also run this command sysctl -w vm.max_map_count=262144 with root privilege to solve this problem.Obed
Use sysctl vm.max_map_count=262144 (iwithout -w) and this way the change is available only till shutdown of OS. It is a dev machine. So, i did not want to change permanently.Carrara
this also works for Kubernetes if anyone is wondering, just run int on all of your nodes, maybe cordon and drain each first though.Oniskey
E
55

See the Elasticsearch documentation about virtual memory. On Centos you can do with following command:

sysctl -w vm.max_map_count=262144
Equilibrist answered 20/7, 2018 at 17:54 Comment(0)
K
32

You can also resolve the memory constraint issue by using single-node discovery type. Set this in the environment: discovery.type=single-node

docker-compose.yml

services:
  es:
    image: elasticsearch
    environment:
      - discovery.type=single-node

See also:

Kemberlykemble answered 5/7, 2021 at 9:33 Comment(0)
A
28

This is not an answer per se but a clarification/shortcut for anyone having the op's problem from a docker container perspective. I had this problem from an application running in a docker container. And as explained here by nishant

You don’t need to increase the virtual memory for Elasticsearch at the container level, you can do it for the host machine by running this command:

sudo sysctl -w vm.max_map_count=262144

and then restart your docker-containers.

As explained by val above setting this max_map_count this way won't persist upon the restart of the machine on which is running the docker container. and so you will need to save it in a more persistent manner as explained by him above.

Ambidexter answered 6/7, 2019 at 14:51 Comment(0)
B
23

I ran into the same issue for the single node elastic search cluster. As perelastic-search documentation, for running single node, you have use "discovery.type=single-node" in the docker run command.

docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.13.3

In docker-compose.yml, you can specif below:

version: '3.1'
services:
 elastic_search:
  image: docker.elastic.co/elasticsearch/elasticsearch:7.13.3
  container_name: es01
  environment:
   - discovery.type=single-node
   - node.name=es01
   - bootstrap.memory_lock=true
   - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
  ports:
   - 9200:9200
  networks:
   - elastic
networks:
 elastic:
Bastille answered 16/7, 2021 at 5:55 Comment(0)
D
21

For WSL, you can create config file (.wslconfig) at:

C:\Users\[your user]\.wslconfig

and put in it:

[wsl2]
kernelCommandLine = "sysctl.vm.max_map_count=262144"

So that you do not have to set max_map_count every time you restart PC

Dahlberg answered 4/4, 2022 at 19:52 Comment(1)
maybe I'm missing something since this doesn't work in my win 11Aphasic
S
10

Please run the following command: sysctl -w vm.max_map_count=262144 to increase the default virtual memory used by the Elasticsearch.

Note: When you run the above-mentioned command your problem will get resolved but, this will be a temporary solution as node/system/container gets restart your changes will go. So if you want to set this permanently, you need to edit /etc/sysctl.conf and set vm.max_map_count to 262144.

For more detail click here.

Signature answered 30/11, 2019 at 18:41 Comment(0)
D
5

This worked for me.

 sysctl -w vm.max_map_count=262144
Disentomb answered 4/6, 2022 at 11:38 Comment(0)
G
3

According to this answer, you can run:

sudo sysctl -w vm.max_map_count=262144

Just run the following command to see the value changed:

sysctl vm.max_map_count
Gauhati answered 10/5, 2023 at 14:16 Comment(0)
L
2

vm.max_map_count=262144

Add this line in to below path

vim /etc/sysctl.conf

or go to this link https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html

Laval answered 12/11, 2021 at 5:55 Comment(2)
What is the additional insight which your post provides in addition to existing answer? Especially compared to the most upvoted answer and the one it refers to. Try to avoid the impression that you create answers by using info from other answers to the same question, especially when even the summary is already there...Optimum
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Dianemarie
C
2

I am using mac m1,

Just added SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: true to the environment section of sonarqube image.

sonarqube:
  image: sonarqube:community
  hostname: sonarqube
  container_name: sonarqube
  depends_on:
    - db
  environment:
    SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
    SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: true
Cateran answered 5/11, 2023 at 11:21 Comment(0)
D
1

Max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144].
Please run the command below to fix this issue:

sysctl -w vm.max_map_count=262144
Durante answered 21/9, 2020 at 4:43 Comment(0)
W
1

You might also set node.store.allow_mmap: false.

However, this setting has memory implications for production workloads as mentioned here. It helped me to deploy Elasticsearch 8.4.0 in a minikube kubernetes cluster using the elastic operator.

Weksler answered 30/8, 2022 at 14:48 Comment(0)
G
1

To do this with docker (docker-compose) you use something like:

ulimits:
  memlock:
    soft: -1
    hard: -1

to remove limits - it should be in docker not the host machine..

Gally answered 22/11, 2023 at 1:38 Comment(0)
A
0

In case anyone is on elasticsearch 8.0 with kubernetes ECK operator.

Set runAsUser: 0

elastic/cloud-on-k8s#5410 (comment)

Starting with 8.0 Elasticsearch container is not running as root anymore, which is required to run sysctl. You can add runAsUser: 0 to force the init container to run as root

Amniocentesis answered 4/4, 2022 at 5:15 Comment(0)
R
0

if you are using yml file

apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: prod
spec:
  version: 8.6.0
  nodeSets:
    - name: master-nodes
      count: 3
      config:
        node.roles: ["master"]
      podTemplate:
        spec:
          initContainers:
            - name: sysctl
              securityContext:
                privileged: true
                runAsUser: 0
              command: ["sh", "-c", "sysctl -w vm.max_map_count=262144"]
      volumeClaimTemplates:
        - metadata:
            name: elasticsearch-data
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 10Gi
            storageClassName: standard
    - name: data-nodes
      count: 10
      config:
        node.roles: ["data"]
      podTemplate:
        spec:
          initContainers:
            - name: sysctl
              securityContext:
                privileged: true
                runAsUser: 0
              command: ["sh", "-c", "sysctl -w vm.max_map_count=262144"]
      volumeClaimTemplates:
        - metadata:
            name: elasticsearch-data
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 100Gi
            storageClassName: standard
Refugia answered 5/2, 2023 at 22:31 Comment(0)
D
0

Val's answer is correct however I would like to say there's a chance that your system does not use /etc/sysctl.conf instead uses /etc/sysctl.d/ (source). You could make a file inside /etc/sysctl.d/ (maybe called container.conf) and pass in the configurations into it

vm.max_map_count = 262144

and then reboot.

Dreamland answered 1/10, 2023 at 15:5 Comment(0)
L
0

For Rancher Desktop users (I'm using Windows), enter Rancher Desktop shell:

rdctl shell

Then:

sysctl -w vm.max_map_count=262144

Then restart Rancher Desktop for the changes to take effects:

rdctl shutdown

&

rdctl start
Loganiaceous answered 1/11, 2023 at 10:39 Comment(0)
D
-1

this will make changing now, and always work even if you reboot the device

echo 'vm.max_map_count=262144' | sudo tee -a /etc/sysctl.conf;sudo sysctl -w vm.max_map_count=262144

Defeasible answered 9/12, 2022 at 11:23 Comment(1)
A code-only answer is not high quality. While this code may be useful, you can improve it by saying why it works, how it works, when it should be used, and what its limitations are. Please edit your answer to include explanation and link to relevant documentation.Undermanned
E
-3

If you're using Rancher Desktop in macOS to work with images that for instance use ElasticSearch you can do the following:

Create override.yaml file at ~/Library/Application Support/rancher-desktop/lima/_config/override.yaml. Add the following to override.yaml:

provision:
- mode: system
  script: sysctl -w vm.max_map_count=262144 

Lastly, please stop and restart Rancher Desktop in order for the updated limits to take effect.

The original source for this solution is: https://docs.rancherdesktop.io/how-to-guides/increasing-open-file-limit/

Elkin answered 5/12, 2023 at 17:11 Comment(1)
A link to a solution is welcome, but please ensure your answer is useful without it: add context around the link so your fellow users will have some idea what it is and why it is there, then quote the most relevant part of the page you are linking to in case the target page is unavailable. Answers that are little more than a link may be deleted.Willin

© 2022 - 2025 — McMap. All rights reserved.