tomcat 6
本文目錄:
tomcat web application deployment
use jmx proxy servlet
tomcat 6 class loader
高效IO
tomcat web application deployment
concept of Context:一個web應用稱為一個context
tomcat通過context描述文件進行配置.context.xml,(不推薦在server.xml配置)
context 配置文件路徑:
deployment on tomcat startup
tomcat應用的啟動順序
1.有context描述文件的應用
2.已經在appbase目錄下解壓過的應用。如果.war文件有更新,則舊文件會移除,重新解壓。
3..war文件會部署,解壓。
deploying on a running tomcat server
1.war文件拷貝到host appbase目錄
2.解壓后的應用拷貝到host appbase目錄
3.新的war文件覆蓋舊的war文件
4.修改/WEB-INF/web.xml文件
5.修改webapp里下面的context描述文件
6.context描述文件拷貝到
deploying useing tomcat manager(http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html)
使用tomcat manager,需要部署/manager應用
manager提供以下功能:
1.部署上傳的war文件
2.部署本地文件系統
3.列出當前的web應用
4.重新裝載web應用,更新
5.列出os,jvm參數
6.列出可用jndi資源,在<Context>的<ResourceLink>配置
7.列出安全規則
8.啟動應用
9.關閉應用
10.卸載應用,刪除document文件
添加context應用在manager.xml中(
2.通過uri提供命令,返回簡單txt文件
3.使用ant文件
配置tomcat manager的權限
1.內存范圍:
2.jdbc范圍
3.jndi范圍
使用RemoteAddrValve對ip進行限制
<Context path="/manager" privileged="true"
命令行使用以下形式:
http://{host}:{port}/manager/{command}?{parameters}
use jmx proxy servlet
JMX proxy servlet是一個修改tomcat內部設置的輕量級代理。通過jmx proxy servlet可以查詢、修改tomcat的一些信息
顯示全部信息:
http://localhost:8080/manager/jmxproxy
use query command:
http://localhost:8080/manager/jmxproxy/?qry=j2eeType=Servlet
但在測試中,此功能無法查詢出來,報錯:Error - javax.management.MalformedObjectNameException: Domain part must be specified
use set command:
http://localhost:8080/manager/jmxproxy/?set=Catalina:j2eeType=WebModule,name=//localhost/skyBook,J2EEApplication=none,J2EEServer=none&att=override&val=true
set=Name
att=attribute name
val= value
tomcat 6 class loader
tomcat6使用一個不同的類裝載器,讓容器的不同部分, 和web應用程序在容器上運行,能夠獲得不同的庫的類和資源。這個機制用來實現servlet 2.4規范。
系統啟動時,tomcat創建了一組類裝載器,如下的父子結構:
System : 通常裝載CLASSPATH,裝載的類對tomcat以及web應用都可見。而標準的tomcat 6啟動腳本(
$CATALINA_HOME/bin/bootstrap.jar運行main方法,初始化tomcat 6 server,與class loader.
$CATALINA_HOME/bin/tomcat-juli.jar重寫包名的common logging api 和java.util.logging.LogManager.
Common:此裝載器裝載
對于jdk1.5 xml 解析需要替換自己的解析器,使用此配置替換:
高效IO
當使用APR或NIO connecter時,tomcat支持非阻塞IO方式運行servlet.
Comet用來支持異步IO,在讀到數據時通過事件event方式觸發。
事件:
EventType.BEGIN:
EventType.READ:
EventType.ERROR:
EventType.END:
一些子類型:
NIO方式可修改timeout設置
CometEvent event ... event.setTimeout(30 * 1000);
event.getHttpServletRequest().setAttribute("org.apache.tomcat.comet.timeout", new Integer(30 * 1000));
APR connecter默認timeout時間:
異步寫:
tomcat sendfile功能提供將數據寫入靜態文件,而不是存放在內存中并阻塞。
sendfile支持需要設置request的屬性:
tomcat web application deployment
use jmx proxy servlet
tomcat 6 class loader
高效IO
tomcat web application deployment
concept of Context:一個web應用稱為一個context
tomcat通過context描述文件進行配置.context.xml,(不推薦在server.xml配置)
context 配置文件路徑:
- $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml
- $CATALINA_BASE/webapps/[webappname]/META-INF/context.xml
- In the
$CATALINA_BASE/conf/context.xml
file: the Context element information will be loaded by all webapps. - In the
$CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default
file: the Context element information will be loaded by all webapps of that host. - In individual files (with a ".xml" extension) in the
$CATALINA_BASE/conf/[enginename]/[hostname]/
directory. The name of the file (less the .xml extension) will be used as the context path. Multi-level context paths may be defined using #, e.g.foo#bar.xml
for a context path of/foo/bar
. The default web application may be defined by using a file calledROOT.xml
. - Only if a context file does not exist for the application in the
$CATALINA_BASE/conf/[enginename]/[hostname]/
, in an individual file at/META-INF/context.xml
inside the application files. If the web application is packaged as a WAR then/META-INF/context.xml
will be copied to$CATALINA_BASE/conf/[enginename]/[hostname]/
and renamed to match the application's context path. Once this file exists, it will not be replaced if a new WAR with a newer/META-INF/context.xml
is placed in the host's appBase. - Inside a Host
element in the main
conf/server.xml
.
deployment on tomcat startup
tomcat應用的啟動順序
1.有context描述文件的應用
2.已經在appbase目錄下解壓過的應用。如果.war文件有更新,則舊文件會移除,重新解壓。
3..war文件會部署,解壓。
deploying on a running tomcat server
1.war文件拷貝到host appbase目錄
2.解壓后的應用拷貝到host appbase目錄
3.新的war文件覆蓋舊的war文件
4.修改/WEB-INF/web.xml文件
5.修改webapp里下面的context描述文件
6.context描述文件拷貝到
$CATALINA_BASE/conf/[enginename]/[hostname]/
deploying useing tomcat manager(http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html)
使用tomcat manager,需要部署/manager應用
manager提供以下功能:
1.部署上傳的war文件
2.部署本地文件系統
3.列出當前的web應用
4.重新裝載web應用,更新
/WEB-INF/classes
or /WEB-INF/lib
5.列出os,jvm參數
6.列出可用jndi資源,在<Context>的<ResourceLink>配置
7.列出安全規則
8.啟動應用
9.關閉應用
10.卸載應用,刪除document文件
添加context應用在manager.xml中(
$CATALINA_BASE/conf/[enginename]/[hostname]
),以下是例子:<Context path="/manager" debug="0" privileged="true"三種使用manager的方式:
docBase="/usr/local/kinetic/tomcat6/server/webapps/manager">
</Context>
1.通過頁面接口:http://localhost/manager/html/
2.通過uri提供命令,返回簡單txt文件
3.使用ant文件
配置tomcat manager的權限
1.內存范圍:
修改$CATALINA_BASE/conf/tomcat-users.xml,以下是一個例子:
![]() |
![]() |
![]() |
![]() |
<user name="craigmcc" password="secret" roles="standard,manager" / |
3.jndi范圍
使用RemoteAddrValve對ip進行限制
<Context path="/manager" privileged="true"
docBase="/usr/local/kinetic/tomcat6/server/webapps/manager">命令行模式
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.0\.0\.1"/>
</Context>
命令行使用以下形式:
http://{host}:{port}/manager/{command}?{parameters}
use jmx proxy servlet
JMX proxy servlet是一個修改tomcat內部設置的輕量級代理。通過jmx proxy servlet可以查詢、修改tomcat的一些信息
顯示全部信息:
http://localhost:8080/manager/jmxproxy
use query command:
http://localhost:8080/manager/jmxproxy/?qry=j2eeType=Servlet
但在測試中,此功能無法查詢出來,報錯:Error - javax.management.MalformedObjectNameException: Domain part must be specified
use set command:
http://localhost:8080/manager/jmxproxy/?set=Catalina:j2eeType=WebModule,name=//localhost/skyBook,J2EEApplication=none,J2EEServer=none&att=override&val=true
set=Name
att=attribute name
val= value
tomcat 6 class loader
tomcat6使用一個不同的類裝載器,讓容器的不同部分, 和web應用程序在容器上運行,能夠獲得不同的庫的類和資源。這個機制用來實現servlet 2.4規范。
系統啟動時,tomcat創建了一組類裝載器,如下的父子結構:
BootstrapBootstrap : 裝載jvm需要的基礎類,和系統擴展文件夾下的類$java_home/jre/lib/ext.
|
System
|
Common
/ \
Webapp1 Webapp2 ..
System : 通常裝載CLASSPATH,裝載的類對tomcat以及web應用都可見。而標準的tomcat 6啟動腳本(
$CATALINA_HOME/bin/catalina.sh
or %CATALINA_HOME%\bin\catalina.bat
)忽略classpath環境變量。而是通過以下加載資源:$CATALINA_HOME/bin/bootstrap.jar運行main方法,初始化tomcat 6 server,與class loader.
$CATALINA_HOME/bin/tomcat-juli.jar重寫包名的common logging api 和java.util.logging.LogManager.
Common:此裝載器裝載
$CATALINA_HOME/lib下
的類,對tomcat以及web 應用可見。- annotations-api.jar - JEE annotations classes.
- catalina.jar - Implementation of the Catalina servlet container portion of Tomcat 6.
- catalina-ant.jar - Tomcat Catalina Ant tasks.
- catalina-ha.jar - High availability package.
- catalina-tribes.jar - Group communication package.
- el-api.jar - EL 2.1 API.
- jasper.jar - Jasper 2 Compiler and Runtime.
- jasper-el.jar - Jasper 2 EL implementation.
- jasper-jdt.jar - Eclipse JDT 3.2 Java compiler.
- jsp-api.jar - JSP 2.1 API.
- servlet-api.jar - Servlet 2.5 API.
- tomcat-coyote.jar - Tomcat connectors and utility classes.
- tomcat-dbcp.jar - package renamed database connection pool based on Commons DBCP.
- tomcat-i18n-**.jar
對于jdk1.5 xml 解析需要替換自己的解析器,使用此配置替換:
-Djava.endorsed.dirs=$JAVA_ENDORSED_DIRS
高效IO
當使用APR或NIO connecter時,tomcat支持非阻塞IO方式運行servlet.
Comet用來支持異步IO,在讀到數據時通過事件event方式觸發。
servlet應實現org.apache.catalina.CometProcessor
,以區別與Servlet.service方法.事件:
EventType.BEGIN:
EventType.READ:
EventType.ERROR:
EventType.END:
一些子類型:
- EventSubType.TIMEOUT: The connection timed out (sub type of ERROR); note that this ERROR type is not fatal, and the connection will not be closed unless the servlet uses the close method of the event.
- EventSubType.CLIENT_DISCONNECT: The client connection was closed (sub type of ERROR). method of the event.
- EventSubType.IOEXCEPTION: An IO exception occurred, such as invalid content, for example, an invalid chunk block (sub type of ERROR).
- EventSubType.WEBAPP_RELOAD: The web application is being reloaded (sub type of END).
- EventSubType.SESSION_END: The servlet ended the session (sub type of END).
NIO方式可修改timeout設置
CometEvent event ... event.setTimeout(30 * 1000);
event.getHttpServletRequest().setAttribute("org.apache.tomcat.comet.timeout", new Integer(30 * 1000));
APR connecter默認timeout時間:
soTimeout*50
異步寫:
tomcat sendfile功能提供將數據寫入靜態文件,而不是存放在內存中并阻塞。
sendfile支持需要設置request的屬性:
org.apache.tomcat.sendfile.support=
Boolean.TRUE
.