• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Tomcat 基础二十三

武飞扬头像
Coisini_LZB
帮助1

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

今天学习的是Tomcat 以下就是今天的全部内容,有点多,希望可以对我们的学习有所帮助。


一、概述

   1. Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。
   2. Tomcat虚拟主机是通过linux或windows操作系统下进行独立运行的一个网站发布容器,他是一种在单一主机或主机群上,实现多网域服务的方法,可以运行多个网站或服务的技术。
    3.默认监听端口
        8080/tcp

二、安装

1. 基础配置
        [root@localhost ~]# systemctl stop NetworkManager
        [root@localhost ~]# systemctl stop firewalld
        [root@localhost ~]# setenforce 0
        sed -i "/s/ONBOOT=no/ONBOOT=yes/" /etc/sysconfig/network-scripts/ifcfg-ens33
        systemctl restart network

学新通
   2. java环境
        java -version
        没有环境
            yum groupinstall "开发工具"
            下载JDK软件包
    tar xf apache-tomcat-8.5.16.tar.gz
    mv  apache-tomcat-8.5.16 /usr/local/tomcat 学新通

三、 目录结构

    bin      命令

学新通
    logs     日志

学新通
    conf      配置文件

学新通
    webapps     应用程序目录
            ROOT       访问首页
            host-manager     主机管理后台页面
            manager       管理后台页面 学新通

学新通

 四、启停

命令优化
        ln -s /usr/local/tomcat/bin/startup.sh /usr/local/bin/btomcat
        ln -s /usr/local/tomcat/bin/shutdown.sh /usr/local/bin/stomcat
    启动tomcat
        tmstart
    停止tomcat
        stomcat
    netstat -anptu | grep java
        查看运行状态

 学新通

测试: 

学新通

五、配置文件

1. server.xml

  1.  
    <?xml version="1.0" encoding="UTF-8"?>
  2.  
    <!--
  3.  
    Licensed to the Apache Software Foundation (ASF) under one or more
  4.  
    contributor license agreements. See the NOTICE file distributed with
  5.  
    this work for additional information regarding copyright ownership.
  6.  
    The ASF licenses this file to You under the Apache License, Version 2.0
  7.  
    (the "License"); you may not use this file except in compliance with
  8.  
    the License. You may obtain a copy of the License at
  9.  
     
  10.  
    http://www.apache.org/licenses/LICENSE-2.0
  11.  
     
  12.  
    Unless required by applicable law or agreed to in writing, software
  13.  
    distributed under the License is distributed on an "AS IS" BASIS,
  14.  
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15.  
    See the License for the specific language governing permissions and
  16.  
    limitations under the License.
  17.  
    -->
  18.  
    <!-- Note: A "Server" is not itself a "Container", so you may not
  19.  
    define subcomponents such as "Valves" at this level.
  20.  
    Documentation at /docs/config/server.html
  21.  
    -->
  22.  
    <Server port="8005" shutdown="SHUTDOWN">
  23.  
    <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  24.  
    <!-- Security listener. Documentation at /docs/config/listeners.html
  25.  
    <Listener className="org.apache.catalina.security.SecurityListener" />
  26.  
    -->
  27.  
    <!--APR library loader. Documentation at /docs/apr.html -->
  28.  
    <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  29.  
    <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  30.  
    <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  31.  
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  32.  
    <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
  33.  
     
  34.  
    <!-- Global JNDI resources
  35.  
    Documentation at /docs/jndi-resources-howto.html
  36.  
    -->
  37.  
    <GlobalNamingResources>
  38.  
    <!-- Editable user database that can also be used by
  39.  
    UserDatabaseRealm to authenticate users
  40.  
    -->
  41.  
    <Resource name="UserDatabase" auth="Container"
  42.  
    type="org.apache.catalina.UserDatabase"
  43.  
    description="User database that can be updated and saved"
  44.  
    factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
  45.  
    pathname="conf/tomcat-users.xml" />
  46.  
    </GlobalNamingResources>
  47.  
     
  48.  
    <!-- A "Service" is a collection of one or more "Connectors" that share
  49.  
    a single "Container" Note: A "Service" is not itself a "Container",
  50.  
    so you may not define subcomponents such as "Valves" at this level.
  51.  
    Documentation at /docs/config/service.html
  52.  
    -->
  53.  
    <Service name="Catalina">
  54.  
     
  55.  
    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
  56.  
    <!--
  57.  
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
  58.  
    maxThreads="150" minSpareThreads="4"/>
  59.  
    -->
  60.  
     
  61.  
     
  62.  
    <!-- A "Connector" represents an endpoint by which requests are received
  63.  
    and responses are returned. Documentation at :
  64.  
    Java HTTP Connector: /docs/config/http.html
  65.  
    Java AJP Connector: /docs/config/ajp.html
  66.  
    APR (HTTP/AJP) Connector: /docs/apr.html
  67.  
    Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
  68.  
    -->
  69.  
    <Connector port="8080" protocol="HTTP/1.1"
  70.  
    connectionTimeout="20000"
  71.  
    redirectPort="8443" />
  72.  
    <!-- A "Connector" using the shared thread pool-->
  73.  
    <!--
  74.  
    <Connector executor="tomcatThreadPool"
  75.  
    port="8080" protocol="HTTP/1.1"
  76.  
    connectionTimeout="20000"
  77.  
    redirectPort="8443" />
  78.  
    -->
  79.  
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
  80.  
    This connector uses the NIO implementation. The default
  81.  
    SSLImplementation will depend on the presence of the APR/native
  82.  
    library and the useOpenSSL attribute of the
  83.  
    AprLifecycleListener.
  84.  
    Either JSSE or OpenSSL style configuration may be used regardless of
  85.  
    the SSLImplementation selected. JSSE style configuration is used below.
  86.  
    -->
  87.  
    <!--
  88.  
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
  89.  
    maxThreads="150" SSLEnabled="true">
  90.  
    <SSLHostConfig>
  91.  
    <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
  92.  
    type="RSA" />
  93.  
    </SSLHostConfig>
  94.  
    </Connector>
  95.  
    -->
  96.  
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
  97.  
    This connector uses the APR/native implementation which always uses
  98.  
    OpenSSL for TLS.
  99.  
    Either JSSE or OpenSSL style configuration may be used. OpenSSL style
  100.  
    configuration is used below.
  101.  
    -->
  102.  
    <!--
  103.  
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
  104.  
    maxThreads="150" SSLEnabled="true" >
  105.  
    <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
  106.  
    <SSLHostConfig>
  107.  
    <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
  108.  
    certificateFile="conf/localhost-rsa-cert.pem"
  109.  
    certificateChainFile="conf/localhost-rsa-chain.pem"
  110.  
    type="RSA" />
  111.  
    </SSLHostConfig>
  112.  
    </Connector>
  113.  
    -->
  114.  
     
  115.  
    <!-- Define an AJP 1.3 Connector on port 8009 -->
  116.  
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
  117.  
     
  118.  
     
  119.  
    <!-- An Engine represents the entry point (within Catalina) that processes
  120.  
    every request. The Engine implementation for Tomcat stand alone
  121.  
    analyzes the HTTP headers included with the request, and passes them
  122.  
    on to the appropriate Host (virtual host).
  123.  
    Documentation at /docs/config/engine.html -->
  124.  
     
  125.  
    <!-- You should set jvmRoute to support load-balancing via AJP ie :
  126.  
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
  127.  
    -->
  128.  
    <Engine name="Catalina" defaultHost="localhost">
  129.  
     
  130.  
    <!--For clustering, please take a look at documentation at:
  131.  
    /docs/cluster-howto.html (simple how to)
  132.  
    /docs/config/cluster.html (reference documentation) -->
  133.  
    <!--
  134.  
    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  135.  
    -->
  136.  
     
  137.  
    <!-- Use the LockOutRealm to prevent attempts to guess user passwords
  138.  
    via a brute-force attack -->
  139.  
    <Realm className="org.apache.catalina.realm.LockOutRealm">
  140.  
    <!-- This Realm uses the UserDatabase configured in the global JNDI
  141.  
    resources under the key "UserDatabase". Any edits
  142.  
    that are performed against this UserDatabase are immediately
  143.  
    available for use by the Realm. -->
  144.  
    <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  145.  
    resourceName="UserDatabase"/>
  146.  
    </Realm>
  147.  
     
  148.  
    <Host name="www.jx1.com" appBase="webapps/jx1"
  149.  
    unpackWARs="true" autoDeploy="true">
  150.  
     
  151.  
    <!-- SingleSignOn valve, share authentication between web applications
  152.  
    Documentation at: /docs/config/valve.html -->
  153.  
    <!--
  154.  
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  155.  
    -->
  156.  
     
  157.  
    <!-- Access log processes all example.
  158.  
    Documentation at: /docs/config/valve.html
  159.  
    Note: The pattern used is equivalent to using pattern="common" -->
  160.  
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  161.  
    prefix="jx1_access_log" suffix=".txt"
  162.  
    pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  163.  
     
  164.  
    </Host>
  165.  
     
  166.  
    <Host name="www.jx2.com" appBase="webapps/jx2"
  167.  
    unpackWARs="true" autoDeploy="true">
  168.  
     
  169.  
    <!-- SingleSignOn valve, share authentication between web applications
  170.  
    Documentation at: /docs/config/valve.html -->
  171.  
    <!--
  172.  
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  173.  
    -->
  174.  
     
  175.  
    <!-- Access log processes all example.
  176.  
    Documentation at: /docs/config/valve.html
  177.  
    Note: The pattern used is equivalent to using pattern="common" -->
  178.  
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  179.  
    prefix="jx2_access_log" suffix=".txt"
  180.  
    pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  181.  
     
  182.  
    </Host>
  183.  
     
  184.  
    </Engine>
  185.  
    </Service>
  186.  
    <Service name="Catalina1">
  187.  
     
  188.  
    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
  189.  
    <!--
  190.  
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
  191.  
    maxThreads="150" minSpareThreads="4"/>
  192.  
    -->
  193.  
     
  194.  
     
  195.  
    <!-- A "Connector" represents an endpoint by which requests are received
  196.  
    and responses are returned. Documentation at :
  197.  
    Java HTTP Connector: /docs/config/http.html
  198.  
    Java AJP Connector: /docs/config/ajp.html
  199.  
    APR (HTTP/AJP) Connector: /docs/apr.html
  200.  
    Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
  201.  
    -->
  202.  
    <Connector port="8081" protocol="HTTP/1.1"
  203.  
    connectionTimeout="20000"
  204.  
    redirectPort="8444" />
  205.  
    <!-- A "Connector" using the shared thread pool-->
  206.  
    <!--
  207.  
    <Connector executor="tomcatThreadPool"
  208.  
    port="8080" protocol="HTTP/1.1"
  209.  
    connectionTimeout="20000"
  210.  
    redirectPort="8443" />
  211.  
    -->
  212.  
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
  213.  
    This connector uses the NIO implementation. The default
  214.  
    SSLImplementation will depend on the presence of the APR/native
  215.  
    library and the useOpenSSL attribute of the
  216.  
    AprLifecycleListener.
  217.  
    Either JSSE or OpenSSL style configuration may be used regardless of
  218.  
    the SSLImplementation selected. JSSE style configuration is used below.
  219.  
    -->
  220.  
    <!--
  221.  
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
  222.  
    maxThreads="150" SSLEnabled="true">
  223.  
    <SSLHostConfig>
  224.  
    <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
  225.  
    type="RSA" />
  226.  
    </SSLHostConfig>
  227.  
    </Connector>
  228.  
    -->
  229.  
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
  230.  
    This connector uses the APR/native implementation which always uses
  231.  
    OpenSSL for TLS.
  232.  
    Either JSSE or OpenSSL style configuration may be used. OpenSSL style
  233.  
    configuration is used below.
  234.  
    -->
  235.  
    <!--
  236.  
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
  237.  
    maxThreads="150" SSLEnabled="true" >
  238.  
    <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
  239.  
    <SSLHostConfig>
  240.  
    <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
  241.  
    certificateFile="conf/localhost-rsa-cert.pem"
  242.  
    certificateChainFile="conf/localhost-rsa-chain.pem"
  243.  
    type="RSA" />
  244.  
    </SSLHostConfig>
  245.  
    </Connector>
  246.  
    -->
  247.  
     
  248.  
    <!-- Define an AJP 1.3 Connector on port 8009 -->
  249.  
    <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
  250.  
     
  251.  
     
  252.  
    <!-- An Engine represents the entry point (within Catalina) that processes
  253.  
    every request. The Engine implementation for Tomcat stand alone
  254.  
    analyzes the HTTP headers included with the request, and passes them
  255.  
    on to the appropriate Host (virtual host).
  256.  
    Documentation at /docs/config/engine.html -->
  257.  
     
  258.  
    <!-- You should set jvmRoute to support load-balancing via AJP ie :
  259.  
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
  260.  
    -->
  261.  
    <Engine name="Catalina1" defaultHost="localhost">
  262.  
     
  263.  
    <!--For clustering, please take a look at documentation at:
  264.  
    /docs/cluster-howto.html (simple how to)
  265.  
    /docs/config/cluster.html (reference documentation) -->
  266.  
    <!--
  267.  
    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  268.  
    -->
  269.  
     
  270.  
    <!-- Use the LockOutRealm to prevent attempts to guess user passwords
  271.  
    via a brute-force attack -->
  272.  
    <Realm className="org.apache.catalina.realm.LockOutRealm">
  273.  
    <!-- This Realm uses the UserDatabase configured in the global JNDI
  274.  
    resources under the key "UserDatabase". Any edits
  275.  
    that are performed against this UserDatabase are immediately
  276.  
    available for use by the Realm. -->
  277.  
    <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  278.  
    resourceName="UserDatabase"/>
  279.  
    </Realm>
  280.  
     
  281.  
    <Host name="www.jx3.com" appBase="webapps/jx3"
  282.  
    unpackWARs="true" autoDeploy="true">
  283.  
     
  284.  
    <!-- SingleSignOn valve, share authentication between web applications
  285.  
    Documentation at: /docs/config/valve.html -->
  286.  
    <!--
  287.  
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  288.  
    -->
  289.  
     
  290.  
    <!-- Access log processes all example.
  291.  
    Documentation at: /docs/config/valve.html
  292.  
    Note: The pattern used is equivalent to using pattern="common" -->
  293.  
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  294.  
    prefix="jx3_access_log" suffix=".txt"
  295.  
    pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  296.  
     
  297.  
    </Host>
  298.  
     
  299.  
    <Host name="www.jx4.com" appBase="webapps/jx4"
  300.  
    unpackWARs="true" autoDeploy="true">
  301.  
     
  302.  
    <!-- SingleSignOn valve, share authentication between web applications
  303.  
    Documentation at: /docs/config/valve.html -->
  304.  
    <!--
  305.  
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  306.  
    -->
  307.  
     
  308.  
    <!-- Access log processes all example.
  309.  
    Documentation at: /docs/config/valve.html
  310.  
    Note: The pattern used is equivalent to using pattern="common" -->
  311.  
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  312.  
    prefix="jx4_access_log" suffix=".txt"
  313.  
    pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  314.  
     
  315.  
    </Host>
  316.  
     
  317.  
    </Engine>
  318.  
    </Service>
  319.  
    </Server>
学新通

(1) Server

erver是server.xml的根元素,用于创建一个Server实例,默认使用的实现类是 org.apache.catalina.core.StandardServer。
内嵌的子元素为 Listener、GlobalNamingResources、Service。
    port

        tomcat      监听的关闭服务器的端口。
        shutdown       关闭服务器的指令字符串

(2) Listener

<!‐‐ 用于以日志形式输出服务器 、操作系统、JVM的版本信息 ‐‐>
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />

<!‐‐ 用于加载(服务器启动) 和 销毁 (服务器停止) APR。 如果找不到APR库, 则会输出日志, 并不影响Tomcat启动 ‐‐>
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />

<!‐‐ 用于避免JRE内存泄漏问题 ‐‐>
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />

<!‐‐ 用户加载(服务器启动) 和 销毁(服务器停止) 全局命名服务 ‐‐>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

<!‐‐ 用于在Context停止时重建Executor 池中的线程, 以避免ThreadLocal 相关的内存泄漏 ‐‐>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />


(3) GlobalNamingResources

<GlobalNamingResources>
    <!‐‐ 可编辑的用户数据库,UserDatabaseRealm也可以使用该数据库对用户进行身份验证 ‐‐>
    <Resource     name="UserDatabase" 
                auth="Container" 
                type="org.apache.catalina.UserDatabase" 
                description="User database that can be updated and saved" 
                factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 
                pathname="conf/tomcat‐users.xml" />
</GlobalNamingResources>

(4) Service

该元素用于创建 Service 实例,默认使用 org.apache.catalina.core.StandardService。默认情况下,Tomcat 仅指定了Service 的名称, 值为 “Catalina”。Service 可以内嵌的元素为 : Listener、Executor、Connector、Engine,其中 : Listener 用于为Service添加生命周期监听器, Executor 用于配置Service 共享线程池,Connector 用于配置Service 包含的链接器, Engine 用于配置Service中链接器对应的Servlet 容器引擎。一个Server服务器,可以包含多个Service服务。

01.Connector

executor:指定共享线程池的名称, 也可以通过maxThreads、minSpareThreads 等属性配置内部线程池。

URIEncoding:用于指定编码URI的字符编码, Tomcat8.x版本默认的编码为UTF-8 , Tomcat7.x版本默认为ISO-8859-1。

maxThreads:池中最大线程数。

minSpareThreads:活跃线程数,也就是核心池线程数,这些线程不会被销毁,会一直存在。

acceptCount:接收的连接数。

maxConnections:接收的最大连接数。

compression:是否压缩。

compressionMinSize:压缩的大小。

disableUploadTimeout:禁用上传超时。

       (1) port

端口号,Connector 用于创建服务端Socket 并进行监听, 以等待客户端请求链接。如果该属性设置为0,Tomcat将会随机选择一个可用的端口号给当前Connector使用。


       (2) protocol

当前Connector 支持的访问协议。 默认为 HTTP/1.1,并采用自动切换机制选择一个基于 JAVA NIO 的链接器或者基于本地APR的链接器(根据本地是否含有Tomcat的本地库判定)


        (3)connectionTimeout

Connector接收连接后的等待超时时间, 单位为毫秒。 -1 表示不超时。


        (4)redirectPort

当前Connector 不支持SSL请求, 接收到了一个请求, 并且也符合 security-constraint 约束, 需要SSL传输,Catalina自动将请求重定向到指定的端口。


    02.Engine
        (1)name

用于指定Engine的名称, 默认为Catalina 。该名称会影响一部分Tomcat的存储路径(如临时文件)。


        (2)defaultHost

默认使用的虚拟主机名称, 当客户端请求指向的主机无效时, 将交由默认的虚拟主机处理, 默认为localhost。


       (3) Host

Host 元素用于配置一个虚拟主机, 它支持以下嵌入元素:Alias、Cluster、Listener、Valve、Realm、Context。

<Host name="www.web1.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
    <Alias>www.web2.com</Alias>
</Host>

           01. name

Host 元素用于配置一个虚拟主机, 它支持以下嵌入元素:Alias、Cluster、Listener、Valve、Realm、Context。

<Host name="www.web1.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
    <Alias>www.web2.com</Alias>
</Host>

           02. appBase

当前Host的应用基础目录,当前Host上部署的Web应用均在该目录下(可以是绝对目录,相对路径),默认为webapps


            03.unpackWARs

设置为true,Host在启动时会将appBase目录下war包解压为目录。设置为false, Host将直接从war文件启动。


            04.autoDeploy

控制tomcat是否在运行时定期检测并自动部署新增或变更的web应用。

(5) Context

 1.docBase

Web应用目录或者War包的部署路径。可以是绝对路径,也可以是相对于Host appBase的相对路径。

   2. path

Web应用的Context 路径。如果我们Host名为localhost, 则该web应用访问的根路径为: http://localhost:8080/myApp。

2. tomcat-users.xml 

主要配置的是Tomcat的用户,角色等信息,用来控制Tomcat中 host-manager、manager的访问权限。

3. web.xml 

web.xml 是web应用的描述文件, 它支持的元素及属性来自于Servlet 规范定义 。 在Tomcat 中, Web 应用的描述信息包括 tomcat/conf/web.xml 中默认配置以及 Web应用 WEB-INF/web.xml 下的定制配置。

六、多tomcat服务部署

1. 部署

   tar xf apache-tomcat-8.5.16.tar.gz
   mv  apache-tomcat-8.5.16 /usr/local/tomcat1

学新通
 2. 命令优化

        ln -s /usr/local/tomcat1/bin/startup.sh /usr/local/bin/tmstart
        ln -s /usr/local/tomcat1/bin/shutdown.sh /usr/local/bin/tmstop


 3. 端口号修改

   server
            port
   connector
            port
            redirectport 

学新通

学新通

学新通

学新通


 4.修改访问页面

   vim  /usr/local/tomcat/webapps/ROOT/index.jsp
        <%
           out.println("tomcat");
       %>

 学新通学新通

测试 

学新通

七、虚拟主机

  1.  基于不同的域名
        复制Host字段
            <Host></Host>
        修改不同Host的name属性,改为不同的域名
        修改webapps指定为不同的访问路径
        修改日志名称
        创建访问目录及首页
            mkdir   /usr/local/tomcat1/jx1/ROOT -p
            vim index.jsp

  1.  
    <Host name="www.jx1.com" appBase="jx1"
  2.  
    unpackWARs="true" autoDeploy="true">
  3.  
     
  4.  
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  5.  
    prefix="jx1_access_log" suffix=".txt"
  6.  
    pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  7.  
    </Host>
  8.  
     
  9.  
    <Host name="www.jx2.com" appBase="jx2"
  10.  
    unpackWARs="true" autoDeploy="true">
  11.  
     
  12.  
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  13.  
    prefix="jx2_access_log" suffix=".txt"
  14.  
    pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  15.  
    </Host>
学新通

学新通

学新通 学新通

 测试

学新通

学新通


    2. 基于不同的端口

  1.  
    <Service name="Catalina1">
  2.  
     
  3.  
    <Connector port="8082" protocol="HTTP/1.1"
  4.  
    connectionTimeout="20000"
  5.  
    redirectPort="8445" />
  6.  
    <Connector port="8011" protocol="AJP/1.3" redirectPort="8445" />
  7.  
     
  8.  
     
  9.  
    <Engine name="Catalina1" defaultHost="localhost1">
  10.  
     
  11.  
    <Realm className="org.apache.catalina.realm.LockOutRealm">
  12.  
    <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  13.  
    resourceName="UserDatabase"/>
  14.  
    </Realm>
  15.  
     
  16.  
    <Host name="localhost1" appBase="webapps1"
  17.  
    unpackWARs="true" autoDeploy="true">
  18.  
     
  19.  
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  20.  
    prefix="localhost1_access_log" suffix=".txt"
  21.  
    pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  22.  
     
  23.  
    </Host>
  24.  
    </Engine>
  25.  
    </Service>
学新通


        复制Service字段
            <Service></Service>
        修改Service的name属性
        修改Engine的name属性
        修改Host的name及appbase属性
        修改日志名称
        端口号修改
            service
                port
            connector
                port
                redirectport
        在webapps1中创建ROOT目录并写入首页
            mkdir /usr/local/tomcat/webapps1/ROOT  
            vim index.jsp


总结

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgbkkch
系列文章
更多 icon
同类精品
更多 icon
继续加载