tomcat相關知識總結(基礎)

tomcat的架構圖

總體的結構框圖如上:http是B/S模型,AJP是S/S模型協議。

  1. 整個tomcat是一個server服務器,裏面能夠包含多個service。
  2. 一個service就是一個完整的服務,包含connet(監聽器,可使多個)、engine(處理引擎 只能是一個),connect監聽鏈接,處理後建立請求體與返回體。交個engine處理
  3. 引擎容器能夠包含多個虛擬主機,只有一個默認主機。
  4. host容器:表明一個站點。其實就是一個主機,有多是虛擬的。包含多個應用容器。
  5. context容器表明一個應用容器。

tomcat配置文件說明

tomcat目錄結構:html

  •   |---bin:存放啓動和關閉tomcat腳本
  •   |---conf:存放不一樣的配置文件(server.xml和web.xml);
  •   |---doc:存放Tomcat文檔;
  •   |---lib/japser/common:存放Tomcat運行須要的庫文件(JARS);
  •   |---logs:存放Tomcat執行時的LOG文件;
  •   |---src:存放Tomcat的源代碼;
  •   |---webapps:Tomcat的主要Web發佈目錄(包括應用程序示例);
  •   |---work:存放jsp編譯後產生的class文件;

Tomcat配置文件: 咱們打開con文件夾能夠看到Tomcat的配置文件:web

  1. server.xml: Tomcat的主配置文件,包含Service, Connector, Engine, Realm, Valve, Hosts主組件的相關配置信息;
  2. web.xml:遵循Servlet規範標準的配置文件,用於配置servlet,併爲全部的Web應用程序提供包括MIME映射等默認配置信息; 
  3. tomcat-user.xml:Realm認證時用到的相關角色、用戶和密碼等信息;Tomcat自帶的manager默認狀況下會用到此文件;在Tomcat中添加/刪除用戶,爲用戶  指定角色等將經過編輯此文件實現;
  4. catalina.policy:Java相關的安全策略配置文件,在系統資源級別上提供訪問控制的能力;
  5. catalina.properties:Tomcat內部package的定義及訪問相關控制,也包括對經過類裝載器裝載的內容的控制;Tomcat在啓動時會事先讀取此文件的相關設置;
  6. logging.properties: Tomcat6經過本身內部實現的JAVA日誌記錄器來記錄操做相關的日誌,此文件即爲日誌記錄器相關的配置信息,能夠用來定義日誌記錄的組  件級別以及日誌文件的存在位置等;
  7. context.xml:全部host的默認配置信息;

tomcat其餘知識點1:配置方式

tomcat的配置方式通常有自動部署與手動部署方式。應用的配置方式主要有兩個一個path與docBase屬性,apache

  1. 自動配置的時候,系統會掃面webapps下的應用目錄,當有一個app1的時候會建立一個app1 的path路徑,當與到ROOT的時候,設置爲主機的默認目錄;系統也會掃描config/Catalina\localhost/***.xml文件,同理也會建立一個***的path,當***的應用不在webapp下面的時候,須要docBase指出。例如配置文件的context增長docBase。
  2. 手動配置的靜態配置,在server.XML中增長注意這種配置方式,server.xml文件不能進行在動加載,在改動的時候,須要從新啓動。 3.另一種方式。其實就是另外兩個方式的另一種實現。就是經過設置CATALANA_BASE的環境變量從新採用一組新的配置文件。idea 就是採用這樣方式先的配置。

tomcat其餘知識點1:自動部署。

自動部署就是自動匹配web應用於uri的路徑信息,找到正確的servlet。設置應用的path的過程與靜態描述以下。tomcat

The automatic deployment process identifies new and/or modified web applications using the following search order:安全

  1. Web applications with a context.xml file located in the Host's configBase.
  2. Web applications with a WAR file located in the Host's appBase that have not already been identified during the scan for context.xml files.
  3. Web applications with a directory located in the Host's appBase that have not already been identified during the scans for context.xml and/or WAR files.

當不在webapps的目錄下的時候須要設置docBase服務器

  1. When using automatic deployment, the docBase defined by an XML Context file should be outside of the appBase directory. If this is not the case, difficulties may be experienced deploying the web application or the application may be deployed twice. The deployIgnore attribute can be used to avoid this situation.架構

  2. Note that if you are defining contexts explicitly in server.xml, you should probably turn off automatic application deployment or specify deployIgnore carefully. Otherwise, the web applications will each be deployed twice, and that may cause problems for the applications.app

context的配置目錄

context有私有文件與默認配置文件,默認配置文件是爲host下面的全部的應用共同應用的,私有的是某個應用專用的。私有配置的文件優先級高,能夠覆蓋公共的文件。less

Individual Context elements may be explicitly defined:webapp

  1. In an individual file at /META-INF/context.xml inside the application files. Optionally (based on the Host's copyXML attribute) this may be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to application's base file name plus a ".xml" extension.
  2. In individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The context path and version will be derived from the base name of the file (the file name less the .xml extension). This file will always take precedence over any context.xml file packaged in the web application's META-INF directory.
  3. Inside a Host element in the main conf/server.xml.

Default Context elements may be defined that apply to multiple web applications. Configuration for an individual web application will override anything configured in one of these defaults. Any nested elements, e.g. elements, that are defined in a default Context will be created once for each Context to which the default applies. They will not be shared between Context elements.

  1. In the $CATALINA_BASE/conf/context.xml file: the Context element information will be loaded by all web applications.
  2. In the $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default file: the Context element information will be loaded by all web applications of that host.

With the exception of server.xml, files that define Context elements may only define a single Context element.

參考: 官網:官網的東西是最爲經典的,純粹的,詳細的
詳解Tomcat 配置文件server.xml :寫的很清晰,是通過思索的文字,而且參考了官網不少內容,值得推薦
tomcat的組成:借鑑了一幅圖。

相關文章
相關標籤/搜索