当前位置:   article > 正文

tomcat_tomcat9.0

tomcat9.0

1.tomcat简介

Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成。由于有了Sun 的参与和支持,最新的Servlet 和JSP 规范总是能在Tomcat 中得到体现,Tomcat 5支持最新的Servlet 2.4 和JSP 2.0 规范。因为Tomcat 技术先进、性能稳定,而且免费,因而深受Java 爱好者的喜爱并得到了部分软件开发商的认可,成为目前比较流行的Web 应用服务器。
Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。对于一个初学者来说,可以这样认为,当在一台机器上配置好Apache 服务器,可利用它响应HTML(标准通用标记语言下的一个应用)页面的访问请求。实际上Tomcat是Apache 服务器的扩展,但运行时它是独立运行的,所以当你运行tomcat 时,它实际上作为一个与Apache 独立的进程单独运行的。
诀窍是,当配置正确时,Apache 为HTML页面服务,而Tomcat 实际上运行JSP 页面和Servlet。另外,Tomcat和IIS等Web服务器一样,具有处理HTML页面的功能,另外它还是一个Servlet和JSP容器,独立的Servlet容器是Tomcat的默认模式。不过,Tomcat处理静态HTML的能力不如Apache服务器。目前Tomcat最新版本为9.0。

tomcat就是传说中的中间件之一,tomcat本身是一个容器,专门用来运行java程序,java语言开发的网页.jsp就应该运行于tomcat中。而tomcat本身的运行也依赖于jdk环境。

tomcat应用场景:lnmt

1.1.java环境安装

//安装jdk环境
[root@localhost yum.repos.d]# dnf -y install java17-openjdk*
//省略安装过程
//查看安装的版本
[root@localhost ~]# java -version
  • 1
  • 2
  • 3
  • 4
  • 5

下载地址https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.65/bin/apache-tomcat-9.0.65.tar.gz

2.tomcat项目部署

//下载软件包
[root@localhost ~]# wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.65/bin/apache-tomcat-9.0.65.tar.gz
//解压
[root@localhost ~]# ls
anaconda-ks.cfg  apache-tomcat-9.0.65.tar.gz
[root@localhost ~]# tar xf apache-tomcat-9.0.65.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache-tomcat-9.0.65  bin  etc  games  include  lib  lib64  libexec  sbin  share  src
[root@localhost local]# mv apache-tomcat-9.0.65/ tomcat
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  sbin  share  src  tomcat
[root@localhost local]# cd tomcat/
[root@localhost tomcat]# ls
BUILDING.txt     LICENSE  README.md      RUNNING.txt  conf  logs  webapps
CONTRIBUTING.md  NOTICE   RELEASE-NOTES  bin          lib   temp  work
//webapps  放应用,java程序
//temp   放临时文件,一段时间自动删除
//logs    日志
[root@localhost tomcat]# 

//创建测试文件
[root@localhost tomcat]# cd webapps/
[root@localhost webapps]# mkdir test
[root@localhost webapps]# cd test
//添加网页文件
[root@localhost test]# vim index.jsp
[root@localhost test]# cat index.jsp 
<html>
<head>
<title>runtime</title>
</head>
<body>
    <%
        out.println("hello world");
    %>
</body>
</html>
//企业尽量不用环境变量,有可能会有多个tomcat,启动一个另一个就不好找到,
[root@localhost test]# echo 'export PATH=/usr/local/tomcat/bin:$PATH' > /etc/profile.d/tomcat.sh   
[root@localhost test]# source /etc/profile.d/tomcat.sh
[root@localhost test]# catalina.sh start
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.
[root@localhost test]# ss -antl
State        Recv-Q       Send-Q                   Local Address:Port               Peer Address:Port       Process       
LISTEN       0            128                            0.0.0.0:22                      0.0.0.0:*                        
LISTEN       0            128                            0.0.0.0:111                     0.0.0.0:*                        
LISTEN       0            32                       192.168.122.1:53                      0.0.0.0:*                        
LISTEN       0            128                               [::]:22                         [::]:*                        
LISTEN       0            1                   [::ffff:127.0.0.1]:8005    //出现端口                      *:*                        
LISTEN       0            128                               [::]:111                        [::]:*                        
LISTEN       0            100                                  *:8080  //首页端口                        *:*                        
//关闭服务器和seliunx
[root@localhost test]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost test]# vim /etc/selinux/config 
[root@localhost test]# setenforce 0

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65

在网页可以访问
在这里插入图片描述
刚刚添加的java文件
在这里插入图片描述

[root@localhost tomcat]# ls bin/
bootstrap.jar       ciphers.sh                    daemon.sh     setclasspath.bat  startup.sh            version.bat
catalina-tasks.xml  commons-daemon-native.tar.gz  digest.bat    setclasspath.sh   tomcat-juli.jar       version.sh
catalina.bat        commons-daemon.jar            digest.sh     shutdown.bat      tomcat-native.tar.gz
catalina.sh         configtest.bat                makebase.bat  shutdown.sh       tool-wrapper.bat
ciphers.bat         configtest.sh                 makebase.sh   startup.bat       tool-wrapper.sh
[root@localhost tomcat]# pwd
/usr/local/tomcat
//catalina.sh     总控开关,开启或关闭
//catalina.bat     在windows,总控开关,开启或关闭
//commons-daemon-native.tar.gz     守护进程
//configtest.bat        配置文件检查
//shutdown.sh       关机
//shutdown.sh    关闭服务
//startup.sh    启动服务
//version.sh     查看版本信息
#企业开机关机用法,多个环境变量情况
[root@localhost bin]# ./configtest.sh stop
//省略过程
[root@localhost bin]# ./configtest.sh start
//省略过程
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 设置配置文件
[root@localhost ~]# cd /usr/local/tomcat/conf/
[root@localhost conf]# ls
Catalina         catalina.properties  jaspic-providers.xml  logging.properties  tomcat-users.xml  web.xml
catalina.policy  context.xml          jaspic-providers.xsd  server.xml          tomcat-users.xsd
[root@localhost conf]# vim server.xml 

//取消注释,用于tomcat跟apache的效率 ,开启AJP协议
//注意如果有多个tomcat,则改一下端口号,比如8009变8010,没用过的端口都行,文件里的端口全都要变,有一些端口要重复注意填写.单个tomcat不用
    <Connector protocol="AJP/1.3"
               address="::1"
               port="8009"
               redirectPort="8443" />
 //重启
[root@localhost conf]# catalina.sh stop
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
[root@localhost conf]# catalina.sh start
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.
[root@localhost conf]# ss -antl
State        Recv-Q       Send-Q                   Local Address:Port               Peer Address:Port       Process       
LISTEN       0            128                            0.0.0.0:22                      0.0.0.0:*                        
LISTEN       0            128                            0.0.0.0:111                     0.0.0.0:*                        
LISTEN       0            32                       192.168.122.1:53                      0.0.0.0:*                        
LISTEN       0            128                               [::]:22                         [::]:*                        
LISTEN       0            1                   [::ffff:127.0.0.1]:8005     //出现                     *:*                        
LISTEN       0            100                              [::1]:8009      //出现                [::]:*                        
LISTEN       0            128                               [::]:111                        [::]:*                        
LISTEN       0            100                                  *:8080      //出现                    *:*                    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

  • 添加用户
<role rolename="manager-gui"/>     //添加
<user username="tomcat" password="tomcat" roles="manager-gui"/>    //添加,改密码,用户,类型
<!--
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
  <user username="both" password="<must-be-changed>" roles="tomcat,role1"/>

//重启
[root@localhost ~]# catalina.sh stop
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
[root@localhost ~]# ss -antl
State         Recv-Q        Send-Q               Local Address:Port               Peer Address:Port        Process        
LISTEN        0             128                        0.0.0.0:22                      0.0.0.0:*                          
LISTEN        0             128                        0.0.0.0:111                     0.0.0.0:*                          
LISTEN        0             32                   192.168.122.1:53                      0.0.0.0:*                          
LISTEN        0             128                           [::]:22                         [::]:*                          
LISTEN        0             128                           [::]:111                        [::]:*                          
[root@localhost ~]# catalina.sh start
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.
[root@localhost ~]# ss -antl
State         Recv-Q        Send-Q               Local Address:Port               Peer Address:Port        Process        
LISTEN        0             128                        0.0.0.0:22                      0.0.0.0:*                          
LISTEN        0             128                        0.0.0.0:111                     0.0.0.0:*                          
LISTEN        0             32                   192.168.122.1:53                      0.0.0.0:*                          
LISTEN        0             128                           [::]:22                         [::]:*                          
LISTEN        0             100                          [::1]:8009                       [::]:*                          
LISTEN        0             128                           [::]:111                        [::]:*                          
LISTEN        0             100                              *:8080                          *:*                          
[root@localhost ~]# ss -antl
State        Recv-Q       Send-Q                   Local Address:Port               Peer Address:Port       Process       
LISTEN       0            128                            0.0.0.0:22                      0.0.0.0:*                        
LISTEN       0            128                            0.0.0.0:111                     0.0.0.0:*                        
LISTEN       0            32                       192.168.122.1:53                      0.0.0.0:*                        
LISTEN       0            128                               [::]:22                         [::]:*                        
LISTEN       0            1                   [::ffff:127.0.0.1]:8005                          *:*                        
LISTEN       0            100                              [::1]:8009                       [::]:*                        
LISTEN       0            128                               [::]:111                        [::]:*                        
LISTEN       0            100                                  *:8080                          *:*             
[root@localhost webapps]# ls
ROOT  docs  examples  host-manager  manager  test
[root@localhost webapps]# cd manager/     //状态里面,在项目里面改配置
[root@localhost manager]# pwd
/usr/local/tomcat/webapps/manager
[root@localhost manager]# vim META-INF/context.xml 

<Context antiResourceLocking="false" privileged="true" >
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
          allow="192\.168\.70\.\d+|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />   //更改成这样,改自己主机的网段
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
//程序里面的类容改了,不用重启
//conf目录的必须要重启

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68

刷新了就可以登录
在这里插入图片描述
停止项目
在这里插入图片描述
这些都是/usr/local/tomcat/webapps/manager目录的类容
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
//打不开,添加角色
在这里插入图片描述

[root@localhost ~]# vim /usr/local/tomcat/conf/tomcat-users.xml 

<role rolename="manager-gui"/>
<role rolename="admin-gui"/>    //添加角色
<user username="tomcat" password="tomcat" roles="manager-gui,admin-gui"/>  //改成这样
<!--



//重启
[root@localhost ~]# catalina.sh stop
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
[root@localhost ~]# ss -antl
State         Recv-Q        Send-Q               Local Address:Port               Peer Address:Port        Process        
LISTEN        0             128                        0.0.0.0:22                      0.0.0.0:*                          
LISTEN        0             128                        0.0.0.0:111                     0.0.0.0:*                          
LISTEN        0             32                   192.168.122.1:53                      0.0.0.0:*                          
LISTEN        0             128                           [::]:22                         [::]:*                          
LISTEN        0             128                           [::]:111                        [::]:*                          
[root@localhost ~]# ps -ef | grep tomcat
root      511251  229197  0 08:15 pts/2    00:00:00 grep --color=auto tomcat
[root@localhost ~]# catalina.sh start
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.
[root@localhost ~]# ps -ef | grep tomcat
root      511553       1 69 08:15 pts/2    00:00:04 /usr/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root      511810  229197  0 08:15 pts/2    00:00:00 grep --color=auto tomcat
[root@localhost ~]# ss -antl
State        Recv-Q       Send-Q                   Local Address:Port               Peer Address:Port       Process       
LISTEN       0            128                            0.0.0.0:22                      0.0.0.0:*                        
LISTEN       0            128                            0.0.0.0:111                     0.0.0.0:*                        
LISTEN       0            32                       192.168.122.1:53                      0.0.0.0:*                        
LISTEN       0            128                               [::]:22                         [::]:*                        
LISTEN       0            1                   [::ffff:127.0.0.1]:8005                          *:*                        
LISTEN       0            100                              [::1]:8009                       [::]:*                        
LISTEN       0            128                               [::]:111                        [::]:*                        
LISTEN       0            100                                  *:8080                          *:*        
[root@localhost manager]# cd ..
[root@localhost webapps]# ls
ROOT  docs  examples  host-manager  manager  test
[root@localhost webapps]# vim host-manager/META-INF/context.xml 

//放行端口

<Context antiResourceLocking="false" privileged="true" >
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
          allow="192\.168\.70\.\d+|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />  改成自己端口
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>

~                                                                       
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64

刷新
在这里插入图片描述
这些都是/usr/local/tomcat/webapps/manager目录的类容,其中一个项目
在这里插入图片描述
流程控制打包工具jenkins
//java程序需要打包
下载官网
https://www.jenkins.io/
下载方法
在这里插入图片描述

3.jenkins简介

jenkins就是一个整合工具,把代码从git或者其他代码托管平台拉取过来,然后通过脚本语言编写执行流程,达到了项目一键启动的目的
准备工作
发布的包放到wabapps目录下

4.部署jenkins

[root@localhost webapps]# ls
ROOT  docs  examples  host-manager  manager  test
[root@localhost webapps]# mv * /opt/
[root@localhost webapps]# ls
[root@localhost ~]# ls
anaconda-ks.cfg  apache-tomcat-9.0.65.tar.gz  jenkins.war
[root@localhost ~]# cp jenkins.war /usr/local/tomcat/webapps/

[root@localhost webapps]# ls
jenkins.war
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
//重启
[root@localhost ~]# catalina.sh stop
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
[root@localhost ~]# ss -antl
State         Recv-Q        Send-Q               Local Address:Port               Peer Address:Port        Process        
LISTEN        0             128                        0.0.0.0:22                      0.0.0.0:*                          
LISTEN        0             128                        0.0.0.0:111                     0.0.0.0:*                          
LISTEN        0             32                   192.168.122.1:53                      0.0.0.0:*                          
LISTEN        0             128                           [::]:22                         [::]:*                          
LISTEN        0             128                           [::]:111                        [::]:*                          

[root@localhost ~]# ps -ef | grep tomcat
root      634521  229197  0 08:48 pts/2    00:00:00 grep --color=auto tomcat
[root@localhost ~]# catalina.sh start
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.
[root@localhost ~]# ss -atnl
State        Recv-Q       Send-Q                   Local Address:Port               Peer Address:Port       Process       
LISTEN       0            128                            0.0.0.0:22                      0.0.0.0:*                        
LISTEN       0            128                            0.0.0.0:111                     0.0.0.0:*                        
LISTEN       0            32                       192.168.122.1:53                      0.0.0.0:*                        
LISTEN       0            128                               [::]:22                         [::]:*                        
LISTEN       0            1                   [::ffff:127.0.0.1]:8005       //出现三个说明成功                   *:*                        
LISTEN       0            100                              [::1]:8009         //出现              [::]:*                        
LISTEN       0            128                               [::]:111          //出现              [::]:*                        
LISTEN       0            100                                  *:8080        
                  
[root@localhost webapps]# ls  //自动解压
jenkins    jenkins.war

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

等一下

在这里插入图片描述
在这里插入图片描述

[root@localhost jenkins]# cat /root/.jenkins/secrets/initialAdminPassword
edff0db19e22484b9e067a3161d283b9
//装个拉包工具
[root@localhost jenkins]# dnf -y install git
//省略过程
//安装项目程序
[root@localhost ~]# git clone https://github.com/chendao2015/tomcat-java-demo.git   

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

安装推荐的插件
在这里插入图片描述
新手就直接用推荐插件
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

4.1使用tomcat

在这里插入图片描述
运行java程序,多给内存,不卡
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

使用jenkins部署项目

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

编写流水线脚本拉取

pipeline {
    agent any 
    stages {
        stage("pull code"){
            steps {
                git 'https://github.com/chendao2015/tomcat-java-demo.git'
            }
            
        }  
    }
}
[root@localhost ~]# cd .jenkins/workspace/test
[root@localhost test]# ls
db  Dockerfile  LICENSE  pom.xml  README.md  src
[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
                """
            }
        }  
    }
}
[root@localhost test]# cd target/   //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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

在这里插入图片描述

在这里插入图片描述


[root@localhost ~]# 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:ILexF+o4ascaGiaXqsJ4gx+KbvUjWp+x8ZMfEtzeS2k root@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
|                 |
|                 |
|    . + .        |
|     o.*..       |
|      +oS.       |
|   o o .o . .    |
|=o*o+o...o E     |
|BO==++*o. + .    |
|@*=+.+..o. .     |
+----[SHA256]-----+
[root@localhost ~]# ssh-copy-id root@192.168.220.30
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.220.30 (192.168.220.30)' can't be established.
ECDSA key fingerprint is SHA256:qoJI5joraUlKD9iXhfj+GRVHvegeRitHHDZexhWLOLs.
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.220.30's password: 

Number of key(s) added: 1

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

# 登陆验证
[root@localhost ~]# ssh root@192.168.220.30
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Thu Aug 18 14:12:17 2022 from 192.168.220.1
[root@localhost ~]# ip addr show ens33 
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:8c:8e:d5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.220.30/24 brd 192.168.220.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe8c:8ed5/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50

编写输出脚本

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.220.30 '/usr/local/tomcat/bin/catalina.sh stop && /usr//local/tomcat/bin/catalina.sh start'
                   """
            }
        }
    }
}
[root@localhost ~]# cd /usr/local/tomcat/webapps/
[root@localhost webapps]# ls
docs  examples  host-manager  ly-simple-tomcat-0.0.1-SNAPSHOT  ly-simple-tomcat-0.0.1-SNAPSHOT.war  manager  ROOT

#关闭防火墙和selinux
[root@localhost webapps]# systemctl disable --now firewall
[root@localhost webapps]# setenforce 0


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/697901
推荐阅读
  

闽ICP备14008679号