jenkins 部署文档
Jenkins是一個(gè)非常出色的持續(xù)集成服務(wù)器,本文主要介紹在CentOS系統(tǒng)中Jenkins的基本安裝配置方法,供參考。
一. 軟件包:
1. 下載apache-maven-2.2.1-bin.tar
http://www.apache.org/dyn/closer.cgi/maven/binaries/apache-maven-2.2.1-bin.tar.gz
2. 下載jenkins:http://mirrors.jenkins-ci.org/war/?列出了jenkins的所有release版本,請(qǐng)選擇下載
二. 安裝
1.安裝jdk
# chmod 755 jdk-8u51-linux-x64.tar.gz
#?tar zxvf jdk-8u51-linux-x64.tar.gz -C /app/zpy/
#?chown -R root.root ?jdk1.8.0_51/
# vim /etc/profile
JAVA_HOME=/app/zpy/jdk1.8.0_51
JAVA_BIN=/app/zpy/jdk1.8.0_51/bin
PATH=$PATH:$JAVA_BIN:
CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export?JAVA_HOME JAVA_BIN PATH CLASSPATH
2.安裝tomcat
#?tar zxvf apache-tomcat-6.0.41.tar.gz -C /app/zpy/
#?mv apache-tomcat-6.0.41/ tomcat_jenkins
修改tomcat配置文件
#?vim tomcat_jenkins/conf/server.xml
修改8080端口的Connector節(jié)點(diǎn),增加如下配置
URIEncoding="UTF-8"
3.安裝maven
1)解壓
#??tar -zvxf apache-maven-2.2.1-bin.tar.gz
2)移動(dòng)到其他目錄
# mv apache-maven-3.3.9/ maven
3)配置環(huán)境變量
# vim /etc/profile
SVN_HOME=/app/zpy/subversion/bin
GIT_HOME=/app/zpy/git
GIT_BIN=/app/zpy/git/bin
MAVEN_HOME=/app/zpy/maven
JENKINS_HOME=/app/zpy/tomcat_jenkins/webapps/jenkins
JAVA_HOME=/app/zpy/jdk1.8.0_51
JAVA_BIN=/app/zpy/jdk1.8.0_51/bin
PATH=$PATH:$JAVA_BIN:$MAVEN_HOME/bin:$GIT_BIN:$SVN_HOME
CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export MAVEN_HOME JENKINS_HOME JAVA_HOME JAVA_BIN PATH CLASSPATH
# . /etc/profile
4) 驗(yàn)證是否安裝成功
#?mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /app/zpy/maven
Java version: 1.8.0_51, vendor: Oracle Corporation
Java home: /app/zpy/jdk1.8.0_51/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-431.el6.x86_64", arch: "amd64", family: "unix"
5) 配置maven
編輯maven的配置文件
# cd maven/conf
# vi settings.xml
修改配置文件示例如下:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
? ? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
? ? xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
? ? <localRepository>/data/jenkins</localRepository>
? ? <servers>
? ? ? ? <server>
? ? ? ? ? ? <username>admin</username>
? ? ? ? ? ? <password>password</password>
? ? ? ? </server>
? ? </servers>
? ? <mirrors>
? ? ? ? <mirror>
? ? ? ? ? ? <!-- This sends everything else to /public -->
? ? ? ? ? ? <id>nexus</id>
? ? ? ? ? ? <mirrorOf>central</mirrorOf>
? ? ? ? ? ? <url>http://10.0.70.242:8081/nexus/content/repositories/public</url>
? ? ? ? </mirror>
? ? </mirrors>
? ? <profiles>
? ? ? ? <profile>
? ? ? ? ? ? <id>nexus</id>
? ? ? ? ? ? <!-- Enable snapshots for the built in central repo to direct -->
? ? ? ? ? ? <!-- all requests to nexus via the mirror -->
? ? ? ? ? ? <repositories>
???????????????
<repository>
? ? ? ? ? ? ? ? ? ? <id>central</id>
? ? ? ? ? ? ? ? ? ? <url>http://10.0.70.242:8081/nexus/content/repositories/public</url>
? ? ? ? ? ? ? ? ? ? <releases>
? ? ? ? ? ? ? ? ? ? ? ? <enabled>true</enabled>
? ? ? ? ? ? ? ? ? ? ? ? <updatePolicy>always</updatePolicy>
? ? ? ? ? ? ? ? ? ? </releases>
? ? ? ? ? ? ? ? ? ? <snapshots>
? ? ? ? ? ? ? ? ? ? ? ? <enabled>true</enabled>
? ? ? ? ? ? ? ? ? ? ? ? <updatePolicy>always</updatePolicy>
? ? ? ? ? ? ? ? ? ? </snapshots>
? ? ? ? ? ? ? ? </repository>
? ? ? ? ? ? </repositories>
? ? ? ? ? ? <pluginRepositories>
? ? ? ? ? ? ? ? <pluginRepository>
? ? ? ? ? ? ? ? ? ? <id>central</id>
? ? ? ? ? ? ? ? ? ? <url>http://192.169.10.109:8081/nexus/content/repositories/public</url>
? ? ? ? ? ? ? ? ? ? <releases>
? ? ? ? ? ? ? ? ? ? ? ? <enabled>true</enabled>
? ? ? ? ? ? ? ? ? ? ? ? <updatePolicy>always</updatePolicy>
? ? ? ? ? ? ? ? ? ? </releases>
? ? ? ? ? ? ? ? ? ? <snapshots>
? ? ? ? ? ? ? ? ? ? ? ? <enabled>true</enabled>
? ? ? ? ? ? ? ? ? ? ? ? <updatePolicy>always</updatePolicy>
? ? ? ? ? ? ? ? ? ? </snapshots>
? ? ? ? ? ? ? ? </pluginRepository>? ? ?
????????????</pluginRepositories>
? ? ? ? </profile>
? ? </profiles>
? ? <activeProfiles>
? ? ? ? <!-- make the profile active all the time -->
? ? ? ? <activeProfile>nexus</activeProfile>
? ? </activeProfiles>
? ? <pluginGroups>
? ? ? ? <!-- define the sonatype plugin group, so the nexus plugins will work without?
? ? ? ? ? ? ? ? ? ? ? ? ?typing the groupId -->
? ? ? ? <pluginGroup>org.sonatype.plugins</pluginGroup>
? ? </pluginGroups>
</settings>
其中localRepository節(jié)點(diǎn)表示私服中下載的jar包存放路徑,根據(jù)實(shí)際存放的路徑修改。
所有url節(jié)點(diǎn)中包含的地址:http://192.169.10.109:8081/nexus/content/repositories/public,表示nexus私服的地址,請(qǐng)根據(jù)實(shí)際的地址修改。由研發(fā)提供,沒(méi)有的話,使用默認(rèn)的setting.xml配置文件,走公有的庫(kù),構(gòu)建任務(wù)時(shí)下載會(huì)慢一些。
username、password節(jié)點(diǎn)表示登錄nexus私服的用戶名及密碼。
4、安裝jenkins
1) 復(fù)制到tomcat webapps目錄
#?cp jenkins.war /app/zpy/tomcat_jenkins/webapps/
2)配置環(huán)境變量
# vim /etc/profile
SVN_HOME=/app/zpy/subversion/bin
GIT_HOME=/app/zpy/git
GIT_BIN=/app/zpy/git/bin
MAVEN_HOME=/app/zpy/maven
JENKINS_HOME=/app/zpy/tomcat_jenkins/webapps/jenkins
JAVA_HOME=/app/zpy/jdk1.8.0_51
JAVA_BIN=/app/zpy/jdk1.8.0_51/bin
PATH=$PATH:$JAVA_BIN:$MAVEN_HOME/bin:$GIT_BIN:$SVN_HOME
CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export MAVEN_HOME JENKINS_HOME JAVA_HOME JAVA_BIN PATH CLASSPATH
# . /etc/profile
3) 啟動(dòng)tomcat,使用http://localhost:8080/jenkins訪問(wèn)jenkins
4) 輸入/app/zpy/tomcat_jenkins/webapps/jenkins/secrets/initialAdminPassword中的密碼
5)?安裝默認(rèn)安裝
6)默認(rèn)插件安裝完成,繼續(xù)。(有些插件安裝失敗,也可繼續(xù))
7)不填內(nèi)容,選擇continue as?admin(后面進(jìn)行用戶管理)
開(kāi)始使用!
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1)創(chuàng)建用戶
系統(tǒng)管理—管理用戶—填入用戶名、密碼
設(shè)置\修改密碼:? 系統(tǒng)管理—管理用戶—選擇指定的用戶—設(shè)置—到最下面修改密碼
2)插件配置
查看已安裝的
系統(tǒng)管理—管理插件--高級(jí)—瀏覽—上傳
4)新建任務(wù)
每個(gè)任務(wù)為部署文件夾或壓縮包
首先創(chuàng)建一個(gè)imp-share的任務(wù)。之后部署的應(yīng)用需要依賴于這個(gè)imp-share(都由研發(fā)提供,上傳至svn)
需要配置的主要有三個(gè)方面:svn?? maven??? deploy
I. svn配置,版本庫(kù)地址、用戶名和密碼
II.?(注意Global Tool Configuration中已配置maven)
III. 完成后點(diǎn)擊立即構(gòu)建。至此依賴包構(gòu)建完成。
5)新建應(yīng)用任務(wù)
I. svn配置,版本庫(kù)地址、用戶名和密碼
注意去掉勾選,如果選上,svn如果更新就自動(dòng)發(fā)包。
II.?(注意Global Tool Configuration中已配置maven)
完成點(diǎn)擊立即構(gòu)建
III. 自動(dòng)遠(yuǎn)程部署到tomcat
接下來(lái)要完成自動(dòng)構(gòu)建war包后,將這些war包上傳到遠(yuǎn)程linus的tomcat的webapps目錄,更新項(xiàng)目的war包,并重啟tomcat服務(wù)。
安裝插件
到https://wiki.jenkins-ci.org/display/JENKINS/Publish+Over+SSH+Plugin下載hpi到本地
系統(tǒng)管理--> 管理插件--> 高級(jí)--> 上傳.hpi插件
配置ssh內(nèi)容:
系統(tǒng)管理--> 系統(tǒng)設(shè)置--> publish over ssh 進(jìn)行配置
點(diǎn)擊高級(jí)
注釋:
如果沒(méi)有做ssh等效性,Passphrase、path to key、key處不需要填寫。
Disable exec 是禁止執(zhí)行命令
SSH Server Name隨便設(shè)置一個(gè)項(xiàng)目名
Hostname 是tomcat服務(wù)器的地址
username 是系統(tǒng)的用戶名
Remote Directory 是登錄到的路徑,此后作為根路徑,后面的配置依據(jù)于這個(gè)路徑
勾選Use password authentication,or use a different key
Passphrase/Password 填寫系統(tǒng)用戶的密碼
進(jìn)行任務(wù)配置
配置imp-im-web任務(wù)
構(gòu)建夠操作--> Sned build artifacts over SSH
注釋:
SSH Server
Name 為之前ssh配置的項(xiàng)目名稱
Transfers
Source files 是war包的位置。默認(rèn)根路徑為/app/zpy/tomcat_jenkins/webapps/jenkins/workspace/imp-im-web所以只從target填寫即可
Remove prefix 去掉的路徑。如果不去掉,傳到tomcat上的包路徑會(huì)加上目錄target比如Remote directory設(shè)置為/tmp則拷貝過(guò)去后成為/tmp/target/imp-im.war
Remote directory 拷貝到tomcat上的路徑,存放war包
Exec command 拷貝war包后 要執(zhí)行的操作。
deploy.sh 腳本的內(nèi)容如下:
#!/bin/sh
#defined?
source /etc/profile
TOMCAT_HOME="/app/zpy/tomcat"
ID=`ps -ef | grep java | grep tomcat|awk '{print $2}'`
echo $ID?
echo "kill tomcat"
kill -9 $ID
echo "remover war file"
cd "$TOMCAT_HOME"/webapps
rm -rf imp-im
rm -rf imp-im.war
echo "copy war to webapp"
cd /tmp
mv imp-im.war "$TOMCAT_HOME"/webapps
cd "$TOMCAT_HOME"/bin
echo "start tomcat"
./startup.sh
至此imp-im-web任務(wù)配置完成,點(diǎn)擊立即構(gòu)建。成功會(huì)顯示
備注:
對(duì)于svn上存放的不是源碼,是編譯完成的war包的情況。
新建任務(wù),選擇自由風(fēng)格
imp-im.war在imp-im-web-test/target下
選擇Send files or execute commands over SSH after the build runs
點(diǎn)擊立即構(gòu)建,完成!!!
轉(zhuǎn)載于:https://blog.51cto.com/zhouxinyu1991/1865913
總結(jié)
以上是生活随笔為你收集整理的jenkins 部署文档的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【目标跟踪】|MOSSE原理及对应代码解
- 下一篇: [Leetcode][第257题][JA