You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Elasticsearch启动失败:无法创建Java虚拟机求助解决方向

Elasticsearch 7.17启动失败解决指南

环境信息

  • 系统:Ubuntu 18.04.4 LTS
  • 应用:Ruby on Rails 6.0.3(Ruby 2.6.3)生产环境
  • Elasticsearch版本:7.17
  • 问题:执行sudo systemctl start elasticsearch.service启动失败

错误日志

systemctl status elasticsearch.service输出

● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2023-11-14 15:46:10 UTC; 936ms ago
     Docs: https://www.elastic.co
  Process: 13188 ExecStart=/usr/share/elasticsearch/bin/systemd-entrypoint -p ${PID_DIR}/elasticsearch.pid --quiet (code=exited, status=1/FAILURE)
 Main PID: 13188 (code=exited, status=1/FAILURE)

Nov 14 15:46:10 appserver systemd-entrypoint[13188]: Error: Could not create the Java Virtual Machine.
Nov 14 15:46:10 appserver systemd-entrypoint[13188]: Error: A fatal exception has occurred. Program will exit.
Nov 14 15:46:10 appserver systemd-entrypoint[13188]:         at org.elasticsearch.tools.launchers.JvmOption.flagsFinal(JvmOption.java:119)
Nov 14 15:46:10 appserver systemd-entrypoint[13188]:         at org.elasticsearch.tools.launchers.JvmOption.findFinalOptions(JvmOption.java:81)
Nov 14 15:46:10 appserver systemd-entrypoint[13188]:         at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:38)
Nov 14 15:46:10 appserver systemd-entrypoint[13188]:         at org.elasticsearch.tools.launchers.JvmOptionsParser.jvmOptions(JvmOptionsParser.java:135)
Nov 14 15:46:10 appserver systemd-entrypoint[13188]:         at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:86)
Nov 14 15:46:10 appserver systemd[1]: elasticsearch.service: Main process exited, code=exited, status=1/FAILURE
Nov 14 15:46:10 appserver systemd[1]: elasticsearch.service: Failed with result 'exit-code'.
Nov 14 15:46:10 appserver systemd[1]: Failed to start Elasticsearch.

journalctl -xe输出

-- Unit elasticsearch.service has begun starting up.
Nov 14 16:22:21 appserver systemd-entrypoint[16564]: Exception in thread "main" java.lang.RuntimeException: starting java failed with [1]
Nov 14 16:22:21 appserver systemd-entrypoint[16564]: output:
Nov 14 16:22:21 appserver systemd-entrypoint[16564]: error:
Nov 14 16:22:21 appserver systemd-entrypoint[16564]: Unrecognized VM option 'UseConcMarkSweepGC'
Nov 14 16:22:21 appserver systemd-entrypoint[16564]: Error: Could not create the Java Virtual Machine.
Nov 14 16:22:21 appserver systemd-entrypoint[16564]: Error: A fatal exception has occurred. Program will exit.
Nov 14 16:22:21 appserver systemd-entrypoint[16564]:         at org.elasticsearch.tools.launchers.JvmOption.flagsFinal(JvmOption.java:119)
Nov 14 16:22:21 appserver systemd-entrypoint[16564]:         at org.elasticsearch.tools.launchers.JvmOption.findFinalOptions(JvmOption.java:81)
Nov 14 16:22:21 appserver systemd-entrypoint[16564]:         at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:38)
Nov 14 16:22:21 appserver systemd-entrypoint[16564]:         at org.elasticsearch.tools.launchers.JvmOptionsParser.jvmOptions(JvmOptionsParser.java:135)
Nov 14 16:22:21 appserver systemd-entrypoint[16564]:         at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:86)
Nov 14 16:22:21 appserver systemd[1]: elasticsearch.service: Main process exited, code=exited, status=1/FAILURE
Nov 14 16:22:21 appserver systemd[1]: elasticsearch.service: Failed with result 'exit-code'.
Nov 14 16:22:21 appserver systemd[1]: Failed to start Elasticsearch.
-- Subject: Unit elasticsearch.service has failed

当前jvm.options配置

################################################################
## IMPORTANT: JVM heap size
################################################################
##
-Xms8g
-Xmx8g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/7.17/heap-size.html
## for more information
##
################################################################


################################################################
## Expert settings
################################################################


## GC configuration
-XX:+UseConcMarkSweepGC
-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 unless an alternative path is
# specified
-XX:+HeapDumpOnOutOfMemoryError

# exit right after heap dump on out of memory error. Recommended to also use
# on java 8 for supported versions (8u92+).
9-:-XX:+ExitOnOutOfMemoryError

# specify an alternative path for heap dumps; ensure the directory exists and
# has sufficient space
-XX:HeapDumpPath=/var/lib/elasticsearch

# specify an alternative path for JVM fatal error logs
-XX:ErrorFile=/var/log/elasticsearch/gc.log

## JDK 8 GC logging
8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:/var/log/elasticsearch/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=/var/log/elasticsearch/gc.log:utctime,pid,tags:filecount=32,filesize=64m

问题原因

日志明确指出Unrecognized VM option 'UseConcMarkSweepGC',说明当前服务器安装的JDK版本不支持CMS垃圾收集器:

  • CMS GC在JDK 9中被标记为废弃,JDK 14及以上版本完全移除了该选项
  • 当前jvm.options默认启用了CMS GC配置,但服务器JDK版本高于13,导致JVM启动失败

解决步骤

  1. 确认JDK版本
    执行命令查看当前JDK版本:

    java -version
    
  2. 修改jvm.options配置
    编辑Elasticsearch的JVM配置文件(默认路径/etc/elasticsearch/jvm.options):

    • 注释掉CMS GC相关配置:
      #-XX:+UseConcMarkSweepGC
      #-XX:CMSInitiatingOccupancyFraction=75
      #-XX:+UseCMSInitiatingOccupancyOnly
      
    • 根据JDK版本启用对应G1GC配置:
      • 若JDK版本为10-13:
        10-13:-XX:-UseConcMarkSweepGC
        10-13:-XX:-UseCMSInitiatingOccupancyOnly
        
      • 若JDK版本为14及以上:
        14-:-XX:+UseG1GC
        14-:-XX:G1ReservePercent=25
        14-:-XX:InitiatingHeapOccupancyPercent=30
        
  3. 重启Elasticsearch
    执行命令重启服务:

    sudo systemctl restart elasticsearch.service
    
  4. 验证启动状态
    检查服务是否正常运行:

    systemctl status elasticsearch.service
    

内容的提问来源于stack exchange,提问作者John Coday

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 11:33:10