How to set heap size via environment variable ES_JAVA_OPTS?

I commented xms and xmx in jvm.options, added export ES_JAVA_OPTS="-Xms800m -Xmx800m" in ./bash_profile. And echo $ES_JAVA_OPTS returns "-xms800m -Xmx800m".
But when I restart ES by .bin/elasticsearch, such a heap setting doesn't take effect. Why? How should I set the ES_JAVA_OPTS?

It has been solved. It's the issue of .bash_profile. Even after source .bash_profile, it can only change the settings of the current console/terminal. But for other console/terminal, including a new one after closing the current console/terminal, you will find the settings unchanged (you can test it by echo ) since it only load the settings from .bash_profile as the current user log-in.

Not sure in what version the jvm.options file is introduced but is definitly 5.x and greater.
If you are on elasticsearch 5.x or greater why not use that file?

more /etc/elasticsearch/jvm.options
## JVM configuration

################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms16g
-Xmx16g

It is said in the Elasticsearch Reference 6.5 (https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html) that " It is also possible to set the heap size via an environment variable. This can be done by commenting out the Xms and Xmx settings in the [ jvm.options ] file and setting these values via ES_JAVA_OPTS :

ES_JAVA_OPTS="-Xms2g -Xmx2g" ./bin/elasticsearch
ES_JAVA_OPTS="-Xms4000m -Xmx4000m" ./bin/elasticsearch .
I just want to know how to set the ES_JAVA_OPTS environment variable.

Ok, and that is not working? Not really sure what the issue is here.

I tried it again. Just added "ES_JAVA_OPTS=-Xms1g -Xmx1g" in .bash_profile, it works. The issue was the property of .bash_file, it only works for the current console/terminal, but not for other consoles/terminals unless you restart Linux.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.