1. jdk8版本启动elasticsearch 7报错解决办法
报错信息:
future versions of Elasticsearch will require Java 11; your Java version from [/opt/jdk1.8.0_211/jre] does not meet this requirement
解决办法(讲解):
由于Elasticsearch依赖于jdk,es和jdk有着对应的依赖关系。
具体可见:
https://www.elastic.co/cn/support/matrix
https://www.elastic.co/guide/en/elasticsearch/reference/7.2/setup.html
这里是说Elasticsearch该版本内置了JDK,而内置的JDK是当前推荐的JDK版本。当然如果你本地配置了JAVA_HOME那么ES就是优先使用配置的JDK启动ES。(言外之意,你不安装JDK一样可以启动,我试了可以的。)
ES推荐使用LTS版本的JDK(这里只是推荐,JDK8就不支持),如果你使用了一些不支持的JDK版本,ES会拒绝启动。
那么哪些版本的JDK支持LTS呢?https://www.oracle.com/technetwork/java/java-se-support-roadmap.html

根据启动信息我们看到Elasticsearch7.2推荐使用JDK11,并且从刚才的截图得知可以下载openjdk 11.
2.安装jdk11
jdk下载地址:https://www.oracle.com/java/technologies/javase-jdk11-downloads.html
[root@centos7 ~]# ls
jdk-11.0.8_linux-x64_bin.tar.gz
解压:
[root@centos7 ~]## tar -xzvf jdk-11.0.8_linux-x64_bin.tar.gz /use/local/
3.不改变原有jdk8环境,只elasticsearch 使用jdk11方法
由于我们日常的代码开发都是使用的JDK1.8,所以这里不会把JAVA_HOME配置成JDK11,我们只需更改Elasticsearch的启动文件,使它指向我们下载的JDK11.
修改配置文件
[root@centos7 bin]# pwd
/home/wx/elasticsearch-7.9.0/bin
[root@centos7 bin]# vi elasticsearch
添加以下几行内容
#配置自己的jdk11
export JAVA_HOME=/usr/local/jdk-11.0.8/
export PATH=$JAVA_HOME/bin:$PATH
#添加jdk判断
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="/usr/local/jdk-11.0.8//bin/java"
else
JAVA=`which java`
fi
4.elasticsearch文件全部内容
[root@centos7 bin]# cat elasticsearch
#!/bin/bash
# CONTROLLING STARTUP:
#
# This script relies on a few environment variables to determine startup
# behavior, those variables are:
#
# ES_PATH_CONF -- Path to config directory
# ES_JAVA_OPTS -- External Java Opts on top of the defaults set
#
# Optionally, exact memory values can be set using the `ES_JAVA_OPTS`. Example
# values are "512m", and "10g".
#
# ES_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/elasticsearch
#配置自己的jdk11
export JAVA_HOME=/usr/local/jdk-11.0.8
export PATH=$JAVA_HOME/bin:$PATH
#添加jdk判断
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="/usr/local/jdk-11.0.8/bin/java"
else
JAVA=`which java`
fi
source "`dirname "$0"`"/elasticsearch-env
CHECK_KEYSTORE=true
DAEMONIZE=false
for option in "$@"; do
case "$option" in
-h|--help|-V|--version)
CHECK_KEYSTORE=false
;;
-d|--daemonize)
DAEMONIZE=true
;;
esac
done
if [ -z "$ES_TMPDIR" ]; then
ES_TMPDIR=`"$JAVA" "$XSHARE" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.TempDirectory`
fi
# get keystore password before setting java options to avoid
# conflicting GC configurations for the keystore tools
unset KEYSTORE_PASSWORD
KEYSTORE_PASSWORD=
if [[ $CHECK_KEYSTORE = true ]]
&& bin/elasticsearch-keystore has-passwd --silent
then
if ! read -s -r -p "Elasticsearch keystore password: " KEYSTORE_PASSWORD ; then
echo "Failed to read keystore password on console" 1>&2
exit 1
fi
fi
# The JVM options parser produces the final JVM options to start Elasticsearch.
# It does this by incorporating JVM options in the following way:
# - first, system JVM options are applied (these are hardcoded options in the
# parser)
# - second, JVM options are read from jvm.options and jvm.options.d/*.options
# - third, JVM options from ES_JAVA_OPTS are applied
# - fourth, ergonomic JVM options are applied
ES_JAVA_OPTS=`export ES_TMPDIR; "$JAVA" "$XSHARE" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_PATH_CONF"`
# manual parsing to find out, if process should be detached
if [[ $DAEMONIZE = false ]]; then
exec
"$JAVA"
"$XSHARE"
$ES_JAVA_OPTS
-Des.path.home="$ES_HOME"
-Des.path.conf="$ES_PATH_CONF"
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR"
-Des.distribution.type="$ES_DISTRIBUTION_TYPE"
-Des.bundled_jdk="$ES_BUNDLED_JDK"
-cp "$ES_CLASSPATH"
org.elasticsearch.bootstrap.Elasticsearch
"$@" <<<"$KEYSTORE_PASSWORD"
else
exec
"$JAVA"
"$XSHARE"
$ES_JAVA_OPTS
-Des.path.home="$ES_HOME"
-Des.path.conf="$ES_PATH_CONF"
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR"
-Des.distribution.type="$ES_DISTRIBUTION_TYPE"
-Des.bundled_jdk="$ES_BUNDLED_JDK"
-cp "$ES_CLASSPATH"
org.elasticsearch.bootstrap.Elasticsearch
"$@"
<<<"$KEYSTORE_PASSWORD" &
retval=$?
pid=$!
[ $retval -eq 0 ] || exit $retval
if [ ! -z "$ES_STARTUP_SLEEP_TIME" ]; then
sleep $ES_STARTUP_SLEEP_TIME
fi
if ! ps -p $pid > /dev/null ; then
exit 1
fi
exit 0
fi
5.启动es提醒cms 垃圾收集器在 jdk9 就开始被标注为 @deprecated解决办法
警告信息:
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
解决办法(详解):
看下JDK11支持的垃圾回收器:https://docs.oracle.com/en/java/javase/11/gctuning/garbage-first-garbage-collector.html#GUID-CE6F94B6-71AF-45D5-829E-DEADD9BA929D

修改jvm.options
将 : -XX:+UseConcMarkSweepGC
改为:-XX:+UseG1GC 即可
6./home/wx/elasticsearch-7.9.0/config/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:
##
## -Xms4g
## -Xmx4g
##
## 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
-Xms2g
-Xmx2g
################################################################
## Expert settings
################################################################
##
## All settings below this section are considered
## expert settings. Don't tamper with them unless
## you understand what you are doing
##
################################################################
## GC configuration
## 原有的注释了,添加了G1回收器
#8-13:-XX:+UseConcMarkSweepGC
#8-13:-XX:CMSInitiatingOccupancyFraction=75
#8-13:-XX:+UseCMSInitiatingOccupancyOnly
-XX:+UseG1GC
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly
## G1GC Configuration
# NOTE: G1 GC is only supported on JDK version 10 or later
# to use G1GC, uncomment the next two lines and update the version on the
# following three lines to your version of the JDK
# 10-13:-XX:-UseConcMarkSweepGC
# 10-13:-XX:-UseCMSInitiatingOccupancyOnly
14-:-XX:+UseG1GC
14-:-XX:G1ReservePercent=25
14-:-XX:InitiatingHeapOccupancyPercent=30
## JVM temporary directory
-Djava.io.tmpdir=${ES_TMPDIR}
## heap dumps
# generate a heap dump when an allocation from the Java heap fails
# heap dumps are created in the working directory of the JVM
-XX:+HeapDumpOnOutOfMemoryError
# specify an alternative path for heap dumps; ensure the directory exists and
# has sufficient space
-XX:HeapDumpPath=data
# specify an alternative path for JVM fatal error logs
-XX:ErrorFile=logs/hs_err_pid%p.log
## JDK 8 GC logging
8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:logs/gc.log
8:-XX:+UseGCLogFileRotation
8:-XX:NumberOfGCLogFiles=32
8:-XX:GCLogFileSize=64m
# JDK 9+ GC logging
9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m
9-:-Djava.locale.providers=COMPAT
7.普通用户启动即可