参考

http://zlrzlm7454.iteye.com/blog/2322307

http://www.cnblogs.com/h--d/p/5673085.html

安装之前请确保你已经安装好JDK,Tomcat,Maven。

1、导入Jenkins key,安装

sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install jenkins

2、修改配置

[root@iZ94zsv4mnfZ ~]# vim /etc/sysconfig/jenkins

修改如下配置:

#避免执行脚本时权限不足

JENKINS_USER="root"

#默认为8080 与tomcat的端口冲突了这里我修改为8888,如你的8080端口未被占用,可以不改

JENKINS_PORT="8888"

JENKINS_USER我这里设置了root需要为root赋予访问jenkins的权限

[root@iZ94zsv4mnfZ ~]# chown -R root /var/log/jenkins
[root@iZ94zsv4mnfZ ~]# chgrp -R root /var/log/jenkins
[root@iZ94zsv4mnfZ ~]# chown -R root /var/lib/jenkins 
[root@iZ94zsv4mnfZ ~]# chgrp -R root /var/lib/jenkins
[root@iZ94zsv4mnfZ ~]# chown -R root /var/cache/jenkins
[root@iZ94zsv4mnfZ ~]# chgrp -R root /var/cache/jenkins

再修改另一处配置

[root@iZ94zsv4mnfZ ~]# vim /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
在/usr/bin/java上面添加一行:/usr/java/jdk1.8.0_102/bin/java 前面是你的java安装路径。

最终如下

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/java/jdk1.8.0_102/bin/java
/usr/bin/java

3启动

[root@iZ94zsv4mnfZ ~]# service jenkins start
启动完成后即可登录  http://IP:8888/ 访问Jenkins

第一次登录Jenkins 会要求解锁

[root@iZ94zsv4mnfZ ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
957fef857878401497edeed960c01b0d
输入上面的字符串

输入完成后会提示安装自定义插件还是推荐插件,此处我们选择推荐插件:

 然后等待安装完成后

安装maven插件

依次进入 系统管理->管理插件 点击可选插件,搜索 Maven Integration plugin  勾选上 点击直接安装

4、配置环境

进入 系统管理 -> Global Tool Configuration

JDK

MAVEN

点击save