安装ElasticSearch使用自带JDK

时间:2024-10-30 12:59:03

平时用jdk8,但运行es7无法启动。在elasticsearch7以上的版本中会自带jdk.
需要修改elasticsearch-env配置文件,就可以使用自带jdk版本,不影响其他java项目。

future versions of Elasticsearch will require Java 11; your Java version from [d:\Program Files\java\jdk1.8.0_91\jre] does not meet this requirement

linux

 39 if [ ! -z "$JAVA_HOME" ]; then
 40   JAVA="$JAVA_HOME/bin/java"
 41   JAVA_TYPE="JAVA_HOME"
 42 else
 43   if [ "$(uname -s)" = "Darwin" ]; then
 44     # macOS has a different structure
 45     JAVA="$ES_HOME//Contents/Home/bin/java"
 46   else
 47     JAVA="$ES_HOME/jdk/bin/java"
 48   fi
 49   JAVA_TYPE="bundled jdk"
 50 fi

修改成

  if [ "$(uname -s)" = "Darwin" ]; then
    # macOS has a different structure
    JAVA="$ES_HOME//Contents/Home/bin/java"
  else
    JAVA="$ES_HOME/jdk/bin/java"
  fi
  JAVA_TYPE="bundled jdk"

windows
打开 文件:

if defined JAVA_HOME (
  set JAVA="%JAVA_HOME%\bin\"
) else (
  set JAVA="%ES_HOME%\jdk\bin\"
  set JAVA_HOME="%ES_HOME%\jdk"
)

修改成

set JAVA="%ES_HOME%\jdk\bin\" 
set JAVA_HOME="%ES_HOME%\jdk" 

然后就可以启动了。最后又出现如下问题

OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.

打开
修改 (大概在35行)

8-13:-XX:+UseConcMarkSweepGC
8-13:-XX:CMSInitiatingOccupancyFraction=75
8-13:-XX:+UseCMSInitiatingOccupancyOnly

改成

8-13:-XX:+UseG1GC
8-13:-XX:CMSInitiatingOccupancyFraction=75
8-13:-XX:+UseCMSInitiatingOccupancyOnly

最后可以启动了。