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 配置文件路径:
  1. $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml
  2. $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 called ROOT.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"



docBase="/usr/local/kinetic/tomcat6/server/webapps/manager">



</Context>



三种使用manager的方式:
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" /
2.jdbc范围
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创建了一组类装载器,如下的父子结构:
Bootstrap



|



System



|



Common



/ \



Webapp1 Webapp2 ..
Bootstrap : 装载jvm需要的基础类,和系统扩展文件夹下的类$java_home/jre/lib/ext.

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
Webappx:装载web应用类。包括:/web-inf/classes,/web-inf/lib。对本web应用可见,不同应用间不可见。

对于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).
同样的,comet filter也是通过异步事件通知机制实现高效IO

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.



posted on 2009-12-16 22:34 江永源blog 阅读(1455) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

常用链接

随笔档案(1)

文章分类(1)

文章档案(9)

最新随笔

积分与排名

最新评论