tomcat配置文件详解

文章目录

目录结构及作用
tomcat配置文件

  1. context.xml
  2. web.xml
  3. server.xml
  4. tomcat-users.xml
    运维常用配置文件讲解
  5. 整体结构
  6. 元素分类
    总结

目录结构及作用

查看目录:

[root@gaosh-1 apache-tomcat-7.0.79]# ls
bin   lib      logs    RELEASE-NOTES  temp     work
conf  LICENSE  NOTICE  RUNNING.txt    webapps

  • bin :脚本文件目录。
  • conf:存放配置文件,最重要的是server.xml。
  • logs:存放日志文件。
  • lib :仅对所有WEB APP可见,对TOMCAT不可见(使用Shared类加载器加载)。
  • temp:Tomcat运行时候存放临时文件用的。
  • webapps:web应用发布目录。
  • work:Tomcat把各种由jsp生成的servlet文件放在这个目录下。删除后,启动时会自动创建。

懒得画图,从网上找了一张图,很直观:
在这里插入图片描述

tomcat配置文件

[root@gaosh-1 conf]# ls
Catalina context.xml tomcat-users.xml
catalina.policy logging.properties web.xml
catalina.properties server.xml
[root@gaosh-1 conf]#

Tomcat 的配置文件由4个 xml 文件构成,context.xml、web.xml、server.xml、tomcat-users.xml

1. context.xml

Context.xml 是 Tomcat 公用的环境配置,tomcat 服务器会定时去扫描这个文件。一旦发现文件被修改(时间戳改变了),就会自动重新加载这个文件,而不需要重启服务器。

服务一旦启动,在去修改server.xml,就得需要重新加载配置文件,或者重新启动服务来加载文件。 而context.xml的优势是无需重启。 所以我们一般会在这个文件中独立配置。

2. web.xml

Web应用程序描述文件,都是关于是Web应用程序的配置文件。所有Web应用的 web.xml 文件的父文件。

3. server.xml

server.xml是对tomcat的设置,可以设置端口号,添加虚拟机这些的,是对服务器的设置

4. tomcat-users.xml

Tomcat Manager是Tomcat自带的、用于对Tomcat自身以及部署在Tomcat上的应用进行管理的web应用。Tomcat是Java领域使用最广泛的服务器之一,因此Tomcat Manager也成为了使用非常普遍的功能应用。
Tomcat Manager的用户配置是在Tomcat安装目录/conf/tomcat-users.xml文件中进行管理的

运维常用配置文件讲解

作为运维用的最多的还是server.xml,我们先来探讨这个文件

vim server.xml

<?xml version='1.0' encoding='utf-8'?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0
  distributed under the License is distributed on an "AS IS" BASIS,
  limitations under the License.
 -->
 ### 上面一堆说的是你可以通过上买的那个网址获得授权的副本, 与咱们没关系,就相当于个声明
<Server port="8005" shutdown="SHUTDOWN">
  -->
  #### 关闭使用的端口
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.JasperListener" />

  <!-- Global JNDI resources   
       Documentation at /docs/jndi-resources-howto.html
  -->
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              pathname="conf/tomcat-users.xml" />
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">
  ### 定义service组件,用来关联executor和engine

    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
         and responses are returned. Documentation at :
    <Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
         documentation -->
    <!--
               clientAuth="false" sslProtocol="TLS" />
    -->



         on to the appropriate Host (virtual host).
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="www.zmkjedu.com">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      -->
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
             resources under the key "UserDatabase".  Any edits
             available for use by the Realm.  -->
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="www.zmkjedu.com"  appBase="/web"
<?xml version='1.0' encoding='utf-8'?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0
  distributed under the License is distributed on an "AS IS" BASIS,
  limitations under the License.
 -->
<Server port="8005" shutdown="SHUTDOWN">
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.JasperListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              pathname="conf/tomcat-users.xml" />
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
126             unpackWARs="true" autoDeploy="true">
127 
128         <!-- SingleSignOn valve, share authentication between we    b applications
129              Documentation at: /docs/config/valve.html -->
130         <!--
131         <Valve className="org.apache.catalina.authenticator.Sing    leSignOn" />
132         -->
133 
134         <!-- Access log processes all example.
135              Documentation at: /docs/config/valve.html
136              Note: The pattern used is equivalent to using patte    rn="common" -->
137         <Valve className="org.apache.catalina.valves.AccessLogVa    lve" directory="logs"
138                prefix="localhost_access_log." suffix=".txt"
139                pattern="%h %l %u %t "%r" %s %b" />
140 
141       </Host>
142     </Engine>
143   </Service>
144 </Server>

1. 整体结构
 1  <Server>
 2   <Service>
 3         <Connector />
 4         <Connector />
 5         <Engine>
 6             <Host>
 7                 <Context />
 8             </Host>
 9         </Engine>
10     </Service>
11 </Server>
2. 元素分类

元素分为4类
1)顶层元素:和

元素是整个配置文件的根元素,元素则代表一个Engine元素以及一组与之相连的Connector元素。

(2)连接器:

代表了外部客户端发送请求到特定Service的接口;同时也是外部客户端从特定Service接收响应的接口。

(3)容器:

容器的功能是处理Connector接收进来的请求,并产生相应的响应。Engine、Host和Context都是容器,但它们不是平行的关系,而是父子关系:Engine包含Host,Host包含Context。一个Engine组件可以处理Service中的所有请求,一个Host组件可以处理发向一个特定虚拟主机的所有请求,一个Context组件可以处理一个特定Web应用的所有请求。

(4)内嵌组件:可以内嵌到容器中的组件。实际上,Server、Service、Connector、Engine、Host和Context是最重要的最核心的Tomcat组件,其他组件都可以归为内嵌组件。

总结

东西实在太多,快6000字了还没写完,感觉才写了20%。 后面会拆分成一个个小的模块来详细讲解。

本文转自 ID: 互联网老辛 更多内容关注公众号《极客运维之家》,扫码添加:

在这里插入图片描述

  • 10
    点赞
  • 56
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值