elasticsearch 错误:初始堆大小无效

问题描述 投票:0回答:1

我在linux系统上安装了elasticsearch

elasticsearch-8.13.0-amd64.deb
Debian GNU/Linux 12 (bookworm)
参考文档手动下载并安装Debian包

然后启动成功。

root@localhost:~# sudo systemctl status --no-pager --full elasticsearch.service
● elasticsearch.service - Elasticsearch
     Loaded: loaded (/lib/systemd/system/elasticsearch.service; enabled; preset: enabled)
     Active: active (running) since Sun 2024-04-21 14:51:02 CST; 3min 37s ago
       Docs: https://www.elastic.co
   Main PID: 2847856 (java)
      Tasks: 75 (limit: 9321)
     Memory: 4.2G
        CPU: 52.155s
     CGroup: /system.slice/elasticsearch.service
             ├─2847856 /usr/share/elasticsearch/jdk/bin/java -Xms4m -Xmx64m -XX:+UseSerialGC -Dcli.name=server -Dcli.script=/usr/share/elasticsearch/bin/elasticsearch -Dcli.libs=lib/tools/server-cli -Des.path.home=/usr/share/elasticsearch -Des.path.conf=/etc/elasticsearch -Des.distribution.type=deb -cp "/usr/share/elasticsearch/lib/*:/usr/share/elasticsearch/lib/cli-launcher/*" org.elasticsearch.launcher.CliToolLauncher -p /var/run/elasticsearch/elasticsearch.pid --quiet
             ├─2847935 /usr/share/elasticsearch/jdk/bin/java -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -Djava.security.manager=allow -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 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j2.formatMsgNoLookups=true -Djava.locale.providers=SPI,COMPAT --add-opens=java.base/java.io=org.elasticsearch.preallocate --enable-native-access=org.elasticsearch.nativeaccess -XX:ReplayDataFile=/var/log/elasticsearch/replay_pid%p.log -Des.distribution.type=deb -XX:+UseG1GC -Djava.io.tmpdir=/tmp/elasticsearch-3162753593522312160 --add-modules=jdk.incubator.vector -XX:+HeapDumpOnOutOfMemoryError -XX:+ExitOnOutOfMemoryError -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,level,pid,tags:filecount=32,filesize=64m" -Xms3906m -Xmx3906m -XX:MaxDirectMemorySize=2047868928 -XX:G1HeapRegionSize=4m -XX:InitiatingHeapOccupancyPercent=30 -XX:G1ReservePercent=15 --module-path /usr/share/elasticsearch/lib --add-modules=jdk.net --add-modules=ALL-MODULE-PATH -m org.elasticsearch.server/org.elasticsearch.bootstrap.Elasticsearch
             └─2847959 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller

Apr 21 14:50:44 localhost systemd[1]: Starting elasticsearch.service - Elasticsearch...
Apr 21 14:50:47 localhost systemd-entrypoint[2847856]: Apr 21, 2024 2:50:47 AM sun.util.locale.provider.LocaleProviderAdapter <clinit>
Apr 21 14:50:47 localhost systemd-entrypoint[2847856]: WARNING: COMPAT locale provider will be removed in a future release
Apr 21 14:51:02 localhost systemd[1]: Started elasticsearch.service - Elasticsearch.

但是当我修改jvm堆大小时出现错误并且无法启动。

我创建了文件

/etc/elasticsearch/jvm.options.d/jvm.options
,并写道:

-Xms1G 
-Xmx1G

停止并重新启动后:

# sudo systemctl stop elasticsearch.service
# sudo systemctl start elasticsearch.service
# sudo journalctl --no-pager --full --unit elasticsearch

出现以下错误:

Apr 21 14:59:17 localhost systemd[1]: Starting elasticsearch.service - Elasticsearch...
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]: Exception in thread "main" java.lang.RuntimeException: starting java failed with [1]
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]: output:
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]: error:
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]: Invalid initial heap size: -Xms1G
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]: Error: Could not create the Java Virtual Machine.
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]: Error: A fatal exception has occurred. Program will exit.
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]:         at org.elasticsearch.server.cli.JvmOption.flagsFinal(JvmOption.java:120)
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]:         at org.elasticsearch.server.cli.JvmOption.findFinalOptions(JvmOption.java:87)
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]:         at org.elasticsearch.server.cli.MachineDependentHeap.determineHeapSettings(MachineDependentHeap.java:59)
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]:         at org.elasticsearch.server.cli.JvmOptionsParser.jvmOptions(JvmOptionsParser.java:141)
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]:         at org.elasticsearch.server.cli.JvmOptionsParser.determineJvmOptions(JvmOptionsParser.java:92)
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]:         at org.elasticsearch.server.cli.ServerCli.startServer(ServerCli.java:248)
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]:         at org.elasticsearch.server.cli.ServerCli.execute(ServerCli.java:100)
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]:         at org.elasticsearch.common.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:54)
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]:         at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:85)
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]:         at org.elasticsearch.cli.Command.main(Command.java:50)
Apr 21 14:59:19 localhost systemd-entrypoint[2850142]:         at org.elasticsearch.launcher.CliToolLauncher.main(CliToolLauncher.java:64)
Apr 21 14:59:19 localhost systemd[1]: elasticsearch.service: Main process exited, code=exited, status=1/FAILURE
Apr 21 14:59:19 localhost systemd[1]: elasticsearch.service: Failed with result 'exit-code'.
Apr 21 14:59:19 localhost systemd[1]: Failed to start elasticsearch.service - Elasticsearch.
Apr 21 14:59:19 localhost systemd[1]: elasticsearch.service: Consumed 3.280s CPU time.

我尝试将其设置为

1G
2G
4G
,但无法正常工作。

只有不设置才能正常启动。

我做错了什么?

linux elasticsearch
1个回答
0
投票

最后发现问题是换行格式导致的。

我以前使用Windows系统保存文件。使用

vim
重新保存文件解决了问题。

© www.soinside.com 2019 - 2024. All rights reserved.