您好,登錄后才能下訂單哦!
安裝maven
91 gitlab-ctl start
92 /etc/init.d/jenkins start
上傳所需安裝包
查看自身jdk環(huán)境
93 rpm -qa | grep jdk
94 rpm -e java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64 java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64 --nodeps #卸載自身jdk環(huán)境
95 tar zxf jdk-8u211-linux-x64.tar.gz -C /usr/local/ 解壓配置文件到/usr/local/
96 tar zxf apache-maven-3.6.1-bin.tar.gz
97 mv apache-maven-3.6.1 /usr/local/maven 解壓配置文件到/usr/local/
98 vim /etc/profile #末尾添加
export XGP=/usr/local/maven
export PATH=$PATH:$XGP/bin
export JAVA_HOME=/usr/local/jdk1.8.0_211
export JRE_HOME=/usr/local/jdk1.8.0_211/jre
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
99 source /etc/profile 刷新一下
100 mvn -v 測試一下是否安裝成功
使用阿里云倉庫地址
vim /usr/local/maven/conf/settings.xml #158添加
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
102 cd
103 mvn archetype:generate -DgroupId=cn.bdqn.bdqnweb -DartifactId=bdqnweb -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false #構建一個項目
86 cd xgp-demo/ 進入之前創(chuàng)建的本地git倉庫中
87 rm -rf * 刪除倉庫的所有內(nèi)容
88 git add * 上傳到緩存 這里會報錯
89 git status 查看一下狀態(tài)
92 git rm index.html x.txt xgp.txt 上傳一下刪除文件
93 git commit -m "del" 上傳到版板庫
94 git push origin master 上傳到遠程倉庫
96 netstat -anpt | grep 8081
97 /etc/init.d/jenkins restart 重啟jdk
98 /etc/init.d/jenkins status 查看jdk環(huán)境
104 ln -s /usr/local/jdk1.8.0_211/bin/java /usr/bin/ 鏈接命令目錄
105 /etc/init.d/jenkins start 再次啟動
107 ps -ef | grep 8081
修改Jenkins運行用戶
108 vim /etc/sysconfig/jenkins
JENKINS_USER="root" #29 用戶改為root
108
/etc/init.d/jenkins restart
109 ps -ef | grep 8081
111 cd bdqnweb/
112 ls
113 cat src/main/webapp/index.jsp
114 vim src/main/webapp/index.jsp 修改如下內(nèi)容
115 cat src/main/webapp/index.jsp
116 cp -r src/ pom.xml /root/xgp-demo/ 復制測試頁面到本地倉庫
117 cd /root/xgp-demo/ 進入本地倉庫
118 git add * 上傳到緩存
119 git commit -m "test1 index.jsp" 上傳到版本庫
120 git push origin master 上傳到版本庫
Jenkins服務器免密登陸1.50,1.60
130 ssh-copy-id root@192.168.1.50
131 ssh-copy-id root@192.168.1.60
132 ssh 192.168.1.50
133 ssh 192.168.1.60
在web界面上運程倉庫看一下
在jdk上安裝or回滾插件
系統(tǒng)管理----全局工具配置---Maven安裝---取消自動安裝
JDK安裝---取消自動安裝
安裝成功
新建任務---構建一-個maven項 目名稱為web- tomcat----參數(shù)化構建過程-- -添加參數(shù)- -選項參數(shù)---名稱Status
選項Deploy
RollBack
描述: ----請選擇發(fā)布or回滾----需要填寫commit id號 -
選項參數(shù)---名稱deploy
選項test
stag
描述: ----請選擇構建環(huán)境
文本參數(shù)---名稱git
描述:請輸入git commit id號
源碼管理: git---Repositories---- Repository URL
git@192. 168.83.3: web/web-demo.git
Branches to build----Branch Specifier (blank for 'any' )---${git}
構建環(huán)境---勾選--Color ANSI Console 0utput
Build:
Goals and options----clean package -Dmaven. test. skip-true .
Post Steps --執(zhí)行shell--編寫腳本
clean package -Dmaven.test.skip=true
##Deploy tomcat
war_bak="/data/war/bak"
tomcat_deploy="/usr/local/tomcat/webapps"
#WAR_PATH="${WORKSPACE}/${MODULE_NAME}/target/*.war"
WAR_PATH="${WORKSPACE}/target/*.war"
test_host="192.168.1.50"
stag_host="192.168.1.60"
port="8080"
echo "構建環(huán)境:${deploy} 項目名稱:${JOB_NAME} 構建時間:`date +%F` 本次上線版本:${GIT_COMMIT}" >> /var/log/${JOB_NAME}.log
### status deploy or rollback
##判斷git是否為空,如果是為空進行提示
if [ "${git}" = "" ];then
echo "請輸入git版本 #############"
exit 1
else
## 判斷發(fā)布 or 回滾
if [ "${Status}" = "Deploy" ];then
### 判斷是否為測試環(huán)境
if [ "${deploy}" = "test" ];then
### 構建主機
for i in ${test_host}
do
ssh ${i} "mkdir -p ${war_bak}/${JOB_NAME}/${git}"
scp ${WAR_PATH} ${i}:${war_bak}/${JOB_NAME}/${git}/ROOT.war
ssh ${i} rm -rf ${tomcat_deploy}/*
ssh ${i} cp ${war_bak}/${JOB_NAME}/${git}/ROOT.war ${tomcat_deploy}
ssh ${i} /etc/init.d/tomcat restart
### 判斷tomcat是否正常
for http in `seq 1 5`
do
tomcat_status=`curl -I ${i}:${port} -s|awk -F "[ ]" '{print $2}' |sed -n '1p'`
if [[ "$tomcat_status" -ne 200 ]] || [[ "$tomcat_status" = "" ]];then
echo -e "\033[5;34m 請稍等,服務啟動中........ \033[0m"
sleep 5
else
echo -e "\033[5;34m 構建 ${i}環(huán)境發(fā)布正常,返回值[${tomcat_status}] \033[0m"
break
fi
done
if [[ "${tomcat_status}" -ne 200 ]] || [[ "${tomcat_status}" = "" ]];then
if [[ "${tomcat_status}" = "" ]];then
echo -e "\033[5;34m 構建 ${i}服務啟動異常 \033[0m"
exit 1
fi
echo -e "\033[5;34m 構建 ${i}環(huán)境發(fā)布異常,返回值[${tomcat_status}] \033[0m"
fi
done
echo -e "\033[5;34m 本次構建${test_host}主機,本次環(huán)境 ${deploy} \033[0m"
## 判斷為預發(fā)布環(huán)境
elif [ "${deploy}" = "stag" ];then
for i in "${stag_host}"
do
ssh ${i} mkdir -p ${war_bak}/${JOB_NAME}/${git}
scp ${WAR_PATH} ${i}:${war_bak}/${JOB_NAME}/${git}/ROOT.war
ssh ${i} rm -rf ${tomcat_deploy}/*
ssh ${i} cp ${war_bak}/${JOB_NAME}/${git}/ROOT.war ${tomcat_deploy}
ssh ${i} /etc/init.d/tomcat restart
### 判斷tomcat是否正常
for http in `seq 1 5`
do
tomcat_status=`curl -I ${i}:${port} -s|awk -F "[ ]" '{print $2}' |sed -n '1p'`
if [[ "$tomcat_status" -ne 200 ]] || [[ "$tomcat_status" = "" ]];then
echo -e "\033[5;34m 請稍等,服務啟動中........ \033[0m"
sleep 5
else
echo -e "\033[5;34m 構建 ${i}環(huán)境發(fā)布正常,返回值[${tomcat_status}] \033[0m"
break
fi
done
if [[ "${tomcat_status}" -ne 200 ]] || [[ "${tomcat_status}" = "" ]];then
if [[ "${tomcat_status}" = "" ]];then
echo -e "\033[5;34m 構建 ${i}服務啟動異常 \033[0m"
exit 1
fi
echo -e "\033[5;34m 構建 ${i}環(huán)境發(fā)布異常,返回值[${tomcat_status}] \033[0m"
fi
done
echo -e "\033[5;34m 本次構建${test_host}主機,本次環(huán)境 ${deploy} \033[0m"
fi
### 回滾操作
elif [[ "${Status}" = "RollBack" ]];then
### 判斷回滾環(huán)境及主機
if [ "${deploy}" = "test" ];then
for i in ${test_host}
do
ssh ${i} "[ -d ${war_bak}/${JOB_NAME}/${git} ]"
if [ $? -ne '0' ];then
echo -e "\033[5;34m git commit 回滾目錄不存在,環(huán)境${deploy} 錯誤主機${i} \033[0m"
exit 3
else
echo -e "\033[5;34m 準備回滾操作 本次回滾環(huán)境${deploy} 回滾主機${i} \033[0m"
sleep 3
fi
ssh ${i} "mkdir -p ${war_bak}/${JOB_NAME}/${git}_${Status}_rollback/"
ssh ${i} "cp -r ${tomcat_deploy}/* ${war_bak}/${JOB_NAME}/${git}_${Status}_rollback/"
ssh ${i} "rm -rf ${tomcat_deploy}/*"
ssh ${i} "cp -r ${war_bak}/${JOB_NAME}/${git}/*.war ${tomcat_deploy}/"
ssh ${i} /etc/init.d/tomcat restart
### 判斷tomcat是否正常
for http in `seq 1 5`
do
tomcat_status=`curl -I ${i}:${port} -s|awk -F "[ ]" '{print $2}' |sed -n '1p'`
if [[ "$tomcat_status" -ne 200 ]] || [[ "$tomcat_status" = "" ]];then
echo -e "\033[5;34m 請稍等,服務啟動中........ \033[0m"
sleep 5
else
echo -e "\033[5;34m 構建 ${i}環(huán)境發(fā)布正常,返回值[${tomcat_status}] \033[0m"
break
fi
done
if [[ "${tomcat_status}" -ne 200 ]] || [[ "${tomcat_status}" = "" ]];then
if [[ "${tomcat_status}" = "" ]];then
echo -e "\033[5;34m 構建 ${i}服務啟動異常 \033[0m"
exit 1
fi
echo -e "\033[5;34m 構建 ${i}環(huán)境發(fā)布異常,返回值[${tomcat_status}] \033[0m"
fi
done
elif [ "${deploy}" = "stag" ];then
echo "123"
### 判斷測試環(huán)境fi結束
fi
fi
#### fi是判斷是否有git地址的結束
fi
1.50,1.60
搭建tomcat環(huán)境
19 cd /usr/src/
20 mkdir tomcat
21 cd tomcat/
22 rz 上傳tomcat安裝包
安裝tomcat
24 tar zxf apache-tomcat-8.5.35.tar.gz
25 mv apache-tomcat-8.5.35 /usr/local/tomcat 移動tomcat配置文件
26 mv tomcat /etc/init.d/ 添加一個tomcat啟動腳本到/etc/init.d
32 chmod +x /etc/init.d/tomcat 給啟動腳本一個可執(zhí)行權限
33 /etc/init.d/tomcat start 啟動tomcat
34 netstat -anpt | grep 8080
35 scp /etc/init.d/tomcat root@192.168.1.60:/etc/init.d/ 復制tomcat啟動文件到1.50和1.60
36 scp -r /usr/local/tomcat root@192.168.1.60:/usr/local/tomcat/ 復制tomcat配置文件到1.50和1.60
1.60
13 /etc/init.d/tomcat start
14 netstat -anpt | grep 8080
測試一下
瀏覽器查看192.168.1.50:8080
瀏覽器查看192.168.1.60:8080
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。