• tomcat服务安装步骤以及详细配置教程


    tomcat服务安装步骤以及详细配置教程

    1.简介

    Tomcat是一个开源的Java Servlet容器,可以作为Java Web应用程序的运行环境。它是Apache软件基金会的一个重要项目,具有高性能、稳定可靠以及跨平台等特点。它实现了Java Servlet和JavaServer Pages(JSP)规范,并提供了一个运行环境,使得Java代码可以在Web服务器上执行。

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

    2.优缺点

    优点:

    1. 开源免费:Tomcat是一个开源项目,可以免费使用,这使得它成为了一个广受欢迎的Java Web应用服务器。
    2. 跨平台:Tomcat可以在各种操作系统上运行,包括Windows、Linux、macOS等。
    3. 轻量级:相比于其他一些Java应用服务器(如WebLogic、WebSphere等),Tomcat相对轻量级,资源占用较少,启动速度也相对较快。
    4. 灵活性:Tomcat可以作为一个独立的Web服务器使用,也可以与其他Web服务器(如Apache)配合使用,形成一个强大的Web服务器架构。

    缺点:

    • 功能相对有限:相对于一些商业的Java应用服务器,Tomcat在一些高级特性和功能方面可能有所欠缺,比如分布式事务、集群等方面的支持。
    • 管理界面相对简陋:Tomcat的管理界面相对简单,对于一些高级的管理需求可能不够满足。

    3.工作原理

    1. omcat的工作原理基于Java Servlet和JavaServer Pages(JSP)规范,它充当了一个Java Web应用程序的运行环境和Web服务器。以下是Tomcat的工作原理的详细说明:

      1. 启动Tomcat:Tomcat作为一个独立的Java应用程序运行。通常,你会使用命令行或启动脚本来启动Tomcat。一旦Tomcat启动,它开始监听HTTP请求的到达。
      2. 连接器(Connectors):Tomcat通过连接器来监听HTTP请求。连接器是Tomcat的组件,负责处理网络连接和接收HTTP请求。常见的连接器包括HTTP连接器(用于处理HTTP请求)和AJP连接器(用于与其他Web服务器如Apache连接)。每个连接器通常监听一个特定的端口,比如HTTP连接器默认监听8080端口。
      3. 容器(Containers):Tomcat包含了两种主要的容器:引擎(Engine)和主机(Host)。引擎负责处理多个主机,每个主机代表一个独立的域名或虚拟主机。主机包含一个或多个上下文(Context),每个上下文对应一个Web应用程序。容器负责处理Servlet和JSP的生命周期管理、请求分发和响应收集。
      4. Servlet容器:当一个HTTP请求到达Tomcat后,Tomcat会根据请求的URL来确定将请求交给哪个Servlet进行处理。Servlet容器是Tomcat的一部分,它负责管理Servlet的生命周期,包括实例化、初始化、调用和销毁。Servlet容器还负责将请求传递给适当的Servlet,并将Servlet生成的响应返回给客户端。
      5. JSP引擎:Tomcat还包含了一个JSP引擎,用于处理JSP页面。当一个JSP页面被请求时,JSP引擎将JSP编译成Servlet,并交给Servlet容器来处理。生成的Servlet负责处理JSP页面的动态内容生成。
      6. 部署描述符(Deployment Descriptors):每个Web应用程序通常包括一个部署描述符(通常是一个web.xml文件),它包含了关于应用程序的配置信息,包括Servlet映射、过滤器配置、监听器配置等。Tomcat会读取这些描述符以了解如何处理请求。
      7. 请求处理流程
        • Tomcat接收到HTTP请求后,连接器将请求传递给适当的主机和上下文。
        • 主机和上下文确定哪个Servlet应该处理请求,并将请求传递给Servlet容器。
        • Servlet容器实例化和初始化Servlet,调用其service()方法来处理请求。
        • Servlet生成响应并将其返回给Servlet容器。
        • Servlet容器将响应返回给主机和连接器,最终发送给客户端。
      8. 关闭Tomcat:当不再需要Tomcat服务时,你可以通过命令行或脚本来关闭Tomcat。Tomcat会执行关闭过程,释放资源并停止监听HTTP请求。

      总之,Tomcat的工作原理涉及连接器、容器、Servlet容器、JSP引擎以及部署描述符等多个组件,它们协同工作来处理HTTP请求,将请求传递给适当的Servlet或JSP,生成响应并将其返回给客户端。这个过程使得Tomcat成为一个强大的Java Web应用服务器,用于部署和运行Java Web应用程序。

    4.工作流程

    tomcat的工作原理基于Java Servlet和JSP规范。它充当一个Web服务器,接收HTTP请求并将其传递给合适的Servlet或JSP进行处理。以下是Tomcat的基本工作流程:

    1. 接收请求:Tomcat作为一个Web服务器监听指定的端口(默认为80或8080)。当一个HTTP请求到达时,Tomcat会接收并解析它。
    2. 请求分发:根据URL和部署在Tomcat中的应用程序配置,Tomcat会决定将请求交给哪个Servlet或JSP进行处理。
    3. Servlet处理:如果请求是一个Servlet请求,Tomcat会将请求信息传递给相应的Servlet。Servlet会处理请求并生成响应,然后将其发送回Tomcat。
    4. JSP处理:如果请求是一个JSP请求,Tomcat会将JSP文件编译成一个Servlet,然后将请求信息传递给这个Servlet进行处理。Servlet再生成响应并将其返回给Tomcat。
    5. 响应传递:Tomcat接收到Servlet或JSP生成的响应后,将其传递回客户端。

    5.实战(tomcat项目部署)

    服务器IP地址系统版本tomcat版本
    tomcat192.168.195.137centos 8apache-tomcat-9.0.80.tar.gz

    首先关闭防火墙和selinux

    [root@tomcat ~]# systemctl disable --now firewalld.service 
    Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
    Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
    [root@tomcat ~]# setenforce 0
    [root@tomcat ~]# vim /etc/selinux/config 
    [root@tomcat ~]# grep '^SELINUX=' /etc/selinux/config
    SELINUX=disabled
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    5.1.java环境安装

    JDK(Java Development Kit)和JRE(Java Runtime Environment)是Java开发和运行环境的两个重要组成部分,它们之间有以下区别:

    JDK:

    1. 功能:JDK是Java开发工具包,提供了开发Java应用程序所需的工具和资源,包括编译器、调试器、开发文档、示例代码等。
    2. 面向开发者:JDK主要面向Java开发者,用于编写、编译和调试Java代码。
    3. 包含内容:JDK包含JRE的所有内容,并且还包含了用于开发Java应用程序的额外工具和库。

    JRE:

    1. 功能:JRE是Java运行环境,提供了Java应用程序运行所需的运行时环境和必要的库文件。
    2. 面向用户:JRE主要面向普通用户,用于执行和运行Java应用程序。
    3. 包含内容:JRE包含Java虚拟机(JVM)和Java类库,可以执行Java程序,但不包含用于开发Java应用程序的工具和资源。

    简而言之,JDK适用于开发者,提供了编译、调试和开发所需的工具和库。而JRE适用于用户,用于运行Java应用程序,不包含开发工具。如果你只是要运行Java程序,只需要安装JRE即可。如果你要进行Java应用程序的开发,需要安装JDK。

    //安装jdk环境
    [root@tomcat ~]# rm -rf /etc/yum.repos.d/*
    [root@tomcat ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
    [root@tomcat ~]# yum makecache
    [root@tomcat ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel wget vim
    省略 . . .
    
    //查看安装的版本,能够查看到版本则说明安装成功
    [root@tomcat ~]# java -version
    openjdk version "1.8.0_312"
    OpenJDK Runtime Environment (build 1.8.0_312-b07)
    OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    5.2.拉取tomcat软件包

    进入tomcat官网

    Apache Tomcat® - Welcome!
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    //拉取tomcat软件包
    [root@tomcat ~]# wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.80/bin/apache-tomcat-9.0.80.tar.gz
    --2023-10-10 13:41:29--  https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.80/bin/apache-tomcat-9.0.80.tar.gz
    Resolving archive.apache.org (archive.apache.org)... 65.108.204.189, 2a01:4f9:1a:a084::2
    Connecting to archive.apache.org (archive.apache.org)|65.108.204.189|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 11692853 (11M) [application/x-gzip]
    Saving to: ‘apache-tomcat-9.0.80.tar.gz’
    
    apache-tomcat-9.0.80.tar.gz   100%[===============================================>]  11.15M  25.2KB/s    in 5m 55s  
    
    2023-10-10 13:47:25 (32.1 KB/s) - ‘apache-tomcat-9.0.80.tar.gz’ saved [11692853/11692853]
    
    [root@tomcat ~]# ls
    anaconda-ks.cfg  apache-tomcat-9.0.80.tar.gz
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    5.3.解压部署

    //解压至指定目录
    [root@tomcat ~]# tar xf apache-tomcat-9.0.80.tar.gz -C /usr/local/
    [root@tomcat ~]# ls /usr/local/
    apache-tomcat-9.0.80  bin  etc  games  include  lib  lib64  libexec  sbin  share  src
    
    //设置tomcat软链接,方便后续如果更换tomcat版本后也能直接使用
    [root@tomcat ~]# cd //usr/local/
    [root@tomcat local]# ll
    total 0
    drwxr-xr-x  9 root root 220 Oct 10 13:49 apache-tomcat-9.0.80
    drwxr-xr-x. 2 root root   6 Aug 12  2018 bin
    drwxr-xr-x. 2 root root   6 Aug 12  2018 etc
    drwxr-xr-x. 2 root root   6 Aug 12  2018 games
    drwxr-xr-x. 2 root root   6 Aug 12  2018 include
    drwxr-xr-x. 2 root root   6 Aug 12  2018 lib
    drwxr-xr-x. 2 root root   6 Aug 12  2018 lib64
    drwxr-xr-x. 2 root root   6 Aug 12  2018 libexec
    drwxr-xr-x. 2 root root   6 Aug 12  2018 sbin
    drwxr-xr-x. 5 root root  49 Jul 20 11:24 share
    drwxr-xr-x. 2 root root   6 Aug 12  2018 src
    [root@tomcat local]# ln -s apache-tomcat-9.0.80 tomcat
    [root@tomcat local]# ll
    total 0
    drwxr-xr-x  9 root root 220 Oct 10 13:49 apache-tomcat-9.0.80
    drwxr-xr-x. 2 root root   6 Aug 12  2018 bin
    drwxr-xr-x. 2 root root   6 Aug 12  2018 etc
    drwxr-xr-x. 2 root root   6 Aug 12  2018 games
    drwxr-xr-x. 2 root root   6 Aug 12  2018 include
    drwxr-xr-x. 2 root root   6 Aug 12  2018 lib
    drwxr-xr-x. 2 root root   6 Aug 12  2018 lib64
    drwxr-xr-x. 2 root root   6 Aug 12  2018 libexec
    drwxr-xr-x. 2 root root   6 Aug 12  2018 sbin
    drwxr-xr-x. 5 root root  49 Jul 20 11:24 share
    drwxr-xr-x. 2 root root   6 Aug 12  2018 src
    lrwxrwxrwx  1 root root  20 Oct 10 13:51 tomcat -> apache-tomcat-9.0.80
    [root@tomcat local]# cd tomcat/
    [root@tomcat tomcat]# pwd
    //usr/local/tomcat
    [root@tomcat tomcat]# ls
    bin           conf             lib      logs    README.md      RUNNING.txt  webapps
    BUILDING.txt  CONTRIBUTING.md  LICENSE  NOTICE  RELEASE-NOTES  temp         work
    [root@tomcat tomcat]# ls bin/
    bootstrap.jar       ciphers.sh                    daemon.sh     setclasspath.bat  startup.sh            version.bat
    catalina.bat        commons-daemon.jar            digest.bat    setclasspath.sh   tomcat-juli.jar       version.sh
    catalina.sh         commons-daemon-native.tar.gz  digest.sh     shutdown.bat      tomcat-native.tar.gz
    catalina-tasks.xml  configtest.bat                makebase.bat  shutdown.sh       tool-wrapper.bat
    ciphers.bat         configtest.sh                 makebase.sh   startup.bat       tool-wrapper.sh
    
    上述的bin目录中我们能够用到的catalina.sh、shutdown.sh、version.sh、startup.sh、configtest.sh
    这几个执行文件,用途分别是:
    catalina.sh 能够关闭和开启服务(常用)
    shutdown.sh 只能关闭服务(不是关闭主机)
    startup.sh 只能开启服务
    version.sh 查看tomcat版本
    configtest.sh 测试配置文件是否存在错误,检查配置文件
    
    //将tomcat的lib位置存放在/etc/ld.so.conf/d/下面,命名一个自身名字的文件,方便查找
    [root@tomcat tomcat]# ls
    bin           conf             lib      logs    README.md      RUNNING.txt  webapps
    BUILDING.txt  CONTRIBUTING.md  LICENSE  NOTICE  RELEASE-NOTES  temp         work
    [root@tomcat tomcat]# vim /etc/ld.so.conf.d/tomcat.conf
    [root@tomcat tomcat]# cat /etc/ld.so.conf.d/tomcat.conf
    /usr/local/tomcat/lib
    [root@tomcat tomcat]# ldconfig -v
    ldconfig: Can't stat /libx32: No such file or directory
    ldconfig: Path `/usr/lib' given more than once
    ldconfig: Path `/usr/lib64' given more than once
    ldconfig: Can't stat /usr/libx32: No such file or directory
    /usr/lib64//bind9-export:
    	libisccfg-export.so.163 -> libisccfg-export.so.163.0.4
    	libisc-export.so.1104 -> libisc-export.so.1104.0.0
    	libirs-export.so.161 -> libirs-export.so.161.0.0
    	libdns-export.so.1107 -> libdns-export.so.1107.1.0
    /usr/local/tomcat/lib:
    /lib:
    /lib64:
    
    • 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
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76

    5.4.启动tomcat服务

    //使用绝对路径执行/usr/local/tomcat/bin/下面的脚本,tomcat不能写进环境变量,放置后续更改tomcat版本后环境变量仍是之前的tomcat版本
    [root@tomcat tomcat]# pwd
    //usr/local/tomcat
    [root@tomcat tomcat]# cd bin
    [root@tomcat bin]# pwd
    //usr/local/tomcat/bin
    [root@tomcat bin]# ./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@tomcat bin]# ss -antl
    State          Recv-Q         Send-Q                      Local Address:Port                 Peer Address:Port        
    LISTEN         0              128                               0.0.0.0:22                        0.0.0.0:*           
    LISTEN         0              1                      [::ffff:127.0.0.1]:8005                            *:*           
    LISTEN         0              100                                     *:8080                            *:*           
    LISTEN         0              128                                  [::]:22                           [::]:*
    [root@tomcat test]# ps -ef | grep tomcat       //查看tomcat进程
    root        1585       1  0 14:02 pts/0    00:00:06 /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        1640    1455  0 14:22 pts/0    00:00:00 grep --color=auto tomcat
    
    服务启动成功
    
    • 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

    5.5.访问tomcat的web页面

    在这里插入图片描述

    在部署tomcat过程中,网页存放目录在/usr/local/tomcat/webapps中,里面可以存放我们的网页,也可以放置app软件,而我们上述所访问到的页面则来自webapp目录中的ROOT目录中的项目

    [root@tomcat tomcat]# ls
    bin           conf             lib      logs    README.md      RUNNING.txt  webapps
    BUILDING.txt  CONTRIBUTING.md  LICENSE  NOTICE  RELEASE-NOTES  temp         work
    [root@tomcat tomcat]# cd webapps/
    [root@tomcat webapps]# ls
    docs  examples  host-manager  manager  ROOT
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    我们新建一个项目目录进行测试

    [root@tomcat webapps]# mkdir test && cd test
    [root@tomcat test]# vim index.jsp
    [root@tomcat test]# cat index.jsp 
    
    
            test page<<span class="token operator">/</span>title>
    <<span class="token operator">/</span>head>
    <body>
            <<span class="token operator">%</span>
                out<span class="token punctuation">.</span>println<span class="token punctuation">(</span><span class="token string">"Hellow World"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token operator">%</span>>
    <<span class="token operator">/</span>body>
    <<span class="token operator">/</span>html>
    <span class="token namespace">[root@tomcat test]</span><span class="token comment"># </span>
    <div class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.130496;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li></ul></pre> 
    <p><strong>访问test项目</strong></p> 
    <p>访问那个项目就在端口后加哪个项目名,不加则默认是ROOT<br> <img src="https://1000bd.com/contentImg/2024/03/13/035134458.png" alt="在这里插入图片描述"></p> 
    <h4><a name="t14"></a><a id="56webapps_304"></a>5.6.尝试访问webapps目录中其他项目</h4> 
    <p><img src="https://1000bd.com/contentImg/2024/03/13/035134436.png" alt="在这里插入图片描述"><br> <img src="https://1000bd.com/contentImg/2024/03/13/035134441.png" alt="在这里插入图片描述"><br> <img src="https://1000bd.com/contentImg/2024/03/13/035135101.png" alt="在这里插入图片描述"></p> 
    <p>解决方法:</p> 
    <pre data-index="7" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;">进入tomcat的conf目录中修改tomcat-user<span class="token punctuation">.</span>xml文件
    <span class="token namespace">[root@tomcat tomcat]</span><span class="token comment"># cd conf/</span>
    <span class="token namespace">[root@tomcat conf]</span><span class="token comment"># ls</span>
    Catalina         catalina<span class="token punctuation">.</span>properties  jaspic-providers<span class="token punctuation">.</span>xml  logging<span class="token punctuation">.</span>properties  tomcat-users<span class="token punctuation">.</span>xml  web<span class="token punctuation">.</span>xml
    catalina<span class="token punctuation">.</span>policy  context<span class="token punctuation">.</span>xml          jaspic-providers<span class="token punctuation">.</span>xsd  server<span class="token punctuation">.</span>xml          tomcat-users<span class="token punctuation">.</span>xsd
    <span class="token namespace">[root@tomcat conf]</span><span class="token comment"># vim tomcat-users.xml</span>
    <span class="token namespace">[root@tomcat conf]</span><span class="token comment"># tail -3 tomcat-users.xml</span>
    <role rolename=<span class="token string">"manager-gui"</span><span class="token operator">/</span>>              <span class="token operator">/</span><span class="token operator">/</span>设置角色
    <user username=<span class="token string">"tomcat"</span> password=<span class="token string">"tomcat123"</span> roles=<span class="token string">"manager-gui"</span><span class="token operator">/</span>>  <span class="token operator">/</span><span class="token operator">/</span>设置用户,密码,并指定角色
    <<span class="token operator">/</span>tomcat-users>
    
    进入tomcat的项目文件(webapps)中任选一个项目
    <span class="token namespace">[root@tomcat conf]</span><span class="token comment"># cd ../webapps/</span>
    <span class="token namespace">[root@tomcat webapps]</span><span class="token comment"># ls</span>
    docs  examples  host-manager  manager  ROOT  test
    <span class="token namespace">[root@tomcat webapps]</span><span class="token comment"># cd manager/</span>
    <span class="token namespace">[root@tomcat manager]</span><span class="token comment"># ls</span>
    css  images  index<span class="token punctuation">.</span>jsp  META-INF  status<span class="token punctuation">.</span>xsd  WEB-INF  xform<span class="token punctuation">.</span>xsl
    <span class="token namespace">[root@tomcat manager]</span><span class="token comment"># cd META-INF/</span>
    <span class="token namespace">[root@tomcat META-INF]</span><span class="token comment"># ls</span>
    context<span class="token punctuation">.</span>xml
    <span class="token namespace">[root@tomcat META-INF]</span><span class="token comment"># vim context.xml   //在allow中加入本机的ip网段</span>
    <span class="token namespace">[root@tomcat META-INF]</span><span class="token comment"># grep -A1 '<Valve className=' context.xml</span>
      <Valve className=<span class="token string">"org.apache.catalina.valves.RemoteAddrValve"</span>
             allow=<span class="token string">"192\.168\.195\.\d+|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1"</span> <span class="token operator">/</span>>
    
    <span class="token operator">/</span><span class="token operator">/</span>修改配置文件后重启服务
    <span class="token namespace">[root@tomcat META-INF]</span><span class="token comment"># /usr/local/tomcat/bin/catalina.sh stop</span>
    <span class="token keyword">Using</span> CATALINA_BASE:   <span class="token operator">/</span>usr/local/tomcat
    <span class="token keyword">Using</span> CATALINA_HOME:   <span class="token operator">/</span>usr/local/tomcat
    <span class="token keyword">Using</span> CATALINA_TMPDIR: <span class="token operator">/</span>usr/local/tomcat/temp
    <span class="token keyword">Using</span> JRE_HOME:        <span class="token operator">/</span>usr
    <span class="token keyword">Using</span> CLASSPATH:       <span class="token operator">/</span>usr/local/tomcat/bin/bootstrap<span class="token punctuation">.</span>jar:<span class="token operator">/</span>usr/local/tomcat/bin/tomcat-juli<span class="token punctuation">.</span>jar
    <span class="token keyword">Using</span> CATALINA_OPTS:   
    <span class="token namespace">[root@tomcat META-INF]</span><span class="token comment"># ss -antl</span>
    State          Recv-Q         <span class="token function">Send-Q</span>                   Local Address:Port                   Peer Address:Port         
    LISTEN         0              128                            0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:22                          0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:<span class="token operator">*</span>            
    LISTEN         0              128                               <span class="token punctuation">[</span>::<span class="token punctuation">]</span>:22                             <span class="token punctuation">[</span>::<span class="token punctuation">]</span>:<span class="token operator">*</span>            
    <span class="token namespace">[root@tomcat META-INF]</span><span class="token comment"># ps -ef | grep tomcat</span>
    <span class="token function">ps</span> <span class="token operator">-</span>ef <span class="token punctuation">|</span> grep tomcat
    root        1839    1455  0 15:06 pts/0    00:00:00 grep <span class="token operator">--</span>color=auto tomcat
    <span class="token namespace">[root@tomcat META-INF]</span><span class="token comment"># /usr/local/tomcat/bin/catalina.sh start</span>
    <span class="token keyword">Using</span> CATALINA_BASE:   <span class="token operator">/</span>usr/local/tomcat
    <span class="token keyword">Using</span> CATALINA_HOME:   <span class="token operator">/</span>usr/local/tomcat
    <span class="token keyword">Using</span> CATALINA_TMPDIR: <span class="token operator">/</span>usr/local/tomcat/temp
    <span class="token keyword">Using</span> JRE_HOME:        <span class="token operator">/</span>usr
    <span class="token keyword">Using</span> CLASSPATH:       <span class="token operator">/</span>usr/local/tomcat/bin/bootstrap<span class="token punctuation">.</span>jar:<span class="token operator">/</span>usr/local/tomcat/bin/tomcat-juli<span class="token punctuation">.</span>jar
    <span class="token keyword">Using</span> CATALINA_OPTS:   
    Tomcat started<span class="token punctuation">.</span>
    <span class="token namespace">[root@tomcat META-INF]</span><span class="token comment"># ss -antl</span>
    State          Recv-Q         <span class="token function">Send-Q</span>                      Local Address:Port                 Peer Address:Port        
    LISTEN         0              128                               0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:22                        0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:<span class="token operator">*</span>           
    LISTEN         0              1                      <span class="token punctuation">[</span>::ffff:127<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1<span class="token punctuation">]</span>:8005                            <span class="token operator">*</span>:<span class="token operator">*</span>           
    LISTEN         0              100                                     <span class="token operator">*</span>:8080                            <span class="token operator">*</span>:<span class="token operator">*</span>           
    LISTEN         0              128                                  <span class="token punctuation">[</span>::<span class="token punctuation">]</span>:22                           <span class="token punctuation">[</span>::<span class="token punctuation">]</span>:<span class="token operator">*</span>           
    <span class="token namespace">[root@tomcat META-INF]</span><span class="token comment"># ps -ef | grep tomcat</span>
    <span class="token function">ps</span> <span class="token operator">-</span>ef <span class="token punctuation">|</span> grep tomcat
    root        1852       1 11 15:06 pts/0    00:00:01 <span class="token operator">/</span>usr/bin/java <span class="token operator">-</span>Djava<span class="token punctuation">.</span>util<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>config<span class="token punctuation">.</span>file=<span class="token operator">/</span>usr/local/tomcat/conf/logging<span class="token punctuation">.</span>properties <span class="token operator">-</span>Djava<span class="token punctuation">.</span>util<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>manager=org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>juli<span class="token punctuation">.</span>ClassLoaderLogManager <span class="token operator">-</span>Djdk<span class="token punctuation">.</span>tls<span class="token punctuation">.</span>ephemeralDHKeySize=2048 <span class="token operator">-</span>Djava<span class="token punctuation">.</span>protocol<span class="token punctuation">.</span>handler<span class="token punctuation">.</span>pkgs=org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>webresources <span class="token operator">-</span>Dorg<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>security<span class="token punctuation">.</span>SecurityListener<span class="token punctuation">.</span>UMASK=0027 <span class="token operator">-</span>Dignore<span class="token punctuation">.</span>endorsed<span class="token punctuation">.</span>dirs= <span class="token operator">-</span>classpath <span class="token operator">/</span>usr/local/tomcat/bin/bootstrap<span class="token punctuation">.</span>jar:<span class="token operator">/</span>usr/local/tomcat/bin/tomcat-juli<span class="token punctuation">.</span>jar <span class="token operator">-</span>Dcatalina<span class="token punctuation">.</span>base=<span class="token operator">/</span>usr/local/tomcat <span class="token operator">-</span>Dcatalina<span class="token punctuation">.</span>home=<span class="token operator">/</span>usr/local/tomcat <span class="token operator">-</span>Djava<span class="token punctuation">.</span>io<span class="token punctuation">.</span>tmpdir=<span class="token operator">/</span>usr/local/tomcat/temp org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>startup<span class="token punctuation">.</span>Bootstrap <span class="token function">start</span>
    root        1883    1455  0 15:06 pts/0    00:00:00 grep <span class="token operator">--</span>color=auto tomcat
    <div class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.130496;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li><li style="color: rgb(153, 153, 153);">47</li><li style="color: rgb(153, 153, 153);">48</li><li style="color: rgb(153, 153, 153);">49</li><li style="color: rgb(153, 153, 153);">50</li><li style="color: rgb(153, 153, 153);">51</li><li style="color: rgb(153, 153, 153);">52</li><li style="color: rgb(153, 153, 153);">53</li><li style="color: rgb(153, 153, 153);">54</li><li style="color: rgb(153, 153, 153);">55</li><li style="color: rgb(153, 153, 153);">56</li><li style="color: rgb(153, 153, 153);">57</li><li style="color: rgb(153, 153, 153);">58</li><li style="color: rgb(153, 153, 153);">59</li></ul></pre> 
    <p><strong>再次访问</strong><br> <img src="https://1000bd.com/contentImg/2024/03/13/035134452.png" alt="在这里插入图片描述"><br> <img src="https://1000bd.com/contentImg/2024/03/13/035134642.png" alt="在这里插入图片描述"><br> <img src="https://1000bd.com/contentImg/2024/03/13/035134665.png" alt="在这里插入图片描述"><br> <img src="https://1000bd.com/contentImg/2024/03/13/035134646.png" alt="在这里插入图片描述"></p> 
    <p><strong>其他项目目录亦是如此,找到项目文件中的context.xml文件添加本机IP网段即可</strong><br> <img src="https://1000bd.com/contentImg/2024/03/13/035134554.png" alt="在这里插入图片描述"><br> <img src="https://1000bd.com/contentImg/2024/03/13/035134547.png" alt="在这里插入图片描述"></p> 
    <h3><a name="t15"></a><a id="_385"></a>总结:</h3> 
    <p>Tomcat是一个可靠、轻量级、跨平台的Java Web应用服务器,适用于许多中小型应用程序。它的工作原理基于Java Servlet和JSP规范,通过将请求分发给相应的Servlet或JSP来处理HTTP请求。虽然Tomcat在一些高级功能方面可能相对有限,但它作为一个开源项目,提供了一个可靠的基础,使得Java Web应用程序可以在其中运行。</p>
                    </div>
                        </div>
                    </li>
    
                    <li class="list-group-item ul-li">
    
                        <b>相关阅读:</b><br>
                        <nobr>
    <a href="/Article/Index/1527742">sqllab第二十四关通关笔记</a>                            <br />
    <a href="/Article/Index/1738934">获取HTML元素的offsetParent属性</a>                            <br />
    <a href="/Article/Index/1569372">nvm安装及使用(mac)</a>                            <br />
    <a href="/Article/Index/1018855">数据库的基础操作</a>                            <br />
    <a href="/Article/Index/1065479">我们正在经历一场机器身份危机</a>                            <br />
    <a href="/Article/Index/1417211">Go 的连接池、重试和超时</a>                            <br />
    <a href="/Article/Index/1315566">Kettle安装初始化问题</a>                            <br />
    <a href="/Article/Index/1456726">软件工程理论与实践 (吕云翔) 第六章 面向对象分析课后习题及其解析</a>                            <br />
    <a href="/Article/Index/1434708">matlab 读写ENVI标准数据</a>                            <br />
    <a href="/Article/Index/1109684">5 步!用阿里云 Serverless 搭建高质量的图片压缩工具</a>                            <br />
                        </nobr>
                    </li>
                    <li class="list-group-item from-a mb-2">
                        原文地址:https://blog.csdn.net/m0_64505752/article/details/133747799
                    </li>
    
                </ul>
            </div>
    
            <div class="col-lg-4 col-sm-12">
                <ul class="list-group" style="word-break:break-all;">
                    <li class="list-group-item ul-li-bg" aria-current="true">
                        最新文章
                    </li>
                    <li class="list-group-item ul-li">
                        <nobr>
    <a href="/Article/Index/1484446">攻防演习之三天拿下官网站群</a>                            <br />
    <a href="/Article/Index/1515268">数据安全治理学习——前期安全规划和安全管理体系建设</a>                            <br />
    <a href="/Article/Index/1759065">企业安全 | 企业内一次钓鱼演练准备过程</a>                            <br />
    <a href="/Article/Index/1485036">内网渗透测试 | Kerberos协议及其部分攻击手法</a>                            <br />
    <a href="/Article/Index/1877332">0day的产生 | 不懂代码的"代码审计"</a>                            <br />
    <a href="/Article/Index/1887576">安装scrcpy-client模块av模块异常,环境问题解决方案</a>                            <br />
    <a href="/Article/Index/1887578">leetcode hot100【LeetCode 279. 完全平方数】java实现</a>                            <br />
    <a href="/Article/Index/1887512">OpenWrt下安装Mosquitto</a>                            <br />
    <a href="/Article/Index/1887520">AnatoMask论文汇总</a>                            <br />
    <a href="/Article/Index/1887496">【AI日记】24.11.01 LangChain、openai api和github copilot</a>                            <br />
                        </nobr>
                    </li>
                </ul>
    
                <ul class="list-group pt-2" style="word-break:break-all;">
                    <li class="list-group-item ul-li-bg" aria-current="true">
                        热门文章
                    </li>
                    <li class="list-group-item ul-li">
                        <nobr>
    <a href="/Article/Index/888177">十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!</a>                            <br />
    <a href="/Article/Index/797680">奉劝各位学弟学妹们,该打造你的技术影响力了!</a>                            <br />
    <a href="/Article/Index/888183">五年了,我在 CSDN 的两个一百万。</a>                            <br />
    <a href="/Article/Index/888179">Java俄罗斯方块,老程序员花了一个周末,连接中学年代!</a>                            <br />
    <a href="/Article/Index/797730">面试官都震惊,你这网络基础可以啊!</a>                            <br />
    <a href="/Article/Index/797725">你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法</a>                            <br />
    <a href="/Article/Index/797702">心情不好的时候,用 Python 画棵樱花树送给自己吧</a>                            <br />
    <a href="/Article/Index/797709">通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!</a>                            <br />
    <a href="/Article/Index/797716">13 万字 C 语言从入门到精通保姆级教程2021 年版</a>                            <br />
    <a href="/Article/Index/888192">10行代码集2000张美女图,Python爬虫120例,再上征途</a>                            <br />
                        </nobr>
                    </li>
                </ul>
    
            </div>
        </div>
    </div>
    <!-- 主体 -->
    
    
        <!--body结束-->
        <!--这里是footer模板-->
        
        <!--footer-->
    <nav class="navbar navbar-inverse navbar-fixed-bottom">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <div class="text-muted center foot-height">
                        Copyright © 2022 侵权请联系<a href="mailto:2656653265@qq.com">2656653265@qq.com</a>   
                        <a href="https://beian.miit.gov.cn/" target="_blank">京ICP备2022015340号-1</a>
                    </div>
                    <div style="width:300px;margin:0 auto; padding:0px 5px;">
                        <a href="/regex.html">正则表达式工具</a>
                        <a href="/cron.html">cron表达式工具</a>
                        <a href="/pwdcreator.html">密码生成工具</a>
                    </div>
                    <div style="width:300px;margin:0 auto; padding:5px 0;">
                        <a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11010502049817" style="display:inline-block;text-decoration:none;height:20px;line-height:20px;">
                        <img src="" style="float:left;" /><p style="float:left;height:20px;line-height:20px;margin: 0px 0px 0px 5px; color:#939393;">京公网安备 11010502049817号</p></a>
                    </div>
                </div>
            </div>
        </div>
      
    </nav>
    <!--footer-->
    
        <!--footer模板结束-->
    
        <script src="/js/plugins/jquery/jquery.js"></script>
        <script src="/js/bootstrap.min.js"></script>
    
        <!--这里是scripts模板-->
        
    
        
     
    
    
        <!--scripts模板结束-->
    
    </body>
    </html>