Question
I have a CentOS server and I'm trying to run jenkins as a service with:
service jenkins start
I am running as root user and I'm getting this response:
Starting Jenkins bash: /usr/bin/java: No such file or directory [FAILED]
I have echo'ed a few things to the command line:
[root@xyz opt]# echo $JAVA_HOME
/opt/jdk
[root@xyz opt]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/opt/jdk/bin:/opt/grails/bin
[root@xyz opt]# java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
[root@xyz opt]# which java
/opt/jdk/bin/java
I cannot see any java configuration in any jenkins files. Any ideas?
我有一个CentOS服务器,我试图运行jenkins作为服务:
service jenkins start
我正在以root用户身份运行,并得到以下回复:
Starting Jenkins bash: /usr/bin/java: No such file or directory [FAILED]
我已经使用echo命令打印了一些到命令行:
[root@xyz opt]# echo $JAVA_HOME
/opt/jdk
[root@xyz opt]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/opt/jdk/bin:/opt/grails/bin
[root@xyz opt]# java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
[root@xyz opt]# which java
/opt/jdk/bin/java
我看不到任何jenkins文件中的任何Java配置。有什么主意吗?
Answer1
Try fix it by using:
ln -s /opt/jdk/bin/java /usr/bin/java
The script file who service utility is using is probably /etc/init.d/jenkins
You could edit this file too...
尝试使用以下方法修复它:
ln -s /opt/jdk/bin/java /usr/bin/java
服务实用程序正在使用的脚本文件可能是/etc/init.d/jenkins您也可以编辑此文件...
Answers2
Jenkins needs java to start and in your case in /usr/bin/ directory java is not available
If you go to /etc/init.d/ and open jenkins file you will find:
candidates="
/etc/alternatives/java
/usr/lib/jvm/java-1.6.0/bin/java
/usr/lib/jvm/jre-1.6.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-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/bin/java
"
These are the paths where jenkins looks for java, and in your case java was not present in any of the above paths.
So look for the path where you are having java and add that path in the above jenkins file.
Since you are having java in /opt/jdk/bin, then add this in jenkins file:
candidates="
/opt/jdk/bin/java <----Add here
/etc/alternatives/java
/usr/lib/jvm/java-1.6.0/bin/java
/usr/lib/jvm/jre-1.6.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-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/bin/java
"
如果你去/etc/init.d/打开jenkins文件,你会发现:
candidates="
/etc/alternatives/java
/usr/lib/jvm/java-1.6.0/bin/java
/usr/lib/jvm/jre-1.6.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-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/bin/java
"
这些是jenkins寻找java的路径,这种情况,java不存在于任何上述路径中。
所以寻找你有java的路径,并在上面的jenkins文件中添加路径。
既然在/opt/jdk/bin目录下有java,那么把它添加到jenkins文件中:
candidates="
/opt/jdk/bin/java <----在这里添加
/etc/alternatives/java
/usr/lib/jvm/java-1.6.0/bin/java
/usr/lib/jvm/jre-1.6.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-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/bin/java
"