其他分享
首页 > 其他分享> > tomcat任务部署

tomcat任务部署

作者:互联网

tomcat项目部署

主机 IP 需求
web-1 192.168.78.144 tomcat+jenkins
web-2 192.168.78.145 tomcat

在RHEL-1主机上部署的jenkins将项目打包传输到RHEL-2主机上并可以实现网页效果

新建任务

输入任务名称选择任务类型

查看流水线语法

生成流水线脚本页面

选择并复制项目的分支和链接

点击生成流水线脚本

拉取代码

pipeline {
    agent any 
    stages {
        stage("pull code"){
            steps {
                git 'https://github.com/chendao2015/tomcat-java-demo.git'
            }
            
        }  
    }
}

应用并保存

查看是否完成

查看状态日志

完成后的任务保存路径

RHEL-1主机上查看

[root@localhost ~]# cd .jenkins/workspace/test/
[root@localhost test]# ls
db  Dockerfile  LICENSE  pom.xml  README.md  src
[root@localhost test]# 

安装maven打包工具

[root@localhost ~]# yum install maven -y

编写打包脚本

pipeline {
    agent any 
    stages {
        stage("pull code"){
            steps {
                git 'https://github.com/chendao2015/tomcat-java-demo.git'
            }
        }    
        stage("make pkg"){
            steps {
                sh """
                    mvn clean package -Dmaven.test.skip=true
                """
            }
        }  
    }
}

完成打包

//可以看到打包后新生成的target目录
[root@localhost ~]# cd .jenkins/workspace/test/
[root@localhost test]# cd target/
[root@localhost target]# ls
classes            ly-simple-tomcat-0.0.1-SNAPSHOT      maven-archiver
generated-sources  ly-simple-tomcat-0.0.1-SNAPSHOT.war  maven-status

配置免密登录

[root@web-1 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:06:f1:f5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.78.144/24 brd 192.168.78.255 scope global dynamic noprefixroute ens160
       valid_lft 1229sec preferred_lft 1229sec
    inet6 fe80::20c:29ff:fe06:f1f5/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@web-1 ~]# ssh root@192.168.78.145
Last login: Thu Aug 18 08:55:30 2022 from 192.168.78.144
[root@web-2 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:93:62:36 brd ff:ff:ff:ff:ff:ff
    inet 192.168.78.145/24 brd 192.168.78.255 scope global dynamic noprefixroute ens160
       valid_lft 1218sec preferred_lft 1218sec
    inet6 fe80::20c:29ff:fe93:6236/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

完善脚本

pipeline {
    agent any 
    stages {
        stage("pull code"){
            steps {
                git 'https://github.com/chendao2015/tomcat-java-demo.git'
            }
        }    
        stage("make pkg"){
            steps {
                sh """
                    mvn clean package -Dmaven.test.skip=true
                """
            }
        } 
        stage("publish"){
            steps {
                sh """
                    cd /root/.jenkins/workspace/test/target/
                   scp ly-simple-tomcat-0.0.1-SNAPSHOT.war   root@192.168.220.30:/usr/local/tomcat/webapps/
                   ssh root@192.168.78.145 '/usr/local/tomcat/bin/catalina.sh stop && /usr//local/tomcat/bin/catalina.sh start'
                   """
            }
        }
    }
}

构建成功

在web-2主机上查看

[root@web-2 ~]# cd /usr/local/tomcat/webapps/
[root@web-2 webapps]# ls
docs      host-manager                     ly-simple-tomcat-0.0.1-SNAPSHOT.war  ROOT
examples  ly-simple-tomcat-0.0.1-SNAPSHOT  manager                              test

web-2主机IP网页测试

标签:00,tomcat,部署,forever,lft,任务,ff,root
来源: https://www.cnblogs.com/wg123/p/16600177.html