?
Tomcat的server.xml配置節(jié)點(diǎn)簡介
?
tomcat 的server.Xml 中的各個(gè)節(jié)點(diǎn)
Server 節(jié)點(diǎn):
Server 代表整個(gè)Catalina servlet 容器。在server.xml 配置文件中必須是頂層元素且唯一,給它配置的屬性代表整個(gè)容器的屬性。
Service 節(jié)點(diǎn):
service 由連接器connector 和共享的處理引擎(Engine)。
Connector 節(jié)點(diǎn):
Connector 分為http connector 和ajp3 connector,http connector 用 Http/1.1 協(xié)議 Connector 接偵聽來自客戶端瀏覽器的http 請求,此時(shí)tomcat 作為獨(dú)立的web 服務(wù)器;ajp3 connector用ajp3 協(xié)議偵聽來自其它Web 服務(wù)器的請求,此時(shí)tomcat 只作為servlet 容器。
Engine 節(jié)點(diǎn):
處理引擎(Engine)代表一個(gè)Service 所屬的請求處理機(jī),它接受所有連接器傳遞過來的客戶端請求,將處理結(jié)果返回給連接器,由連接器將最終響應(yīng)返回給客戶端。Engine 必須配置在Service 組件下。處理引擎下 可以配置多個(gè)虛擬主機(jī)(Virtual Host),每個(gè)虛擬主機(jī)都有一個(gè)域名。當(dāng)處理引擎獲得一個(gè)請求時(shí),它把該請求匹配到某個(gè)虛擬主機(jī)上,把請求交給該虛擬主機(jī)來處理。處理引擎有一個(gè)默認(rèn)虛擬主機(jī),當(dāng)請求無法匹配到任何一個(gè)虛擬主機(jī)上時(shí),交給默認(rèn)虛擬主機(jī)來處理。
Host 節(jié)點(diǎn):
代表一個(gè)虛擬主機(jī),每個(gè)虛擬主機(jī)和某個(gè)網(wǎng)絡(luò)域名(Domain Name)相匹配。每個(gè)虛擬主機(jī)下都可以部署(deploy)一個(gè)或者多個(gè)Web 應(yīng)用程序(Web Application),每個(gè)Web 應(yīng)用程序?qū)?yīng)于一個(gè)Context,有一個(gè)Context path。當(dāng)虛擬主機(jī)獲得一個(gè)請求時(shí),將把該請求匹配到某個(gè)Context上,然后把該請求交給該Context來處理。匹配的方法是“最長匹配”,一個(gè)path=""的Context將成為該虛擬主機(jī)的默認(rèn)Context。所有無法和其它Context的路徑名匹配的請求都將最終和該默認(rèn)Context匹配。在許多情況下,系統(tǒng)管理員希望將多個(gè)網(wǎng)絡(luò)域名綁定到同一個(gè)虛擬主機(jī),這就需要使用“主機(jī)別名”技術(shù)來實(shí)現(xiàn)。
Context節(jié)點(diǎn):
一個(gè)Context對應(yīng)于一個(gè)Web應(yīng)用程序,一個(gè)Web應(yīng)用程序由一個(gè)或者多個(gè)Servlet組成。Context在創(chuàng)建的時(shí)候?qū)⒏鶕?jù)配置文件$CATALINA_HOME/conf/web.xml 和$WebApp/Web-INF/web.xml 載入Servlet類。當(dāng)Context獲得請求時(shí),將在自己的映射表(mapping table)中尋找相匹配的Servlet類。如果找到,則執(zhí)行該類,獲得請求的響應(yīng),并返回。
?
Cluster中的各個(gè)屬性節(jié)點(diǎn)
tomcat 集群各節(jié)點(diǎn)通過建立tcp 鏈接來完成Session的拷貝,拷貝有同步和異步兩種模式。在同步模式下,對客戶端的響應(yīng)必須在Session拷貝到其他節(jié)點(diǎn)完成后進(jìn)行;異步模式無需等待Session拷貝完成就可響應(yīng)。異步模式更高效,但是同步模式可靠性更高。同步異步模式由channelSendOptions參數(shù)控制,默認(rèn)值是8,為異步模式,4是同步模式。在異步模式下,可以通過加上拷貝確認(rèn)(Acknowledge)來提高可靠性,此時(shí)channelSendOptions設(shè)為10。
Manager節(jié)點(diǎn):
用來在節(jié)點(diǎn)間拷貝Session,默認(rèn)使用DeltaManager,DeltaManager采用的一種all-to-all的工作方式,即集群中的節(jié)點(diǎn)會把Session數(shù)據(jù)向所有其他節(jié)點(diǎn)拷貝,而不管其他節(jié)點(diǎn)是否部署 了當(dāng)前應(yīng) 用。當(dāng)集群中 的節(jié)點(diǎn)數(shù) 量很多并且部 署著不同 應(yīng)用時(shí),可以 使用BackupManager,BackManager僅向部署了當(dāng)前應(yīng)用的節(jié)點(diǎn)拷貝Session。但是到目前為止BackupManager并未經(jīng)過大規(guī)模測試,可靠性不及DeltaManager。
Channel節(jié)點(diǎn):
負(fù)責(zé)對tomcat 集群的IO 層進(jìn)行配置。Membership用于發(fā)現(xiàn)集群中的其他節(jié)點(diǎn),這里的address用的是組播地址(Multicast address,),使用同一個(gè)組播地址和端口的多個(gè)節(jié)點(diǎn)同屬一個(gè)子集群,因此通過自定義組播地址和端口就可將一個(gè)大的tomcat 集群分成多個(gè)子集群。Receiver用于各個(gè)節(jié)點(diǎn)接收其他節(jié)點(diǎn)發(fā)送的數(shù)據(jù),在默認(rèn)配置下tomcat 會從4000-4100間依次選取一個(gè)可用的端口進(jìn)行接收,自定義配置時(shí),如果多個(gè)tomcat節(jié)點(diǎn)在一臺物理服務(wù)器上注意要使用不同的端口。Sender用于向其他節(jié)點(diǎn)發(fā)送數(shù)據(jù),具體實(shí)現(xiàn)通過Transport配置,PooledParallelSender是從tcp 連接池中獲取連接,可以實(shí)現(xiàn)并行發(fā)送,即集群中的多個(gè)節(jié)點(diǎn)可以同時(shí)向其他所有節(jié)點(diǎn)發(fā)送數(shù)據(jù)而互不影響。Interceptor有點(diǎn)類似下面將要解釋的Valve,起到一個(gè)閥門的作用,在數(shù)據(jù)到達(dá)目的節(jié)點(diǎn)前進(jìn)行檢測或其他操作,如TcpFailureDetector用于檢測在數(shù)據(jù)的傳輸過程中是否發(fā)生了tcp 錯(cuò)誤。
Valve節(jié)點(diǎn):
用于在節(jié)點(diǎn)向客戶端響應(yīng)前進(jìn)行檢測或進(jìn)行某些操作,ReplicationValve就是用于用于檢測當(dāng)前的響應(yīng)是否涉及Session數(shù)據(jù)的更新,如果是則啟動Session拷貝操作,filter用于過濾
請求,如客戶端對圖片,css,js 的請求就不會涉及Session,因此不需檢測,默認(rèn)狀態(tài)下不進(jìn)行過濾,監(jiān)測所有的響應(yīng)。JvmRouteBinderValve會在前端的Apache mod_jk發(fā)生錯(cuò)誤時(shí)
保證同一客戶端的請求發(fā)送到集群的同一個(gè)節(jié)點(diǎn),tomcat 官方文檔并未解釋如何實(shí)現(xiàn)這一點(diǎn)。?
Deployer節(jié)點(diǎn):
用于集群的farm 功能,監(jiān)控應(yīng)用中文件的更新,以保證集群中所有節(jié)點(diǎn)應(yīng)用的一致性,如某個(gè)用戶上傳文件到集群中某個(gè)節(jié)點(diǎn)的應(yīng)用程序目錄下,Deployer會監(jiān)測到這一操作并把這一文件拷貝到集群中其他節(jié)點(diǎn)相同應(yīng)用的對應(yīng)目錄下以保持所有應(yīng)用的一致。這是一個(gè)相當(dāng)強(qiáng)大的功能,不過很遺憾,tomcat 集群目前并不能做到這一點(diǎn),開發(fā)人員正在努力實(shí)現(xiàn)它,這里的配置只是預(yù)留了一個(gè)接口。
Listener節(jié)點(diǎn):
用于跟蹤集群中節(jié)點(diǎn)發(fā)出和收到的數(shù)據(jù),也有點(diǎn)類似Valve的功能。
一個(gè)樣例,直接貼上來:
<? 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" > <!-- 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" /> <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html --> < Listener className ="org.apache.catalina.mbeans.ServerLifecycleListener" /> < Listener className ="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <!-- 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 JSSE configuration, when using APR, the connector should be using the OpenSSL style configuration described in the APR documentation --> <!-- <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" 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"/> --> <!-- The request dumper valve dumps useful debugging information about the request and response data received and sent by Tomcat. Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.valves.RequestDumperValve"/> --> <!-- 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" /> <!-- Define the default virtual host Note: XML Schema validation will not work with Xerces 2.2. --> < Host name ="localhost" appBase ="webapps" unpackWARs ="true" autoDeploy ="true" xmlValidation ="false" xmlNamespaceAware ="false" > <!-- 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 --> <!-- <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/> --> </ Host > </ Engine > </ Service > </ Server >
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
