目录
0.概述:
Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能。
1.功能:
Jenkins功能包括:
1、持续的软件版本发布/测试项目。
2、监控外部调用执行的工作。
2.搭建
环境准备:
【本例采用的jdk-1.8.0_202,apache-tomcat-8.0.30,Jenkins v2.176.1,Jenkins的web.xml版本是3.1】
web.xml——version2.2——JDK1.1——Tomcat3.3
web.xml——version2.3——JDK1.3——Tomcat4.1
web.xml——version2.4——JDK1.4——Tomcat5.5
web.xml——version2.5——JDK5.0——Tomcat6.0
web.xml——version3.0——JDK6.0——Tomcat7.0
web.xml——version3.1——JDK7.0,JDK8.0——Tomcat8.0,Tomcat8.5
web.xml——version4.0——JDK8.0——Tomcat9.0
2.1服务器环境:
[root@docker_g ~]# uname -a
Linux docker_g 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
2.2安装jdk环境:
可执行java查看版本命令,看下有没有安装jdk:
java -version
【如果安装已openjdk,需先卸载】
linux下安装jdk:
1.2.1:查看linux是32位还是64位:
getconf LONG_BIT
1.2.2:根据不同linux系统,选择jdk安装包
1.2.2.1:本地安装【jdk-1.8.0_202,安装包下载地址https://www.oracle.com/technetwork/java/javase/archive-139210.html】:
##################################################
[root@docker_g ~]# mkdir -p /usr/myapps/0apps
[root@docker_g ~]# mkdir -p /usr/myapps/java
[root@docker_g ~]# cd /usr/myapps/java
##################################################
sftp> cd /usr/myapps/0apps
sftp> pwd
/usr/myapps/0apps
sftp> lcd G:\s\software\jdk\8
sftp> lls
jdk-8u202-linux-i586.tar.gz jdk-8u202-linux-x64.tar.gz
jdk-8u202-windows-i586.exe jdk-8u202-windows-x64.exe
sftp> put jdk-8u202-linux-x64.tar.gz
Uploading jdk-8u202-linux-x64.tar.gz to /usr/myapps/0apps/jdk-8u202-linux-x64.tar.gz
100% 189494KB 8613KB/s 00:00:22
G:/s/software/jdk/8/jdk-8u202-linux-x64.tar.gz: 194042837 bytes transferred in 22 seconds (8613 KB/s)
sftp> ls
jdk-8u202-linux-x64.tar.gz
##################################################
[root@docker_g ~]# cd /usr/myapps/0apps
[root@docker_g /usr/myapps/0apps]# tar -zxvf jdk-8u202-linux-x64.tar.gz -C ../java/
[root@docker_g /usr/myapps/0apps]# cd ..
[root@docker_g /usr/myapps/java]# ll
总用量 0
drwxr-xr-x. 7 10 143 245 12月 16 2018 jdk1.8.0_202
##配置环境变量################################################
[root@docker_g /etc]# vi profile
#文件最后添加以下内容
#java
JAVA_HOME=/usr/myapps/java/jdk1.8.0_202
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
##验证################################################
[root@docker_g /etc]# source profile
[root@docker_g /etc]# java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)
##################################################
2.3安装web容器:
eg:Tomact
1.3.1:tomcat下载地址【http://tomcat.apache.org/】
1.3.2:tomcat安装步骤
########################################################
sftp> cd /root/software/apps
sftp> pwd
/root/software/apps
sftp> lcd G:\s\software\tomcat\Tomcat8\
sftp> lpwd
G:/s/software/tomcat/Tomcat8/8.0.30
sftp> lls
apache-tomcat-8.0.30.tar.gz
sftp> put apache-tomcat-8.0.30.tar.gz
Uploading apache-tomcat-8.0.30.tar.gz to /root/software/apps/apache-tomcat-8.0.30.tar.gz
100% 8825KB 8825KB/s 00:00:00
G:/s/software/tomcat/Tomcat8/apache-tomcat-8.0.30.tar.gz: 9037227 bytes transferred in 0 seconds (8825 KB/s)
########################################################
[root@docker_g ~]# cd ~/software/apps
[root@docker_g ~/software/apps]# ll
总用量 8828
-rw-r--r--. 1 root root 9037227 5月 15 21:44 apache-tomcat-8.0.30.tar.gz
[root@docker_g ~/software/apps]# tar -zxvf apache-tomcat-8.0.30.tar.gz -C ~/software/
[root@docker_g ~/software/apps]# cd ..
[root@docker_g ~/software]# ll
总用量 0
drwxr-xr-x. 9 root root 160 6月 30 16:48 apache-tomcat-8.0.30
drwxr-xr-x. 2 root root 41 6月 30 16:43 apps
###为了方便修改默认端口配置,也可不修改,使用默认的##################
[root@docker_g ~/software/apache-tomcat-8.0.30/conf]# vi server.xml
......
<Server port="8006" shutdown="SHUTDOWN">
......
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8444" />
......
<Connector port="8010" protocol="AJP/1.3" redirectPort="8444" />
......
########################################################
1.3.3:tomcat启动验证
#######################################################
[root@docker_g ~]# cd software/apache-tomcat-8.0.30/bin
[root@docker_g ~/software/apache-tomcat-8.0.30/bin]# ./startup.sh
Using CATALINA_BASE: /root/software/apache-tomcat-8.0.30
Using CATALINA_HOME: /root/software/apache-tomcat-8.0.30
Using CATALINA_TMPDIR: /root/software/apache-tomcat-8.0.30/temp
Using JRE_HOME: /usr/myapps/java/jdk1.8.0_202
Using CLASSPATH: /root/software/apache-tomcat-8.0.30/bin/bootstrap.jar:/root/software/apache-tomcat-8.0.30/bin/tomcat-juli.jar
Tomcat started.
[root@docker_g ~/software/apache-tomcat-8.0.30/bin]# cd ../logs
[root@docker_g ~/software/apache-tomcat-8.0.30/logs]# tail -f catalina.out
07-Jul-2019 10:48:07.600 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /root/software/apache-tomcat-8.0.30/webapps/docs has finished in 67 ms
07-Jul-2019 10:48:07.600 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /root/software/apache-tomcat-8.0.30/webapps/examples
07-Jul-2019 10:48:08.294 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /root/software/apache-tomcat-8.0.30/webapps/examples has finished in 694 ms
07-Jul-2019 10:48:08.295 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /root/software/apache-tomcat-8.0.30/webapps/host-manager
07-Jul-2019 10:48:08.356 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /root/software/apache-tomcat-8.0.30/webapps/host-manager has finished in 60 ms
07-Jul-2019 10:48:08.356 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /root/software/apache-tomcat-8.0.30/webapps/manager
07-Jul-2019 10:48:08.418 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /root/software/apache-tomcat-8.0.30/webapps/manager has finished in 62 ms
07-Jul-2019 10:48:08.437 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8081"]
07-Jul-2019 10:48:08.446 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8010"]
07-Jul-2019 10:48:08.474 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 45149 ms
##服务启动,但浏览器访问不同。。。。##############################
##经查,是防火墙搞的鬼。。。#####################################
##CentOS 7.* firewalld的基本使用###############################
##systemctl是CentOS7的服务管理工具中主要的工具###################
##它融合之前service和chkconfig的功能于一体
##启动: systemctl start firewalld
##
##查看状态: systemctl status firewalld
##
##停止: systemctl disable firewalld
##
##禁用: systemctl stop firewalld
##############################################################
##查看8080端口
[root@docker_g ~]# firewall-cmd --zone=public --query-port=8080/tcp
no
##开启8080端口############################################################
##添加
##
##firewall-cmd --zone=public --add-port=80/tcp --permanent ##(--permanent永久生效,没有此参数重启后失效)
##
##重新载入
##
##firewall-cmd --reload
##
##删除
##
##firewall-cmd --zone= public --remove-port=80/tcp --permanent
##
##############################################################
[root@docker_g ~]# firewall-cmd --zone=pfirewall-cmd --zone=public --add-port=8080/tcp --permanent
success
[root@docker_g ~]# firewall-cmd --zone=public --query-port=8080/tcp
no
[root@docker_g ~]# firewall-cmd --reload
success
[root@docker_g ~]# firewall-cmd --zone=public --query-port=8080/tcp
yes
##############################################################
2.4Jenkins安装
Jenkins官网下载地址【http://jenkins-ci.org/】下载后是一个jenkins.war包,直接放到tomcat下,启动tomcat服务器就可以使用了
【安装可参考官方说明:https://jenkins.io/zh/doc/book/installing/】
【亦可参考Jenkins官方文档:https://jenkins.io/zh/doc/book/installing/】
##先停止tomcat服务############################################
[root@docker_g ~/software/apache-tomcat-8.0.30/bin]# ./shutdown.sh
Using CATALINA_BASE: /root/software/apache-tomcat-8.0.30
Using CATALINA_HOME: /root/software/apache-tomcat-8.0.30
Using CATALINA_TMPDIR: /root/software/apache-tomcat-8.0.30/temp
Using JRE_HOME: /usr/myapps/java/jdk1.8.0_202
Using CLASSPATH: /root/software/apache-tomcat-8.0.30/bin/bootstrap.jar:/root/software/apache-tomcat-8.0.30/bin/tomcat-juli.jar
[root@docker_g ~/software/apache-tomcat-8.0.30/bin]# ps -ef|grep java
root 8175 7638 0 10:52 pts/4 00:00:00 grep --color=auto java
##############################################
sftp> cd /root/software/apache-tomcat-8.0.30/webapps
sftp> pwd
/root/software/apache-tomcat-8.0.30/webapps
sftp> ls
docs examples host-manager
manager ROOT
sftp> lcd G:\s\software\Jenkins\Jenkins2.176.1
sftp> lpwd
G:/s/software/Jenkins/Jenkins2.176.1
sftp> lls
jenkins.war
sftp> put jenkins.war
Uploading jenkins.war to /root/software/apache-tomcat-8.0.30/webapps/jenkins.war
100% 75461KB 18865KB/s 00:00:04
G:/s/software/Jenkins/Jenkins2.176.1/jenkins.war: 77272319 bytes transferred in 4 seconds (18865 KB/s)
##启动tomcat服务############################################
[root@docker_g ~/software/apache-tomcat-8.0.30/bin]# ./startup.sh
Using CATALINA_BASE: /root/software/apache-tomcat-8.0.30
Using CATALINA_HOME: /root/software/apache-tomcat-8.0.30
Using CATALINA_TMPDIR: /root/software/apache-tomcat-8.0.30/temp
Using JRE_HOME: /usr/myapps/java/jdk1.8.0_202
Using CLASSPATH: /root/software/apache-tomcat-8.0.30/bin/bootstrap.jar:/root/software/apache-tomcat-8.0.30/bin/tomcat-juli.jar
Tomcat started.
[root@docker_g ~/software/apache-tomcat-8.0.30/bin]# cd ../logs
[root@docker_g ~/software/apache-tomcat-8.0.30/logs]# tail -f catalina.out
##启动完成############################################
07-Jul-2019 13:16:18.556 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session
ID generation using [SHA1PRNG] took [10,859] milliseconds.
07-Jul-2019 13:16:19.248 INFO [Finalizing set up] jenkins.install.SetupWizard.init
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
cf03d059582640f099099b52563102dc
This may also be found at: /root/.jenkins/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
07-Jul-2019 13:16:20.363 INFO [localhost-startStop-1] org.springframework.context.support.AbstractApplicationContext.prepareRefresh Refreshing org.springframework.web
.context.support.StaticWebApplicationContext@672cbbe5: display name [Root WebApplicationContext]; startup date [Sun Jul 07 13:16:20 CST 2019]; root of context hierarc
hy
07-Jul-2019 13:16:20.363 INFO [localhost-startStop-1] org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory Bean factory for applicati
on context [org.springframework.web.context.support.StaticWebApplicationContext@672cbbe5]: org.springframework.beans.factory.support.DefaultListableBeanFactory@31c146
d3
07-Jul-2019 13:16:20.401 INFO [localhost-startStop-1] org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons Pre-instantiating
singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@31c146d3: defining beans [authenticationManager]; root of factory hierarchy
07-Jul-2019 13:16:21.025 INFO [localhost-startStop-1] org.springframework.context.support.AbstractApplicationContext.prepareRefresh Refreshing org.springframework.web
.context.support.StaticWebApplicationContext@565157c3: display name [Root WebApplicationContext]; startup date [Sun Jul 07 13:16:21 CST 2019]; root of context hierarc
hy
07-Jul-2019 13:16:21.026 INFO [localhost-startStop-1] org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory Bean factory for applicati
on context [org.springframework.web.context.support.StaticWebApplicationContext@565157c3]: org.springframework.beans.factory.support.DefaultListableBeanFactory@6e7c41
fa
07-Jul-2019 13:16:21.047 INFO [localhost-startStop-1] org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons Pre-instantiating
singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6e7c41fa: defining beans [filter,legacy]; root of factory hierarchy
07-Jul-2019 13:16:21.267 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /root/software/apache-tom
cat-8.0.30/webapps/jenkins.war has finished in 40,521 ms
##############################################
复制如下图红框部分,浏览器访问【http:IP:端口/jenkins】,按照提示设置即可:
2.5.jenkins安装问题统计:
2.5.1:报错如下:大概意思是tomcat版本和Jenkins.war安装包里web.xml的版本对应错误
信息: Starting Servlet Engine: Apache Tomcat/7.0.85
七月 04, 2019 10:21:21 下午 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive /root/software/apache-tomcat-7.0.85/webapps/jenkins.war
七月 04, 2019 10:21:23 下午 org.apache.catalina.deploy.WebXml setVersion
警告: Unknown version string [3.1]. Default version will be used.
此处换成tomcat8即可,具体对应关系,可参考:
web.xml——version2.2——JDK1.1——Tomcat3.3
web.xml——version2.3——JDK1.3——Tomcat4.1
web.xml——version2.4——JDK1.4——Tomcat5.5
web.xml——version2.5——JDK5.0——Tomcat6.0
web.xml——version3.0——JDK6.0——Tomcat7.0
web.xml——version3.1——JDK7.0——Tomcat8.0,Tomcat8.5
web.xml——version4.0——JDK8.0——Tomcat9.0
2.6.其他软件安装
2.5.1:maven安装:mvn -version
3.启动
首先保证系统中已经安装了jdk,最好是jdk1.5以上。
第一种启动方法,切换到jenkins.war存放的目录,输入如下命令:
$ java -jar jenkins.war
如果需要修改端口可以使用如下命令:
$ java -jar jenkins.war--httpPort=8081
然后在浏览器中输入服务器IP:8081,就可以打开jenkins。
第二种方法是用tomcat打开
解压tomcat到某个目录,进入tomcat下的/bin目录,启动tomcat
将jenkins.war文件放入tomcat下的webapps目录下,启动tomcat时,会自动在webapps目录下建立jenkins目录,在地址栏上需要输入服务器IP:8080/jenkins。