以下为centos6.9下测试安装:
docker下安装jenkins:
- 更新yum源:
yum -y update
- 安装docker:
yum -y install docker-io
- 启动docket服务:
service docker start
- 自启动:
chkconfig docker on
- 安装jenkins:
sudo docker pull jenkins
- 手动指定jenkins安装目录:
cd /home && mkdir jenkins_home
- 把jenkins_home 文件夹给 jenkins用户操作权限:
sudo chown -R 1000 /home/jenkins_home
- 启动jenkins Docker 在8080端口 (如果已经被占用,可以换成对应其他的端口):
sudo docker run -p 8080:8080 -p 50000:50000 -v /home/jenkins_home:/var/jenkins_home jenkins
- 后台运行的话使用如下:
sudo docker run -d -ti -p 8080:8080 -p 50000:50000 -v /home/jenkins_home:/var/jenkins_home jenkins
- 访问8080,进入安装引导页,在里面找到初始密码:
cat /home/jenkins_home/secrets/initialAdminPassword
直接安装:
安装java环境:
# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.tar.gz"
# tar xzf jdk-8u91-linux-x64.tar.gz
当然,提前卸载已安装的java环境是有必要的:
rpm -qa | grep -E '^open[jre|jdk]|j[re|dk]'
配置java环境变量:
vim /etc/profile
在profile文件最下方追加如下:
export JAVA_HOME=/opt/jdk1.8.0_91
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
更新配置文件,让配置生效:
source /etc/profile
添加jenkins的yum源:
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
安装jenkins:
yum install jenkins
启动jenkins:
service jenkins start
设置jenkins自启动:
chkconfig jenkins on
如果出现如下类似错误:
Starting Jenkins bash: /usr/bin/java: No such file or directory [FAILED]
是因为jenkins默认的java路径不对的问题,设置如下:
vi /etc/init.d/jenkins
找到/usr/bin/java那一行,在底下加入如下代码:
/opt/jdk1.8.0_91/bin/java
再重启jenkins即可:
service jenkins start/stop/restart
如果还访问不到的话,试着关闭linux防火墙或者允许8080端口穿透过防火墙即可!
完整效果如下: