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.部署本地文件系統(tǒng)
          3.列出當前的web應用
          4.重新裝載web應用,更新/WEB-INF/classes or /WEB-INF/lib
          5.列出os,jvm參數(shù)
          6.列出可用jndi資源,在<Context>的<ResourceLink>配置
          7.列出安全規(guī)則
          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應用程序在容器上運行,能夠獲得不同的庫的類和資源。這個機制用來實現(xiàn)servlet 2.4規(guī)范。

          系統(tǒng)啟動時,tomcat創(chuàng)建了一組類裝載器,如下的父子結構:
          Bootstrap



          |



          System



          |



          Common



          / \



          Webapp1 Webapp2 ..
          Bootstrap : 裝載jvm需要的基礎類,和系統(tǒng)擴展文件夾下的類$java_home/jre/lib/ext.

          System : 通常裝載CLASSPATH,裝載的類對tomcat以及web應用都可見。而標準的tomcat 6啟動腳本($CATALINA_HOME/bin/catalina.sh or %CATALINA_HOME%\bin\catalina.bat)忽略classpath環(huán)境變量。而是通過以下加載資源:
          $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,在讀到數(shù)據(jù)時通過事件event方式觸發(fā)。

          servlet應實現(xiàn)org.apache.catalina.CometProcessor,以區(qū)別與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也是通過異步事件通知機制實現(xiàn)高效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功能提供將數(shù)據(jù)寫入靜態(tài)文件,而不是存放在內存中并阻塞。
          sendfile支持需要設置request的屬性:org.apache.tomcat.sendfile.support=Boolean.TRUE.



          posted on 2009-12-16 22:34 江永源blog 閱讀(1459) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網站導航:
           

          導航

          常用鏈接

          隨筆檔案(1)

          文章分類(1)

          文章檔案(9)

          最新隨筆

          積分與排名

          最新評論

          主站蜘蛛池模板: 庆安县| 清镇市| 武平县| 高州市| 会同县| 福清市| 内乡县| 平谷区| 安远县| 波密县| 丰宁| 额尔古纳市| 曲沃县| 北宁市| 扬中市| 新邵县| 龙山县| 新干县| 恩施市| 南乐县| 南丰县| 嘉定区| 承德市| 苗栗市| 策勒县| 青川县| 双鸭山市| 镇坪县| 开封县| 夏河县| 利川市| 且末县| 宁远县| 屏东市| 嘉定区| 庆安县| 铜鼓县| 滨海县| 太康县| 贺州市| 青海省|