通过rpm安装Jenkins后进行启动
使用systemctl start jenkins.service
启动Jenkins时提示:
Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details.
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 Tue 2022-05-24 11:40:22 CST; 2min 27s ago
Docs: man:systemd-sysv-generator(8)
Process: 3912 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=1/FAILURE)
May 24 11:40:22 VM-4-13-centos systemd[1]: Starting LSB: Jenkins Automation Server...
May 24 11:40:22 VM-4-13-centos runuser[3918]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
May 24 11:40:22 VM-4-13-centos jenkins[3912]: Starting Jenkins bash: /usr/bin/java: No such file or directory
May 24 11:40:22 VM-4-13-centos runuser[3918]: pam_unix(runuser:session): session closed for user jenkins
May 24 11:40:22 VM-4-13-centos jenkins[3912]: [FAILED]
May 24 11:40:22 VM-4-13-centos systemd[1]: jenkins.service: control process exited, code=exited status=1
May 24 11:40:22 VM-4-13-centos systemd[1]: Failed to start LSB: Jenkins Automation Server.
May 24 11:40:22 VM-4-13-centos systemd[1]: Unit jenkins.service entered failed state.
May 24 11:40:22 VM-4-13-centos systemd[1]: jenkins.service failed.
Jenkins启动时需要Jdk环境,返回信息中提示无法找到/usr/bin/java
文件或目录。
查阅相关资料发现Jenkins在没有修改配置文件时启动,会默认去找指定目录下的Java执行文件。
解决方案分为两种,选取其中一种即可解决问题。
方式一:通过命令安装Jdk,这里使用的是yum进行安装。
yum install java-1.8.0-openjdk* -y
方式二: 自定义安装的Jdk安装后需要进行相应处理
处理方式同样分为两种,选取其中一种即可解决问题。
/etc/init.d/jenkins
,让Jenkins识别到安装的Java执行文件。vi /etc/init.d/jenkins
在candidates中添加自定义安装的Jdk路径candidates="
/etc/alternatives/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/lib/jvm/java-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/lib/jvm/java-11.0/bin/java
/usr/lib/jvm/jre-11.0/bin/java
/usr/lib/jvm/java-11-openjdk-amd64
/usr/bin/java
# Jdk目录下bin/java文件
/usr/local/jdk1.8/bin/java
"
ln -s Jdk目录下bin/java文件 /usr/bin/java