使用jenkins將項(xiàng)目部署到另一臺(tái)主機(jī)的過(guò)程
環(huán)境
| 主機(jī)名 | ip地址 | 服務(wù) |
|---|---|---|
| jenkins | 192.168.216.200 | tomcat、jenkins |
| server | 192.168.216.215 | tomcat |


//關(guān)閉防火墻selinux //安裝打包命令,git [root@jenkins ~]# yum -y install maven [root@jenkins ~]# yum -y install git //配置免密登錄 [root@localhost ~]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:npcyZyHpOPmqGL1nbpZRj7UYULZxJhvNIcDg2G9Qvso root@localhost.localdomain The key's randomart image is: +---[RSA 3072]----+ | .oooBo+. | | + oo. Xo | | . + ..o | | o .o.. | | +.S*.. | | o o.=oooo | | . E +o* = | | o .*o * | | . oBo.. | +----[SHA256]-----+ [root@localhost ~]# ssh-copy-id root@192.168.216.215 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@192.168.216.215's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'root@192.168.216.215'" and check to make sure that only the key(s) you wanted were added. [root@localhost ~]# ssh root@192.168.216.215 Last login: Wed Oct 20 11:03:43 2021 from 192.168.216.200 [root@localhost ~]# exit 登出 Connection to 192.168.216.215 closed.
進(jìn)入jenkins端



pipeline {
agent any
stages {
stage('Build') {
steps {
// Get some code from a GitHub repository
git 'https://gitee.com/forgotten/tomcat-java-demo.git' #下載包,確保主機(jī)上有g(shù)it命令
// Run Maven on a Unix agent.
sh "mvn -Dmaven.test.failure.ignore=true clean package" #打包成war包
sh "mv target/ly-simple-tomcat-0.0.1-SNAPSHOT.war target/myapp.war" #更改包名
// To run Maven on a Windows agent, use
// bat "mvn -Dmaven.test.failure.ignore=true clean package"
}
}
stage("publish"){
steps{
sh "ssh root@192.168.216.215 'tar -Jcf /opt/backup/webapps-\$(date +%Y-%m%d).tar.xz /usr/local/tomcat/webapps/*'" #備份原有的項(xiàng)目
sh "scp target/myapp.war root@192.168.216.215:/usr/local/tomcat/webapps/" #傳包到目標(biāo)主機(jī)
sh "ssh root@192.168.216.215 '/usr/local/tomcat/bin/catalina.sh stop;sleep 3;/usr/local/tomcat/bin/catalina.sh start'" # 重啟生成項(xiàng)目
}
}
}
}


去目標(biāo)主機(jī)驗(yàn)證

手動(dòng)部署
//關(guān)閉防火墻,selinux //確保git命令存在,拉取部署的項(xiàng)目包 [root@jenkins opt]# git clone https://gitee.com/forgotten/tomcat-java-demo.git 正克隆到 'tomcat-java-demo'... remote: Enumerating objects: 558, done. remote: Counting objects: 100% (558/558), done. remote: Compressing objects: 100% (316/316), done. remote: Total 558 (delta 217), reused 558 (delta 217), pack-reused 0 接收對(duì)象中: 100% (558/558), 5.08 MiB | 673.00 KiB/s, 完成. 處理 delta 中: 100% (217/217), 完成. [root@jenkins opt]# ls tomcat-java-demo // 打包,確保mvn命令存在 [root@jenkins opt]# cd tomcat-java-demo/ [root@jenkins tomcat-java-demo]# ls db Dockerfile LICENSE README.md deploy.yaml jenkinsfile pom.xml src // 只要是帶pom.xml這樣文件的都是用mvn打包 [root@jenkins tomcat-java-demo]# mvn clean package [root@jenkins tomcat-java-demo]# mv target/ly-simple-tomcat-0.0.1-SNAPSHOT.war target/myapp.war [root@jenkins tomcat-java-demo]# ls target/ classes ly-simple-tomcat-0.0.1-SNAPSHOT maven-status generated-sources maven-archiver myapp.war // 確保有免密登錄,通過(guò)ssh啟動(dòng)server端tomcat,然后把要部署的包傳過(guò)去 [root@jenkins tomcat-java-demo]# scp target/myapp.war root@192.168.47.163:/usr/local/tomcat/webapps/ //tomcat會(huì)自動(dòng)解壓,過(guò)一會(huì)進(jìn)入網(wǎng)站對(duì)應(yīng)目錄就能看到新部署的項(xiàng)目
到此這篇關(guān)于使用jenkins將項(xiàng)目部署到另一臺(tái)主機(jī)的文章就介紹到這了,更多相關(guān)jenkins項(xiàng)目部署另一臺(tái)主機(jī)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用Tomcat服務(wù)器運(yùn)行sts時(shí)出現(xiàn)報(bào)錯(cuò)的解決辦法
前幾天在運(yùn)行 Spring ToolSuite 時(shí)出現(xiàn)Starting Tomcat v8.5 Server at localhost' hasencountered a problem.的錯(cuò)誤,所以本文給大家介紹了解決這個(gè)錯(cuò)的方法,需要的朋友可以參考下2023-09-09
Idea部署tomcat服務(wù)實(shí)現(xiàn)過(guò)程圖解
這篇文章主要介紹了Idea部署tomcat服務(wù)實(shí)現(xiàn)過(guò)程圖解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08
netty 實(shí)現(xiàn)tomcat的示例代碼
這篇文章主要介紹了netty 實(shí)現(xiàn)tomcat,主要包括自定義基礎(chǔ)類及netty 服務(wù)端的示例代碼詳解,通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06
IDEA 2020 配置Tomcat服務(wù)器的詳細(xì)步驟
這篇文章主要介紹了IDEA 2020 配置Tomcat服務(wù)器的詳細(xì)教程,本文分步驟給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-08-08
Tomcat啟動(dòng)war包卡死及啟動(dòng)慢的問(wèn)題解決
本文主要介紹了Tomcat啟動(dòng)war包卡死及啟動(dòng)慢的問(wèn)題解決,文中通過(guò)圖文示例介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-08-08

