tomcat server.xml配置文件 解析

  把服务拆分出来了。
     前几天我也进行了拆分。可是当时服务起不来所以我想会不会有什么设置,使得这个服务在主机中只能启一个。然后我又找了一台服务器,也把代码放了进去。结果仿佛是我料想到的样子,服务正常启动了。
所以我想这下可以正式拆分服务了。于是我就先停掉原来的服务,再把相关的代码放在另外一个文件,然后重启第一个服务正常,然后重启随访后台的时候还是不能重启。于是我就回滚了。第一次拆分失败。
我就有打开了日志看,提示端口被占用了。当时我就想我应经把端口从18000改成18140了啊。哪来的3086端口呢。于是我看netstat -lntp | grep 3085.原来在第一个服务中已经被使用了。服务没起来的原因是。我少改了两个端口。
     我就想tomcat中除了我们经常访问的端口,其他端口是做什么的呢。tomcat配置文件到底都关系到那些设置呢?我就在网上查了查,总结了总结。(希望大家不要嫌我分享的low)
 
下面是一个toncat配置  
 
  <?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">                                                    ## 用来监听shutdown属性所对应的那个命令,实现关闭tomcat操作的TCP端口。
## 例如 在命令行键入:telnet ip port 后,然后键入大写的SHUTDOWN。然后回车,tomcat服务立即就会被关掉。
  <!--APR library loader. Documentation at /docs/apr.html -->                                 ##  好像是启动apr模式   对静态资源(HTML,图片等)进行了优化。
  <!--
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />              
--> 
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  <Listener className="org.apache.catalina.core.JasperListener" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>                                                                                          ## 全局命名资源,来定义一些外部访问资源。启作用是为所有引擎应用程序所引用的外部资源的定义 

    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"                                                 ##定义的一个名叫“UserDatabase”的认证资源,将conf/tomcat-users.xml加载至内存中,在需要认证的时候到内存中进行认证
              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>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="CatalinaMedAdmin">                                                                   ##定义Service组件,同来关联Connector和Engine,一个Engine可以对应多个Connector,每个Service中只应一个Engine
 
    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->
   
   
    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080
-->

    <Connector  
          port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"                                                    ##Connector中的port创建服务器端的端口号,此端口监听用户端的请求
          connectionTimeout="20000"                    ##连接超时时间(ms)
          maxKeepAliveRequests="1"                       ## 一次连接可以进行的HTTP请求的最大请求次数。 1表示禁用,-1表示不限制个数,默认100个
          redirectPort="8443"                                  ##指定服务器正在处理http 请求时收到了一个SSL 传输请求后重定向的端口号
          URIEncoding="utf-8"                                 ##tomcat容器的URL编码格式
          maxHttpHeaderSize="8192"                       
          enableLookups="false"                               ##如果为true ,则可以通过调用request.getRemoteHost() 进行DNS 查询来得到远程客户端的实际主机名,若为false 则不进行DNS 查询,而是返回其ip 地址
          acceptCount="2000"                                  ##指定当所有可以使用的处理请求的线程数都被使用时,可以放到处理队列中的请求数,超过这个数的请求将不予处理
          disableUploadTimeout="true"                      ##上传时是否使用超时机制
          compression="on"                                       ##压缩选项
          compressionMinSize="2048"                       ## 对小于该配置大小的文件不进行压缩(单位:B,也就是默认是2K)。注该属性自Tomcat7中有效
          noCompressionUserAgents="gozilla, traviata"  ## 指定不需要压缩的浏览器Agent,使用逗号间隔
          compressableMimeType="text/text,text/html,text/xml,text/javascript,text/css,text/plain"   ## 指定需要压缩的请求文档类型
/>

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8309" protocol="AJP/1.3" redirectPort="8443" />  ## Apache和Tomcat集成时使用

     <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">        
    -->
    <Engine name="CatalinaMedAdmin" defaultHost="localhost">   ##指定缺省的主机名

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->       

      <!-- The request dumper valve dumps useful debugging information about
           the request and response data received and sent by Tomcat.
           Documentation at: /docs/config/valve.html -->
      <!--
      <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
      -->

      <!-- This Realm uses the UserDatabase configured in the global JNDI
           resources under the key "UserDatabase".  Any edits
           that are performed against this UserDatabase are immediately
           available for use by the Realm.  -->
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>

      <!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.
       -->
      <Host name="localhost"                                       ##指定主机名
               appBase="/app/web/services/medadmin"    ##应用程序基本目录,即存放应用程序的目录
               unpackWARs="true"                                     ##tomcat在webapps文件夹中发现war文件时,是否自动将其解压
               autoDeploy="true"                                        ## 设为true,则web.xml发生变化时,tomcat自动重新部署程序。实现这个功能必需允许后台处理
               xmlValidation="false" xmlNamespaceAware="false">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />      ##定义远程访问策略
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"                     ##日志设置
               prefix="localhost_access_log."                              ##指定log文件的前缀
               suffix=".txt"                                                          ##指定后缀
               pattern="common"                                               ##有两个值,common 方式记录远程主机名或ip 地址,用户名,日期,第一行请求的字符串,HTTP 响应代码,发送的字节数。combined 方式比common 方式记录的值更多(具体可看http://goon.iteye.com/blog/1814609 )
               resolveHosts="false"/>                                        ## 如果这个值是true的话,tomcat会将这个服务器IP地址通过DNS转换为主机名,如果是false,就直接写服务器IP地址
        -->

      </Host>
    </Engine>
  </Service>
posted @ 2015-12-13 16:18  崔志朋  阅读(426)  评论(0编辑  收藏  举报