环境准说明
操作系统:CentOS 7.1
IP地址:10.0.0.76
关闭防火墙
关闭SELinux
Jenkins是Java编写的,所以需要先安装JDK。可以使用源码安装也可以使用yum安装。笔者使用的是源码安装。
# tar xf jdk-8u121-linux-x64.gz -C /usr/local/
设置Java环境变量
###在/etc/profile文件最下面添加如下配置
# vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.8.0_121
export JRE_HOME=$JAVA_HOME/jre
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
#source /etc/profile
查看Java版本
# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
###证明Java配置成功
安装Jenkins
# cd /etc/yum.repos.d/
# wget http://pkg.jenkins.io/redhat/jenkins.repo
# rpm --import http://pkg.jenkins.io/redhat/jenkins.io.key
# yum install -y jenkins
启动Jenkins
# systemctl start jenkins
启动时报错,提示找不到java
Starting Jenkins bash: /usr/bin/java: No such file or directory
解决方法,在启动文件内添加本机的Java路径
# which java <--查看本机java路径
/usr/local/jdk1.8.0_121/bin/java
# vim /etc/init.d/jenkins
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/bin/java
/usr/local/jdk1.8.0_121/bin/java <--在此处添加本机java路径
"
for candidate in $candidates
do
[ -x "$JENKINS_JAVA_CMD" ] && break
JENKINS_JAVA_CMD="$candidate"
done
再次启动jenkin即可。
相关配置文件:
/usr/lib/jenkins/:jenkins安装目录,WAR包会放在这里。
/etc/sysconfig/jenkins:jenkins配置文件,“端口”,“JENKINS_HOME”等都可以在这里配置。