记录坑位:
问题描述:gerrit-2.16.2无法启动
gerrit@100ask:~/review_site/logs$ sudo ~/review_site/bin/gerrit.sh restart
Stopping Gerrit Code Review: start-stop-daemon: warning: failed to kill 11350: No such process
1 pids were not killed
No process in pidfile '/home/gerrit/review_site/logs/gerrit.pid' found running; none killed.
OK
Starting Gerrit Code Review: FAILED
gerrit@100ask:~/review_site/logs$
解决方案:
(1)首先打印出错log信息,log位置如下:
gerrit@100ask:~/review_site/logs$ ls
error_log gc_log gerrit.pid gerrit.run httpd_log sshd_log
备注:review_site是我的gerrit安装目录
执行命令:cat error_log
[2020-11-04 03:33:09,975] [main] INFO com.google.gerrit.server.git.WorkQueue : Adding metrics for 'SshCommandStart' queue
[2020-11-04 03:33:10,258] [main] WARN com.google.gerrit.sshd.SshDaemon : Cannot format SSHD host key [EdDSA]: invalid key type
[2020-11-04 03:33:10,259] [main] INFO com.google.gerrit.server.git.WorkQueue : Adding metrics for 'SSH-Stream-Worker' queue
[2020-11-04 03:33:10,260] [main] INFO com.google.gerrit.server.git.WorkQueue : Adding metrics for 'SSH-Interactive-Worker' queue
[2020-11-04 03:33:10,261] [main] INFO com.google.gerrit.server.git.WorkQueue : Adding metrics for 'SSH-Batch-Worker' queue
[2020-11-04 03:33:10,976] [main] INFO org.eclipse.jetty.util.log : Logging initialized @6742ms to org.eclipse.jetty.util.log.Slf4jLog
[2020-11-04 03:33:11,042] [main] ERROR com.google.gerrit.pgm.Daemon : Unable to start daemon
java.lang.reflect.InaccessibleObjectException: Unable to make public long com.sun.management.internal.OperatingSystemImpl.getProcessCpuTime() accessible: module jdk.management does not "opens com.sun.management.internal" to unnamed module @407a7f2a
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:340)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:280)
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:198)
at java.base/java.lang.reflect.Method.setAccessible(Method.java:192)
at com.google.gerrit.metrics.proc.OperatingSystemMXBeanProvider.<init>(OperatingSystemMXBeanProvider.java:55)
at com.google.gerrit.metrics.proc.OperatingSystemMXBeanProvider.<init>(OperatingSystemMXBeanProvider.java:23)
at com.google.gerrit.metrics.proc.OperatingSystemMXBeanProvider$Factory.create(OperatingSystemMXBeanProvider.java:40)
at com.google.gerrit.metrics.proc.ProcMetricModule.procCpuUsage(ProcMetricModule.java:67)
at com.google.gerrit.metrics.proc.ProcMetricModule.configure(ProcMetricModule.java:40)
at com.google.gerrit.metrics.proc.MetricModule$1.start(MetricModule.java:36)
at com.google.gerrit.lifecycle.LifecycleManager.start(LifecycleManager.java:95)
at com.google.gerrit.pgm.Daemon.start(Daemon.java:364)
at com.google.gerrit.pgm.Daemon.run(Daemon.java:268)
at com.google.gerrit.pgm.util.AbstractProgram.main(AbstractProgram.java:61)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.google.gerrit.launcher.GerritLauncher.invokeProgram(GerritLauncher.java:226)
at com.google.gerrit.launcher.GerritLauncher.mainImpl(GerritLauncher.java:122)
at com.google.gerrit.launcher.GerritLauncher.main(GerritLauncher.java:66)
at Main.main(Main.java:28)
从log中可以看出问题在于:
[2020-11-04 03:33:11,042] [main] ERROR com.google.gerrit.pgm.Daemon : Unable to start daemon
java.lang.reflect.InaccessibleObjectException: Unable to make public long com.sun.management.internal.OperatingSystemImpl.getProcessCpuTime() accessible: module jdk.management does not "opens com.sun.management.internal" to unnamed module @407a7f2a
(2)查看本地java版本:
gerrit@100ask:~/review_site/logs$ java --version
openjdk 11.0.9 2020-10-20
OpenJDK Runtime Environment (build 11.0.9+11-Ubuntu-0ubuntu1.18.04.1)
OpenJDK 64-Bit Server VM (build 11.0.9+11-Ubuntu-0ubuntu1.18.04.1, mixed mode)
gerrit@100ask:~/review_site/logs$
本地JDK为11.0.9,经过谷歌后发现,是java版本过高导致,具体可以参考此贴。
(3)查看本地安装的java环境
gerrit@100ask:~/review_site/logs$ ls /usr/lib/jvm/
default-java java-1.11.0-openjdk-amd64 java-11-openjdk-amd64 java-1.8.0-openjdk-amd64 java-8-openjdk-amd64
gerrit@100ask:~/review_site/logs$
我本地安装了java-8-openjdk,因此只需要修改文件gerrit.config中的javaHome变量,如下所示 ,gerrit.config的位置:/home/gerrit/review_site/etc
[gerrit]
basePath = git
serverId = e76fdbdc-4672-4e8f-89b8-69dd856da8bc
canonicalWebUrl = http://192.168.8.191:8081/
[database]
type = h2
database = /home/gerrit/review_site/db/ReviewDB
[noteDb "changes"]
disableReviewDb = true
primaryStorage = note db
read = true
sequence = true
write = true
[container]
javaOptions = "-Dflogger.backend_factory=com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance"
javaOptions = "-Dflogger.logging_context=com.google.gerrit.server.logging.LoggingContext#getInstance"
user = gerrit
#修改此处为java-8-openjdk版本
javaHome = /usr/lib/jvm/java-8-openjdk-amd64
#javaHome = /usr/lib/jvm/java-11-openjdk-amd64
[index]
type = LUCENE
[auth]
type = HTTP
[receive]
enableSignedPush = false
[sendemail]
smtpServer = localhost
[sshd]
listenAddress = *:29418
[httpd]
listenUrl = proxy-http://*:8091/
[cache]
directory = cache
[gitweb]
type = gitweb
cgi = /usr/lib/cgi-bin/gitweb.cgi
(4)再次重启gerrit即可正常访问
sudo ~/review_site/bin/gerrit.sh restart
gerrit@100ask:~/review_site/etc$ sudo ~/review_site/bin/gerrit.sh restart
Stopping Gerrit Code Review: start-stop-daemon: warning: failed to kill 16095: No such process
1 pids were not killed
No process in pidfile '/home/gerrit/review_site/logs/gerrit.pid' found running; none killed.
OK
Starting Gerrit Code Review: OK
gerrit@100ask:~/review_site/etc$
界面如下:
附注
如果没有java-8-openjdk
的朋友,可以参考下述办法安装:
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jdk