查看目录:
[root@gaosh-1 apache-tomcat-7.0.79]# ls
bin lib logs RELEASE-NOTES temp work
conf LICENSE NOTICE RUNNING.txt webapps
[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
Context.xml 是 Tomcat 公用的环境配置,tomcat 服务器会定时去扫描这个文件。一旦发现文件被修改(时间戳改变了),就会自动重新加载这个文件,而不需要重启服务器。
服务一旦启动,在去修改server.xml,就得需要重新加载配置文件,或者重新启动服务来加载文件。 而context.xml的优势是无需重启。 所以我们一般会在这个文件中独立配置。
Web应用程序描述文件,都是关于是Web应用程序的配置文件。所有Web应用的 web.xml 文件的父文件。
server.xml是对tomcat的设置,可以设置端口号,添加虚拟机这些的,是对服务器的设置
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 <Server>
2 <Service>
3 <Connector />
4 <Connector />
5 <Engine>
6 <Host>
7 <Context />
8 </Host>
9 </Engine>
10 </Service>
11 </Server>
元素分为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%。 后面会拆分成一个个小的模块来详细讲解。