如何诊断更改 JVM 选项后无法启动 jenkins?

How do I diagnose failure to start jenkins after changing JVM options?

我正在尝试为 jenkins 设置一些 JVM,以便我可以根据此处的建议四处查看垃圾收集日志

我的 jenkins 服务器在亚马逊 linux 的 EC2 上运行,所以我在 /etc/sysconfig/jenkins 处编辑了配置文件,包括:

JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -XX:+AlwaysPreTouch -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/jenkins -XX:+UseG1GC -XX:+UseStringDeduplication -XX:+ParallelRefProcEnabled -XX:+DisableExplicitGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -verbose:gc -Xloggc:/var/log/jenkins/gc.log -XX:NumberOfGCLogFiles=2 -XX:+UseGCLogFileRotation -XX:GCLogFileSize=100m -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintHeapAtGC -XX:+PrintGCCause -XX:+PrintTenuringDistribution -XX:+PrintReferenceGC -XX:+PrintAdaptiveSizePolicy -XX:ErrorFile=/var/log/jenkins/hs_err_%p.log -XX:+LogVMOutput -XX:LogFile=/var/log/jenkins/jvm.log"

但是当我重新启动服务时 (sudo systemctl restart jenkins.service),看起来它已经启动了:

[ec2-user@ip-10-0-0-30 ~]$ sudo systemctl status jenkins.service
● jenkins.service - LSB: Jenkins Automation Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
   Active: active (exited) since Mon 2021-11-08 18:49:28 UTC; 7s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 18318 ExecStop=/etc/rc.d/init.d/jenkins stop (code=exited, status=0/SUCCESS)
  Process: 20797 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=0/SUCCESS)

Nov 08 18:49:28 ip-10-0-0-30.ec2.internal systemd[1]: Starting LSB: Jenkins Automation Server...
Nov 08 18:49:28 ip-10-0-0-30.ec2.internal jenkins[20797]: Starting Jenkins [  OK  ]
Nov 08 18:49:28 ip-10-0-0-30.ec2.internal systemd[1]: Started LSB: Jenkins Automation Server.

我通常希望看到“活动:活动 (运行)” 我无法访问它(端口 8080 上的连接被拒绝),并且 /var/log/jenkins/jenkins.log

中没有新的日志消息

None 个其他日志文件创建于:

[ec2-user@ip-10-0-0-30 ~]$ sudo ls -la /var/log/jenkins
total 5856
drwxr-x--- 2 jenkins jenkins     242 Nov  4 11:17 .
drwxr-xr-x 9 root    root       4096 Nov  8 03:45 ..
-rw-r--r-- 1 jenkins jenkins 2007179 Nov  8 17:29 jenkins.log
-rw-r--r-- 1 jenkins jenkins  312046 Oct 15 03:40 jenkins.log-20211015.gz
-rw-r--r-- 1 jenkins jenkins  546457 Oct 23 03:36 jenkins.log-20211023.gz
-rw-r--r-- 1 jenkins jenkins  352006 Oct 28 03:09 jenkins.log-20211028.gz
...

还有什么地方可以查明服务未启动的原因?

更新:一组更小的可行选项:

JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -XX:+UseG1GC -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -XX:+ParallelRefProcEnabled -XX:+DisableExplicitGC"

原来cloudbeespost推荐的很多选项都是Java8特有的,与Java11不兼容。基于this blog post ,我使用以下 JVM 选项让它工作:

JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -XX:+AlwaysPreTouch -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/jenkins/ -XX:+UseG1GC -XX:+UseStringDeduplication -XX:+ParallelRefProcEnabled -XX:+DisableExplicitGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xlog:gc*,gc+heap=trace,gc+age*=trace,gc+ref*=trace,gc+ergo*=trace:file=/var/log/jenkins/gc-%t.log:utctime:filecount=2,filesize=100m -XX:ErrorFile=/var/log/jenkins/hs_err_%p.log -XX:+LogVMOutput -XX:LogFile=/var/log/jenkins/hs_%p.log"