文章目录

  • ​​前言​​
  • ​​一、目录结构及作用​​
  • ​​二、conf配置文件​​
  • ​​1、概述​​
  • ​​a、context.xml​​
  • ​​b、web.xml​​
  • ​​c、server.xml​​
  • ​​d、tomcat-users.xml​​
  • ​​1、配置文件: server.xml​​
  • ​​a、全部内容​​
  • ​​b、全部内容(去掉注释)​​
  • ​​c、标签分析​​
  • ​​3、配置文件:待写​​

前言

  1. 很久没有用到tomcat了,因老师需求是springboot项目,所以打算系统整理一下,有些地方也借鉴了其他博文,在此表示感谢。
  2. tomcat版本:​​apache-tomcat-7.0.70​

一、目录结构及作用

查看目录:

(base) C02ZT6HWLVDL:apache-tomcat-7.0.70 alsc$ ls -l
total 176
-rw-r--r--@ 1 alsc staff 56846 Jun 16 2016 LICENSE
-rw-r--r--@ 1 alsc staff 1239 Jun 16 2016 NOTICE
-rw-r--r--@ 1 alsc staff 8965 Jun 16 2016 RELEASE-NOTES
-rw-r--r--@ 1 alsc staff 16195 Jun 16 2016 RUNNING.txt
drwxr-xr-x@ 25 alsc staff 800 Nov 2 17:11 bin
drwxr-xr-x@ 10 alsc staff 320 Nov 7 17:17 conf
drwxr-xr-x@ 23 alsc staff 736 Jun 16 2016 lib
drwxr-xr-x@ 19 alsc staff 608 Nov 8 12:54 logs
drwxr-xr-x@ 3 alsc staff 96 Jun 16 2016 temp
drwxr-xr-x@ 7 alsc staff 224 Jun 16 2016 webapps
drwxr-xr-x@ 3 alsc staff 96 Nov 2 17:12 work
(base) C02ZT6HWLVDL:apache-tomcat-7.0.70 alsc$

tomcat学习一:tomcat 目录及配置文件学习 server.xml 等_学习

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

懒得画图,从网上找了一张图,很直观:

tomcat学习一:tomcat 目录及配置文件学习 server.xml 等_servlet_02

二、conf配置文件

1、概述

  • 查看:
(base) C02ZT6HWLVDL:conf alsc$ ls -l
total 408
drwxr-xr-x 3 alsc staff 96 Nov 2 17:12 Catalina
-rw-------@ 1 alsc staff 12257 Jun 16 2016 catalina.policy
-rw-------@ 1 alsc staff 6322 Jun 16 2016 catalina.properties
-rw-------@ 1 alsc staff 1394 Jun 16 2016 context.xml
-rw-------@ 1 alsc staff 3288 Jun 16 2016 logging.properties
-rw-------@ 1 alsc staff 1759 Nov 7 17:17 server.xml
-rw-------@ 1 alsc staff 1950 Jun 16 2016 tomcat-users.xml
-rw-------@ 1 alsc staff 168099 Jun 16 2016 web.xml
  • Tomcat 的配置文件由4个 xml 文件构成,​​context.xml​​​、​​server.xml​​​、​​tomcat-users.xml​​​、​​web.xml​​。

a、context.xml

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

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

b、web.xml

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

c、server.xml

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

d、tomcat-users.xml

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

1、配置文件: server.xml

a、全部内容

直接复制过来的

<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<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>

<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">

<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->


<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<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"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the BIO implementation that requires the JSSE
style configuration. When using the APR/native implementation, the
OpenSSL style configuration is required as described in the APR/native
documentation -->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->

<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">

<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->

<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>

<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">

<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->

<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />

</Host>
</Engine>
</Service>
</Server>

b、全部内容(去掉注释)

<?xml version='1.0' encoding='utf-8'?>

<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

<GlobalNamingResources>
<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>

<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>

<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>

c、标签分析

​​Tomcat Server.xml配置详解

3、配置文件:待写