报错如下:
[root@localhost /]# systemctl status jenkins.service
● jenkins.service - LSB: Jenkins Automation Server
Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since 一 2022-02-21 15:27:10 CST; 7s ago
Docs: man:systemd-sysv-generator(8)
Process: 14141 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=1/FAILURE)
2月 21 15:27:10 localhost.localdomain systemd[1]: Starting LSB: Jenkins Automation Server…
2月 21 15:27:10 localhost.localdomain runuser[14146]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
2月 21 15:27:10 localhost.localdomain jenkins[14141]: Starting Jenkins bash: /usr/bin/java: 是一个目录
2月 21 15:27:10 localhost.localdomain jenkins[14141]: [失败]
2月 21 15:27:10 localhost.localdomain systemd[1]: jenkins.service: control process exited, code=exited status=1
2月 21 15:27:10 localhost.localdomain systemd[1]: Failed to start LSB: Jenkins Automation Server.
2月 21 15:27:10 localhost.localdomain systemd[1]: Unit jenkins.service entered failed state.
2月 21 15:27:10 localhost.localdomain systemd[1]: jenkins.service failed.
[root@localhost /]# vim /etc/rc.d/init.d/jenkins
这一看报错,明显java环境出了问题,找不到java了
检查java环境:
[root@localhost /]# systemctl daemon-reload
[root@localhost /]# systemctl restart jenkins
[root@localhost /]# systemctl status jenkins
● jenkins.service - LSB: Jenkins Automation Server
Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
Active: active (running) since 一 2022-02-21 15:30:38 CST; 6s ago
Docs: man:systemd-sysv-generator(8)
Process: 15485 ExecStop=/etc/rc.d/init.d/jenkins stop (code=exited, status=0/SUCCESS)
Process: 15507 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/jenkins.service
└─15528 /usr/local/jdk1.8.0_251/bin/java -Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -j…
2月 21 15:30:37 localhost.localdomain systemd[1]: Stopped LSB: Jenkins Automation Server.
2月 21 15:30:37 localhost.localdomain systemd[1]: Starting LSB: Jenkins Automation Server…
2月 21 15:30:37 localhost.localdomain runuser[15512]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
2月 21 15:30:38 localhost.localdomain systemd[1]: Started LSB: Jenkins Automation Server.
2月 21 15:30:38 localhost.localdomain jenkins[15507]: Starting Jenkins [ 确定 ]
最后一行添加自己安装的java路径(注:一定要写道jbin/java),保存退出
再次启动jenkins
systemctl restart jenkins
systemctl status jenkins
启动成功!
附上jenkins的各文件路径:
/usr/lib/jenkins/jenkins.war WAR包
/etc/sysconfig/jenkins 配置文件
/var/lib/jenkins/ 默认的家目录
/var/log/jenkins/jenkins.log 日志文件