How can I modify the path Elasticsearch 2.4.6 uses to run Java in Linux?

Brand new to Elasticsearch. Can anyone explain how how to modify the path Elasticsearch v2.4.6 uses for Java on Linux? There is a discrepancy between Test and Production and I need to change Test to match Production:

Production Server:

elastic+   1265      1  3  2022 ?        5-19:32:36 /bin/java

/bin/java -> /etc/alternatives/java

/etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-oracle-1.8.0.151-1jpp.5.el7.x86_64/**jre/bin/java**

Test Server:

elastic+   1243      1  0  2022 ?        22:00:51 /usr/lib/jvm/java-oracle/bin/java

/usr/lib/jvm/java-oracle -> /etc/alternatives/java_sdk_oracle

/etc/alternatives/java_sdk_oracle -> /usr/lib/jvm/java-1.8.0-oracle-1.8.0.151-1jpp.5.el7.x86_64

/usr/lib/jvm/java-1.8.0-oracle-1.8.0.151-1jpp.5.el7.x86_64/**bin/java**

I need to modify the Test server to use the same Java binary as Production Server which is obscured a little bit by several soft (symbolic links) but the slightly different absolute paths are above. How can I modify the path Elasticsearch uses to run Java? Thanks!

Elasticsearch 2.4.6 is EOL and no longer supported. Please upgrade ASAP.

(This is an automated response from your friendly Elastic bot. Please report this post if you have any suggestions or concerns :elasticheart: )

Just so everyone knows, yes, I'm aware Elasticsearch 2.4.6 is EOL and we are still a few months away from testing and cutting over to new Test and Production servers running Liferay 7.4 DXP with Elasticsearch 7.17.9, however our web developers are troubleshooting an issue with the frontend web site with the root cause suspected to be the path to the Java binary that still needs to be modified to match Production, so if anyone can comment how to do this I'd appreciate the help.

You can define what JVM Elasticsearch uses as per Setup | Elasticsearch Guide [2.4] | Elastic;

The version of Java to use can be configured by setting the JAVA_HOME environment variable.

This may also be more of an OS specific question, but debian - How to use the command update-alternatives --config java - Stack Overflow has some options.

Thanks, I really needed to know more specifically how can I set the JAVA_HOME variable. I eventually looked at the file /usr/share/elasticsearch/bin/elasticsearch

Through quite a bit of searching I found an include file /usr/share/elasticsearch/bin/elasticsearch and it contained the following code block which indicated I was close to finding it:

if [ -x "$JAVA_HOME/bin/java" ]; then
    JAVA="$JAVA_HOME/bin/java"
else
    JAVA=`which java`
fi

if [ ! -x "$JAVA" ]; then
    echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"
    exit 1
fi

if [ -z "$ES_CLASSPATH" ]; then
    echo "You must set the ES_CLASSPATH var" >&2
    exit 1
fi

At the top of this file under where it says CONTROLLING STARTUP I found several Java variables so I knew I was close to finding the JAVA_HOME environment variable:

#   ES_CLASSPATH -- A Java classpath containing everything necessary to run.
#   JAVA_OPTS    -- Additional arguments to the JVM for heap size, etc
#   ES_JAVA_OPTS -- External Java Opts on top of the defaults set

Further down in the file I saw:

# Any serious use-case though will likely require customization of the
# include. For production installations, it is recommended that you copy
# the sample to one of /usr/share/elasticsearch/elasticsearch.in.sh,
# /usr/local/share/elasticsearch/elasticsearch.in.sh, or
# /opt/elasticsearch/elasticsearch.in.sh and make your modifications there.

I ran ls -al on /usr/share/elasticsearch/bin and saw the file elasticsearch.in.sh and found the entry I needed to fix: JAVA_HOME=/usr/lib/jvm/java-oracle. I modified it to JAVA_HOME=/bin/java, saved the file, and restarted both elasticsearch nodes in the cluster.

For some reason the elasticsearch daemon executed /usr/bin/java, but through a series of symolic links, it still executes the Java binary we need at the path we need, /usr/lib/jvm/java-1.8.0-oracle-1.8.0.151-1jpp.5.el7.x86_64/jre/bin/java:

[root@liferayhost1]  ps -ef | grep elastic
elastic+  96919      1 74 15:04 ?        00:00:15 /usr/bin/java -Xms12g -Xmx12g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/usr/share/elasticsearch -cp /usr/share/elasticsearch/lib/elasticsearch-2.4.6.jar:/usr/share/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch start -Des.pidfile=/var/run/elasticsearch/elasticsearch.pid -Des.default.path.home=/usr/share/elasticsearch -Des.default.path.logs=/var/log/elasticsearch -Des.default.path.data=/usr/local/liferay/elasticsearch/var -Des.default.path.conf=/etc/elasticsearch
root      97041  91410  0 15:04 pts/43   00:00:00 grep --color=auto elastic
[root@portaltest2 bin] ls -al /usr/bin/java
lrwxrwxrwx. 1 root root 22 Jun 28  2018 /usr/bin/java -> /etc/alternatives/java
[root@portaltest2 bin] ls -al /etc/alternatives/java
lrwxrwxrwx. 1 root root 71 Jun 28  2018 /etc/alternatives/java -> **/usr/lib/jvm/java-1.8.0-oracle-1.8.0.151-1jpp.5.el7.x86_64/jre/bin/java**
[root@portaltest2 bin] ls -al /bin/java
lrwxrwxrwx. 1 root root 22 Jun 28  2018 /bin/java -> /etc/alternatives/java

I'm satisfied that we've modified the JAVA_HOME environment variable in the include file at /usr/share/elasticsearch/bin/elasticsearch.in.sh used by the file /usr/share/elasticsearch/bin/elasticsearch to start Elasticsearch 2.4.6 with Java. Thank you!

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