TL;DR
JAVA_HOME
By the way, ** Logstash does not bundle OpenJDK **.
When I installed Elasticsearch on CentOS with yum
, I suddenly noticed that it was running with the JDK that I had inside the installed package.
When I read the docs, it seems that OpenJDK is bundled.
Install Elasticsearch with RPM
Elasticsearch includes a bundled version of OpenJDK from the JDK maintainers (GPLv2+CE). To use your own version of Java, see the JVM version requirements
I want to start from 7.0.
Release Notes/ Elasticsearch version 7.0.0
Bundle java in distributions
Looking at the Pull Request, it seems that you didn't like the hassle of setup and the problems caused by the environment with the old JDK.
If you want to use your own JDK, you can specify it in the environment variable JAVA_HOME
.
Set a custom Java path to be used.
The bundled Java Development Kit used to run Elasticsearch. Can be overriden by setting the JAVA_HOME environment variable in /etc/sysconfig/elasticsearch
Let's actually check it.
Click here for this environment.
$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
First, try installing Elasticsearch according to the documentation.
Install Elasticsearch with RPM
$ sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
$ sudo vim /etc/yum.repos.d/elasticsearch.repo
$ sudo yum install --enablerepo=elasticsearch elasticsearch
Click here for the contents of the created /etc/yum.repos.d/elasticsearch.repo
.
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
Start Elasticsearch.
$ sudo systemctl start elasticsearch
Now let's take a look at the Java used to launch Elasticsearch.
$ ps -ef | grep java | grep -v grep
elastic+ 24025 1 39 05:49 ? 00:00:23 /usr/share/elasticsearch/jdk/bin/java -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dio.netty.allocator.numDirectArenas=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.locale.providers=COMPAT -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Djava.io.tmpdir=/tmp/elasticsearch-5336255756681085720 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/lib/elasticsearch -XX:ErrorFile=/var/log/elasticsearch/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=/var/log/elasticsearch/gc.log:utctime,pid,tags:filecount=32,filesize=64m -XX:MaxDirectMemorySize=536870912 -Des.path.home=/usr/share/elasticsearch -Des.path.conf=/etc/elasticsearch -Des.distribution.flavor=default -Des.distribution.type=rpm -Des.bundled_jdk=true -cp /usr/share/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch -p /var/run/elasticsearch/elasticsearch.pid --quiet
It runs on Java bundled with Elasticsearch.
It looks like the AdoptOpenJDK is bundled.
$ /usr/share/elasticsearch/jdk/bin/java --version
openjdk 13.0.1 2019-10-15
OpenJDK Runtime Environment AdoptOpenJDK (build 13.0.1+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 13.0.1+9, mixed mode, sharing)
Moreover, 13 ...
Although it is supported, some people may want to use LTS OpenJDK.
Support Matrix / Product and JVM
Now, switch to the OpenJDK you installed yourself instead of the bundled AdoptOpenJDK.
Install OpenJDK by yourself.
$ sudo yum install java-11-openjdk-devel
$ java --version
openjdk 11.0.5 2019-10-15 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.5+10-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode, sharing)
This OpenJDK cannot be used by Elasticsearch as it is, so change the settings.
Look here and let's specify JAVA_HOME
as / usr / lib / jvm / java-11-openjdk
.
$ ll /usr/lib/jvm
total 0
lrwxrwxrwx. 1 root root 26 Dec 13 06:00 java -> /etc/alternatives/java_sdk
lrwxrwxrwx. 1 root root 29 Dec 13 06:00 java-11 -> /etc/alternatives/java_sdk_11
lrwxrwxrwx. 1 root root 37 Dec 13 06:00 java-11-openjdk -> /etc/alternatives/java_sdk_11_openjdk
drwxr-xr-x. 8 root root 97 Dec 13 06:00 java-11-openjdk-11.0.5.10-0.el7_7.x86_64
lrwxrwxrwx. 1 root root 34 Dec 13 06:00 java-openjdk -> /etc/alternatives/java_sdk_openjdk
lrwxrwxrwx. 1 root root 21 Dec 13 06:00 jre -> /etc/alternatives/jre
lrwxrwxrwx. 1 root root 24 Dec 13 06:00 jre-11 -> /etc/alternatives/jre_11
lrwxrwxrwx. 1 root root 32 Dec 13 06:00 jre-11-openjdk -> /etc/alternatives/jre_11_openjdk
lrwxrwxrwx. 1 root root 40 Dec 13 06:00 jre-11-openjdk-11.0.5.10-0.el7_7.x86_64 -> java-11-openjdk-11.0.5.10-0.el7_7.x86_64
lrwxrwxrwx. 1 root root 29 Dec 13 06:00 jre-openjdk -> /etc/alternatives/jre_openjdk
Set / etc / sysconfig / elasticsearch
.
# Elasticsearch Java path
#JAVA_HOME=
Set the Java you want to use in JAVA_HOME
.
# Elasticsearch Java path
JAVA_HOME=/usr/lib/jvm/java-11-openjdk
Restart Elasticsearch.
$ sudo systemctl restart elasticsearch
Now you can use the OpenJDK you installed yourself.
$ ps -ef | grep java | grep -v grep
elastic+ 24695 1 83 06:08 ? 00:00:23 /usr/lib/jvm/java-11-openjdk/bin/java -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dio.netty.allocator.numDirectArenas=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.locale.providers=COMPAT -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Djava.io.tmpdir=/tmp/elasticsearch-586651067490676884 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/lib/elasticsearch -XX:ErrorFile=/var/log/elasticsearch/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=/var/log/elasticsearch/gc.log:utctime,pid,tags:filecount=32,filesize=64m -XX:MaxDirectMemorySize=536870912 -Des.path.home=/usr/share/elasticsearch -Des.path.conf=/etc/elasticsearch -Des.distribution.flavor=default -Des.distribution.type=rpm -Des.bundled_jdk=true -cp /usr/share/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch -p /var/run/elasticsearch/elasticsearch.pid --quiet