栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

tomcat使用jenkins部署项目到另一台主机

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

tomcat使用jenkins部署项目到另一台主机

文章目录
  • tomcat使用jenkins部署项目到另一台主机
      • 1.部署环境
      • 2.安装打包的命令
      • 3.配置免密
      • 4.在jenkins上创建项目
      • 5.修改shell脚本

tomcat使用jenkins部署项目到另一台主机 1.部署环境
主机IP地址服务
jenkins192.168.100.146tomcat、jenkins
test192.168.100.147tomcat
2.安装打包的命令
[root@jenkins ~]# yum -y install maven  git
上次元数据过期检查:1 day, 22:33:38 前,执行于 2021年10月17日 星期日 06时20分17秒。
依赖关系解决。
3.配置免密
[root@jenkins ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
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:K2YbaWd+PXts2rSfaoNYwQTIaHQl2LLiEHoWVEhoBj8 root@jenkins
The key's randomart image is:
+---[RSA 3072]----+
|o+ooo.=ooo.      |
|.=o  =.+.  .     |
|+ E.. o   o      |
|..oo .     o     |
| oo .   S   .    |
|   .   . . .     |
|      B + o....  |
|     + B ...o=+..|
|      . ..  +B=o.|
+----[SHA256]-----+
[root@jenkins ~]# ssh-copy-id root@192.168.100.147
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.100.147 (192.168.100.147)' can't be established.
ECDSA key fingerprint is SHA256:r5uhMkBRTNxvYYvWxormTvBxafc0DHlna23cHgnhfl4.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/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.100.147's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.100.147'"
and check to make sure that only the key(s) you wanted were added.

[root@jenkins ~]# 
4.在jenkins上创建项目


5.修改shell脚本
pipeline {
    agent any
    
    stages {
        stage('Build') {
            steps {
                // Get some code from a GitHub repository
                git 'https://gitee.com/forgotten/tomcat-java-demo.git'                //拉取包

                // 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.100.147  'tar -Jcf /opt/backup/myapp-`date +%F`.tar.xz    /usr/local/tomcat/webapps/myapp'"      //备份原有的项目
                sh "scp target/myapp.war root@192.168.153.156:/usr/local/tomcat/webapps/"    //传包
                sh "ssh root@192.168.100.147 '/usr/local/tomcat/bin/catalina.sh stop;sleep 3;/usr/local/tomcat/bin/catalina.sh start'"   // 重启生成项目
            }
        }
    }
}




转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/334877.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号