Sonarqube 无法在 Ubuntu 后启动

Sonarqube can't be started in Ubuntu

当我尝试启动 sonarqube 时,出现以下错误。

--> Wrapper Started as Daemon
Launching a JVM...
Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
  Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.

2019.08.19 17:30:23 INFO  app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sonarqube/temp
2019.08.19 17:30:23 INFO  app[][o.s.a.es.EsSettings] Elasticsearch listening on /127.0.0.1:9001
2019.08.19 17:30:23 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[[key='es', ipcIndex=1, logFilenamePrefix=es]] from [/opt/sonarqube/elasticsearch]: /opt/sonarqube/elasticsearch/bin/elasticsearch
2019.08.19 17:30:23 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
2019.08.19 17:30:24 INFO  app[][o.e.p.PluginsService] no modules loaded
2019.08.19 17:30:24 INFO  app[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2019.08.19 17:30:41 WARN  app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [es]: 1
2019.08.19 17:30:41 INFO  app[][o.s.a.SchedulerImpl] Process[es] is stopped
2019.08.19 17:30:41 INFO  app[][o.s.a.SchedulerImpl] SonarQube is stopped
<-- Wrapper Stopped

我找不到解决这个问题的方法,我真的需要 运行 sonarqube 的帮助。我可能做错了什么,但我已经按照 sonarqube 文档进行了安装。

这是 es.log 文件

Server VM/11.0.4/11.0.4+11-post-Ubuntu-1ubuntu218.04.3]
2019.08.20 20:38:29 INFO  es[][o.e.n.Node] JVM arguments [-XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -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, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/opt/sonarqube/temp, -XX:ErrorFile=../logs/es_hs_err_pid%p.log, -Des.enforce.bootstrap.checks=true, -Xms512m, -Xmx512m, -Des.path.home=/opt/sonarqube/elasticsearch, -Des.path.conf=/opt/sonarqube/temp/conf/es, -Des.distribution.flavor=default, -Des.distribution.type=tar]
2019.08.20 20:38:30 INFO  es[][o.e.p.PluginsService] loaded module [analysis-common]
2019.08.20 20:38:30 INFO  es[][o.e.p.PluginsService] loaded module [lang-painless]
2019.08.20 20:38:30 INFO  es[][o.e.p.PluginsService] loaded module [mapper-extras]
2019.08.20 20:38:30 INFO  es[][o.e.p.PluginsService] loaded module [parent-join]
2019.08.20 20:38:30 INFO  es[][o.e.p.PluginsService] loaded module [percolator]
2019.08.20 20:38:30 INFO  es[][o.e.p.PluginsService] loaded module [reindex]
2019.08.20 20:38:30 INFO  es[][o.e.p.PluginsService] loaded module [repository-url]
2019.08.20 20:38:30 INFO  es[][o.e.p.PluginsService] loaded module [transport-netty4]
2019.08.20 20:38:30 INFO  es[][o.e.p.PluginsService] no plugins loaded
2019.08.20 20:38:34 WARN  es[][o.e.d.c.s.Settings] [http.enabled] setting was deprecated in Elasticsearch and will be removed in a future release! See the breaking changes documentation for the next major version.
2019.08.20 20:38:36 INFO  es[][o.e.d.DiscoveryModule] using discovery type [zen] and host providers [settings]
2019.08.20 20:38:36 INFO  es[][o.e.n.Node] initialized
2019.08.20 20:38:36 INFO  es[][o.e.n.Node] starting ...
2019.08.20 20:38:37 INFO  es[][o.e.t.TransportService] publish_address {127.0.0.1:9001}, bound_addresses {127.0.0.1:9001}
2019.08.20 20:38:37 INFO  es[][o.e.b.BootstrapChecks] explicitly enforcing bootstrap checks
2019.08.20 20:38:37 ERROR es[][o.e.b.Bootstrap] node validation exception
[1] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
2019.08.20 20:38:37 INFO  es[][o.e.n.Node] stopping ...
2019.08.20 20:38:37 INFO  es[][o.e.n.Node] stopped
2019.08.20 20:38:37 INFO  es[][o.e.n.Node] closing ...
2019.08.20 20:38:37 INFO  es[][o.e.n.Node] closed

Elasticsearch 未启动,查看日志:

2019.08.20 20:38:37 ERROR es[][o.e.b.Bootstrap] node validation exception
[1] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]

这是他们在 their doc 中所说的:

Elasticsearch uses a lot of file descriptors or file handles. Running out of file descriptors can be disastrous and will most probably lead to data loss. Make sure to increase the limit on the number of open files descriptors for the user running Elasticsearch to 65,536 or higher.

因此您需要提高限制:

For the .zip and .tar.gz packages, set ulimit -n 65535 as root before starting Elasticsearch, or set nofile to 65535 in /etc/security/limits.conf.

解决方案在 sonar.service 文件中,应该保留在 /etc/systemd/system.sonar.service

[Unit]
Description=SonarQube service
After=syslog.target network.target

[Service]
Type=simple
User=sonarqube
Group=sonarqube
PermissionsStartOnly=true
ExecStart=/bin/nohup /opt/java/bin/java -Xms32m -Xmx32m -Djava.net.preferIPv4Stack=true -jar /opt/sonarqube/lib/sonar-application-7.4.jar
StandardOutput=syslog
LimitNOFILE=65536
LimitNPROC=8192
TimeoutStartSec=5
Restart=always

[Install]
WantedBy=multi-user.target

您必须在服务上定义文件限制

您需要设置fs.file-max来增加最大文件描述符。

sysctl -w fs.file-max=65535

您可能还需要设置 vm.max-map-count

sysctl -w vm.max_map_count=262144