tomcat7的配置文件server.xml解析
這里對tomcat7的server.xml文件進行解釋一下,方便在分析啟動源碼的時候理解Digester做的事情。
<?xml version='1.0' encoding='utf-8'?> <Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <Listener className="org.apache.catalina.security.SecurityListener" /> <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"> <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="150" minSpareThreads="4"/> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" /> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost"> <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> <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.authenticator.SingleSignOn" /> <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>
Server
tomcat中Server代表一個tomcat實例,所以只會存在一個Server,而在配置文件中也是作為頂級元素出現(xiàn),代碼如下:
<Server port="8005" shutdown="SHUTDOWN"> 。。。 </Server>
- port,監(jiān)聽shutdown命令的端口,-1表示禁用shutdown命令。
- shutdown,關(guān)閉tomcat的指令。
Listener
監(jiān)聽器,用來監(jiān)聽某些事件的發(fā)生。
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
VersionLoggerListener,啟動時對tomcat,java,操作系統(tǒng)信息打印日志。
<Listener className="org.apache.catalina.security.SecurityListener" />
SecurityListener,啟動tomcat時,做一些安全檢查。
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
AprLifecycleListener,用來監(jiān)聽Apache服務(wù)器相關(guān)的。
<Listener className="org.apache.catalina.core.JasperListener" />
JasperListener,Jasper 2 JSP 引擎,主要負責對更新之后的jsp進行重新編譯。
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
JreMemoryLeakPreventionListener,防止內(nèi)存溢出的監(jiān)聽器。
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
GlobalResourcesLifecycleListener,初始化定義在元素GlobalNamingResources下的全局JNDI資源
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
ThreadLocalLeakPreventionListener,防止ThreadLocal溢出監(jiān)聽器。
GlobalNamingResources
GlobalNamingResources定義Server的全局JNDI資源??梢詾樗械囊鎽?yīng)用程序引用。
<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>
配置文件中定義了一個JNDI,名為UserDatabase,通過conf/tomcat-users.xml
的內(nèi)容,來得到一個用于授權(quán)用戶的數(shù)據(jù)庫,是一個內(nèi)存數(shù)據(jù)庫。
Service
<Service name="Catalina"> 。。。 </Service>
Server下面可以有多個Service,Service下面有多個Connector和一個Engine。這里默認的Service名字為Catalina,下面有兩個Connector:Http和AJP。
- name,Service顯示的名稱,名字必須唯一。
Connector
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
上面是用來處理http請求的Connector。
- port,端口號8080。
- protocol,協(xié)議,http協(xié)議
- connectionTimeout,響應(yīng)的最大等待時間,20秒
- redirectPort,ssl請求會重定向到8443端口
<Connector executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
上面是使用線程池,處理http請求。
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" />
上面處理ssl請求,端口是8443。
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
上面處理AJP請求,可以將tomcat和apache的http服務(wù)器一起運行。
Engine
Engine是容器,一個Service中只包含一個Engine:
<Engine name="Catalina" defaultHost="localhost"> ... </Engine>
Engine下面可以包含一個多或者多個Host。Engine從http請求的頭信息中的主機名或者ip映射到真確的主機上。
- name,Engine的名字,需要唯一。
- defaultHost,默認主機名
Cluster
集群相關(guān)的配置。tomcat支持服務(wù)器集群,可以復(fù)制整個集群的回話和上下文屬性,也可以部署一個war包到所有的集群上。
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
Realm
<Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm>
Realm是一個包含user、password、role的數(shù)據(jù)庫,Realm可以定義在任何容器中。這里通過外部資源UserDatabase進行認證。
Host
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>
Host虛擬主機,定義在Engine下面,一個Engine下面可以有多個Host,在一個Host下面可以有多個Context。
- name,虛擬主機的網(wǎng)絡(luò)名稱,必須有一個host的名字和Engine的defaulHost一樣。
- appBase,虛擬主機應(yīng)用的根目錄,默認是webapps。
- unpackWARs,在webapps目錄下的war文件是否應(yīng)該解壓。
- autoDeploy,值為true時,tomcat會定時檢查appBase等目錄,對新的web應(yīng)用和Context描述文件進行部署。
Value
<Valve className="org.apache.catalina.authenticator.SingleSignOn" /> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" />
Value在這里是閥門的意思,可以攔截http請求,可以定義在任何容器中。
SingleSignOn 是單點登錄,AccessLogValve是訪問日志的記錄。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
搭建Tomcat 8源碼開發(fā)環(huán)境的步驟詳解
相信大家都知道開源軟件tomcat目前幾乎已經(jīng)是Java web開發(fā)的必備軟件了,目前有很多關(guān)于tomcat的書籍,已經(jīng)通過配置對tomcat進行一些跟應(yīng)用業(yè)務(wù)功能的調(diào)優(yōu),但感覺如果僅僅只是了解一些配置,可能稍微少了點什么,下面通過本文深入到源代碼中進行學些和了解。2016-10-10解決Tomcat 中catalina.out持續(xù)累加問題
這篇文章主要介紹了解決Tomcat 中catalina.out持續(xù)累加問題 ,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2018-03-03Apache結(jié)合Tomcat實現(xiàn)動靜分離的方法
這篇文章主要介紹了Apache結(jié)合Tomcat實現(xiàn)動靜分離的方法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-01-01TOMCAT啟動失敗using?catalina_opts為空的解決方法
這篇文章主要給大家分享了TOMCAT啟動失敗using?catalina_opts為空的解決方法,文中有詳細的解決流程,具有一定的參考價值,需要的朋友可以參考下2023-10-10使用IDEA創(chuàng)建Web項目并發(fā)布到tomcat的操作方法
這篇文章主要介紹了使用IDEA創(chuàng)建Web項目并發(fā)布到tomcat的操作方法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-05-05