Tomcat是基于組件的服務(wù)器,它的構(gòu)成組件都是可配置的,Tomcat各組件是在<Tomcat_HOME>confserver.xml文件中配置,其配置文件內(nèi)容如下:
<?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" /> <!-- 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 Java AJP Connector: /docs/config/ajp.html APR (HTTP/AJP) Connector: /docs/apr.html Define a non-SSL/TLS 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/TLS HTTP/1.1 Connector on port 8443 This connector uses the NIO implementation. The default SSLImplementation will depend on the presence of the APR/native library and the useOpenSSL attribute of the AprLifecycleListener. Either JSSE or OpenSSL style configuration may be used regardless of the SSLImplementation selected. JSSE style configuration is used below. --> <!-- <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true"> <SSLHostConfig> <Certificate certificateKeystoreFile="conf/localhost-rsa.jks" type="RSA" /> </SSLHostConfig> </Connector> --> <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2 This connector uses the APR/native implementation which always uses OpenSSL for TLS. Either JSSE or OpenSSL style configuration may be used. OpenSSL style configuration is used below. --> <!-- <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol" maxThreads="150" SSLEnabled="true" > <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" /> <SSLHostConfig> <Certificate certificateKeyFile="conf/localhost-rsa-key.pem" certificateFile="conf/localhost-rsa-cert.pem" certificateChainFile="conf/localhost-rsa-chain.pem" type="RSA" /> </SSLHostConfig> </Connector> --> <!-- 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>
二 組件分析1.server組件
<Server port="8005" shutdown="SHUTDOWN">
監(jiān)聽8005端口,接收關(guān)閉Tomcat的SHUTDOWN命令。一個Server實例就是一個JVM。
2.service組件
<Service name="Catalina">
用于關(guān)聯(lián)連接器(Connector)和引擎(Engine);一個service里面包含一個引擎和一個或多個連接器。
3.Connector組件
<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol" maxThreads="150" SSLEnabled="true" >
每個連接器有一個特定的端口和協(xié)議,它接收入站請求交給引擎處理,也將引擎處理結(jié)果交給客戶。連接器類型有:
Http Connector:基于HTTP協(xié)議,負(fù)責(zé)建立HTTP連接。它又分為BIO Http Connector與NIO Http Connector兩種,后者提供非阻塞IO與長連接Comet支持。 AJP Connector:基于AJP協(xié)議,AJP是專門設(shè)計用于Tomcat與HTTP服務(wù)器通信定制的協(xié)議,能提供較高的通信速度和效率。如與Apache服務(wù)器集成時,采用這個協(xié)議。 APR HTTP Connector:用C實現(xiàn),通過JNI調(diào)用的。主要提升對靜態(tài)資源(如HTML、圖片、CSS、JS等)的訪問性能。現(xiàn)在這個庫已獨立出來可用在任何項目中。由于APR性能較前兩類有很大提升,所以目前是Tomcat的默認(rèn)Connector。4.Engine組件
<Engine name="Catalina" defaultHost="localhost">
defaultHost:Tomcat支持基于FQDN的虛擬主機(jī),這些虛擬主機(jī)可以通過在Engine容器中定義多個不同的Host組件來實現(xiàn);但如果此引擎的連接器收到一個發(fā)往非非明確定義虛擬主機(jī)的請求時則需要將此請求發(fā)往一個默認(rèn)的虛擬主機(jī)進(jìn)行處理,因此,在Engine中定義的多個虛擬主機(jī)的主機(jī)名稱中至少要有一個跟defaultHost定義的主機(jī)名稱同名;
name:Engine組件的名稱,用于日志和錯誤信息記錄時區(qū)別不同的引擎;
Engine容器中可以包含Realm、Host、Listener和Valve子容器。
5.host組件
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
位于Engine容器中用于接收請求并進(jìn)行相應(yīng)處理的主機(jī)或虛擬主機(jī)。
6.Context組件
一個Context定義用于標(biāo)識tomcat實例中的一個Web應(yīng)用程序。
7.Realm組件
<Realm className="org.apache.catalina.realm.LockOutRealm">
一個Realm表示一個安全上下文,它是一個授權(quán)訪問某個給定Context的用戶列表和某用戶所允許切換的角色相關(guān)定義的列表。因此,Realm就像是一個用戶和組相關(guān)的數(shù)據(jù)庫。定義Realm時惟一必須要提供的屬性是classname,它是Realm的多個不同實現(xiàn),用于表示此Realm認(rèn)證的用戶及角色等認(rèn)證信息的存放位置。
8.Value組件
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" />
Valve類似于過濾器,它可以工作于Engine和Host/Context之間、Host和Context之間以及Context和Web應(yīng)用程序的某資源之間。一個容器內(nèi)可以建立多個Valve,而且Valve定義的次序也決定了它們生效的次序。
網(wǎng)站名稱:Tomcat架構(gòu)探究
路徑分享:http://www.rwnh.cn/article38/cgjssp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、網(wǎng)站制作、微信公眾號、服務(wù)器托管、網(wǎng)站改版、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)