centos部署jenkins

Posted EWWE

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos部署jenkins相关的知识,希望对你有一定的参考价值。

1. 实验环境:

 
操作系统: CentOS Linux release 7.2.1511 (Core)
软件版本: jdk-8u60-linux-x64    apache-tomcat-9.0.0.M17    jenkins-2.44
实验条件: 关闭防火墙,iptables 开启对主机 80 / 8080 端口的访问
 
systemctl stop firewalld  
iptables -A INPUT -p tcp -s 0/0 --dport 80 -j ACCEPT  
iptables -A OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT  
iptables -A INPUT -p tcp -s 0/0 --dport 8080 -j ACCEPT  
iptables -A OUTPUT -p tcp --sport 8080 -m state --state ESTABLISHED -j ACCEPT  
iptables-save  

2. 安装 Java 环境

a. 安装包下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html (请根据实际情况选择对应的安装包)

本文使用的安装包是:jdk-8u60-linux-x64.tar.gz
wget http://download.Oracle.com/otn-pub/java/jdk/8u60-b27/jdk-8u60-linux-x64.tar.gz (请替换成安装包下载地址里面具体安装包的对应链接)  
tar xzvf jdk-8u60-linux-x64.tar.gz -C /usr/local/   
cd /usr/local/  
ln -sv jdk1.8.0_60 jdk  

 

b. 配置环境变量:

vim /etc/profile.d/jdk.sh  
--------------------------------------------------->  
JAVA_HOME=/usr/local/jdk  
PATH=$JAVA_HOME/bin:$PATH  
export JAVA_HOME PATH  
<---------------------------------------------------  
. /etc/profile.d/jdk.sh //重读此文件,让变量生效  

 

3. 查看JAVA是否安装成功:

[[email protected] local]# java -version  
java version "1.8.0_60"  
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)  
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)  

3. 安装 Tomcat

 
a. 安装包下载地址:http://tomcat.apache.org/download-90.cgi  (请根据实际情况选择对应的安装包)
本文使用的安装包是:9.0.0.M17 > Binary Distributions > Core > tar.gz 
wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.0.M17/bin/apache-tomcat-9.0.0.M17.tar.gz  
tar xzvf apache-tomcat-9.0.0.M17.tar.gz -C /usr/local/  
cd /usr/local/  
ln -sv apache-tomcat-9.0.0.M17 tomcat  

 

b. 配置环境变量:
 
vim /etc/profile.d/tomcat.sh  
--------------------------------------------------->  
CATALINA_BASE=/usr/local/tomcat  
PATH=$CATALINA_BASE/bin:$PATH  
JENKINS_HOME=$CATALINA_BASE/webapps/jenkins  
export PATH CATALINA_BASE JENKINS_HOME  
<---------------------------------------------------  
. /etc/profile.d/tomcat.sh  

c. 查看tomcat是否安装成功:

[[email protected] local]# catalina.sh version  
Using CATALINA_BASE:   /usr/local/tomcat  
Using CATALINA_HOME:   /usr/local/tomcat  
Using CATALINA_TMPDIR: /usr/local/tomcat/temp  
Using JRE_HOME:        /usr/local/jdk  
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar  
Server version: Apache Tomcat/9.0.0.M17  
Server built:   Jan 10 2017 20:59:20 UTC  
Server number:  9.0.0.0  
OS Name:        Linux  
OS Version:     3.10.0-327.28.3.el7.x86_64  
Architecture:   amd64  
JVM Version:    1.8.0_60-b27  
JVM Vendor:     Oracle Corporation  

 

 

4. 配置 Tomcat

 a. 配置server.xml:
vim /usr/local/tomcat/conf/server.xml  
---------------------------------------------------------->  
<Connector port="80" protocol="HTTP/1.1" //默认端口为8080,改为80  
connectionTimeout="20000"  
redirectPort="8443" />  

 

b. tomcat有 manager-gui 的管理页面,想要使用必须配置管理用户,不使用可以跳过此步。配置tomcat-users.xml:

vim /usr/local/tomcat/conf/tomcat-users.xml  
------------------------------------------------------------------------------->  
<role rolename="manager-gui"/> //指定用户可以使用的接口为manager-gui  
<user username="tomcat" password="tomcat" roles="manager-gui"/> //用户名和密码为tomcat,在manager-gui接口使用  

 

5. 安装 Jenkins 到 Tomcat

 

a. 安装包下载地址:http://mirrors.jenkins-ci.org/war/latest/jenkins.war

wget http://mirrors.jenkins-ci.org/war/latest/jenkins.war  
mkdir /usr/local/tomcat/webapps/jenkins  
cp jenkins.war /usr/local/tomcat/webapps/jenkins  
cd /usr/local/tomcat/webapps/jenkins  
jar -xvf jenkins.war  

 

b. 安装完成,现在可以开启 Tomcat 来使用 jenkins 了:

[[email protected] jenkins]# catalina.sh start  
Using CATALINA_BASE: /usr/local/tomcat  
Using CATALINA_HOME: /usr/local/tomcat  
Using CATALINA_TMPDIR: /usr/local/tomcat/temp  
Using JRE_HOME: /usr/local/jdk  
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar  

 

c. 在 Client 上打开浏览器,访问 http://172.0.0.1/jenkins 

 

参考文献:
http://www.linuxidc.com/Linux/2015-08/122234.htm
https://wiki.jenkins-ci.org/display/JENKINS/Tomcat
http://blog.sina.com.cn/s/blog_61df320b01019z4c.html
http://www.server110.com/linux/201308/740.html

以上是关于centos部署jenkins的主要内容,如果未能解决你的问题,请参考以下文章

Gitlab+jenkins持续集成+自动化部署

centos 7 jenkins 部署

Centos7 部署Jenkins

centos7部署jenkins

centos7部署jenkins

Centos7.5部署最新稳定版jenkins并配置ldap认证