Jenkins在AWS EC2机器中更新后失败



我在AWS的EC2机器中安装了Jenkins。我尝试安装slack插件,它破坏了其他插件,所以我尝试更新Jenkins版本以使其再次工作,现在我无法事件启动它。我收到以下消息:

Starting jenkins (via systemctl):  Failed to start jenkins.service: Unit is not loaded properly: Invalid argument.
See system logs and 'systemctl status jenkins.service' for details.
[FAILED]

我还试图按照本指南完全删除Jenkins:然后按照AWS中的Jenkins指南重新安装它。但它仍然不起作用。在我做journalctl -xe的某个时候,我遇到了这个错误(我不记得我做了什么,但至少我保存了这个日志跟踪(:

Unit jenkins.service has begun starting up.
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: Sep 20, 2022 4:39:49 PM executable.Main verifyJavaVersion
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: SEVERE: Running with Java class version 52, which is older than
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: java.lang.UnsupportedClassVersionError: 52.0
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: at executable.Main.verifyJavaVersion(Main.java:145)
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: at executable.Main.main(Main.java:109)
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: Jenkins requires Java versions [17, 11] but you are running wit
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: java.lang.UnsupportedClassVersionError: 52.0
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: at executable.Main.verifyJavaVersion(Main.java:145)
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: at executable.Main.main(Main.java:109)
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal systemd[1]: Failed to start Jenkins Continuous Integration Server.
-- Subject: Unit jenkins.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit jenkins.service has failed.
--

因此,我认为我终于发现了错误,我检查了java版本,它显示的是java1.8。因此,我用alternatives --config java更改了它,并将其设置为:

java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64/bin/java)

我还将此路径添加到了/etc/rc.d/init.d/jenkins中。现在,当我得到java版本时,我得到的是:

openjdk version "11.0.16" 2022-07-19 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.16.0.8-1.amzn2.0.1) (build 11.0.16+8-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.16.0.8-1.amzn2.0.1) (build 11.0.16+8-LTS, mixed mode, sharing)

当我试图用systemctl status jenkins.service -l获得詹金斯的状态时,我得到了:

● jenkins.service
Loaded: error (Reason: Invalid argument)
Drop-In: /etc/systemd/system/jenkins.service.d
└─override.conf
Active: failed (Result: start-limit) since Tue 2022-09-20 16:39:49 UTC; 15h ago
Main PID: 23035 (code=exited, status=0/SUCCESS)
Sep 20 16:57:30 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 20 16:57:43 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 21 07:15:59 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 21 07:20:02 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 21 07:23:12 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 21 07:23:20 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 21 07:24:26 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 21 07:30:58 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 21 07:31:06 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 21 07:48:04 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.

当我使用journalctl -xe时,我得到:

-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit session-120.scope has finished starting up.
-- 
-- The start-up result is done.
Sep 21 07:40:01 ip-10-10-3-149.ec2.internal CROND[842]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Sep 21 07:41:28 ip-10-10-3-149.ec2.internal dhclient[3121]: XMT: Solicit on eth0, interval 131610ms.
Sep 21 07:43:39 ip-10-10-3-149.ec2.internal dhclient[3121]: XMT: Solicit on eth0, interval 118630ms.
Sep 21 07:45:38 ip-10-10-3-149.ec2.internal dhclient[3121]: XMT: Solicit on eth0, interval 121300ms.
Sep 21 07:46:59 ip-10-10-3-149.ec2.internal sshd[3483]: Received disconnect from 92.255.85.69 port 28784:
Sep 21 07:46:59 ip-10-10-3-149.ec2.internal sshd[3483]: Disconnected from 92.255.85.69 port 28784 [preaut
Sep 21 07:47:04 ip-10-10-3-149.ec2.internal dhclient[3075]: DHCPREQUEST on eth0 to 10.10.3.1 port 67 (xid
Sep 21 07:47:04 ip-10-10-3-149.ec2.internal dhclient[3075]: DHCPACK from 10.10.3.1 (xid=0x18dc5aad)
Sep 21 07:47:04 ip-10-10-3-149.ec2.internal NET[3542]: dhclient: Locked /run/dhclient/resolv.lock
Sep 21 07:47:04 ip-10-10-3-149.ec2.internal dhclient[3075]: bound to 10.10.3.149 -- renewal in 1618 secon
Sep 21 07:47:04 ip-10-10-3-149.ec2.internal ec2net[3561]: [get_meta] Querying IMDS for meta-data/network/
Sep 21 07:47:04 ip-10-10-3-149.ec2.internal ec2net[3562]: [get_meta] Getting token for IMDSv2.
Sep 21 07:47:04 ip-10-10-3-149.ec2.internal ec2net[3565]: [get_meta] Trying to get http://169.254.169.254
Sep 21 07:47:04 ip-10-10-3-149.ec2.internal ec2net[3570]: [remove_aliases] Removing aliases of eth0
Sep 21 07:47:39 ip-10-10-3-149.ec2.internal dhclient[3121]: XMT: Solicit on eth0, interval 116180ms.
Sep 21 07:48:03 ip-10-10-3-149.ec2.internal sudo[3947]:     root : TTY=pts/0 ; PWD=/root ; USER=root ; CO
Sep 21 07:48:03 ip-10-10-3-149.ec2.internal sudo[3947]: pam_unix(sudo:session): session opened for user r
Sep 21 07:48:03 ip-10-10-3-149.ec2.internal systemd[1]: Reloading.
Sep 21 07:48:04 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecSto
Sep 21 07:48:04 ip-10-10-3-149.ec2.internal sudo[3947]: pam_unix(sudo:session): session closed for user r
Sep 21 07:48:09 ip-10-10-3-149.ec2.internal sudo[4019]:     root : TTY=pts/0 ; PWD=/root ; USER=root ; CO
Sep 21 07:48:09 ip-10-10-3-149.ec2.internal sudo[4019]: pam_unix(sudo:session): session opened for user r
Sep 21 07:48:09 ip-10-10-3-149.ec2.internal sudo[4019]: pam_unix(sudo:session): session closed for user r

我也尝试过这里的解决方案。我不知道还能尝试什么。

更新:这就是我的jenkins单元的样子(systemctl-cat-jenkins(:

# /etc/systemd/system/jenkins.service
[Service]
Environment="JENKINS_PORT=8000"
# /etc/systemd/system/jenkins.service.d/override.conf
[Service]
Environment="JENKINS_PORT=8000"

根据日志,单元文件缺少启动和停止脚本,可由
systemctl cat jenkins确认
根据Jenkins的文档,systemd文件需要更改。复制并用文档中给出的单位文件覆盖单位文件可以解决这个问题。

最新更新