疯狂

STANDING ON THE SHOULDERS OF GIANTS
posts - 481, comments - 486, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

apache 集群tomcat配置参数说明

Posted on 2011-02-15 10:37 疯狂 阅读(2152) 评论(0)  编辑  收藏 所属分类: apache项目架构

Tomcat 集群配置
打开Server.xml,shutdown, ajp, http这三个端口就不多说了,解开下面注释
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
jvmRoute的值要根据apache的配置,不能冲突。
接着是最重要的一点,tomcat默认集群配置(<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>)时,配置的细节实际上被省略了,对于大多数应用而言,使用默认配置已经足够,完整的默认配置应该是这样:

Xml代码 [url=http://tyler-zhou.javaeye.com/blog/507158]


<!--同步异步模式由channelSendOptions参数控制,默认值是8,为异步模式,4是同步模式。在异步模式下,可以通过加上拷贝确认(Acknowledge)来提高可靠性,此时channelSendOptions设为10。-->  
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"  channelSendOptions="6">  
<!---session 拷贝方式 BackupManager 只拷贝部署当前应用的服务器,DeltaManager 拷贝方式all to all-->  
    <Manager className="org.apache.catalina.ha.session.BackupManager"  
        expireSessionsOnShutdown="false"  
        notifyListenersOnReplication="true"  
        mapSendOptions="6"/>  
    <!--   
    <Manager className="org.apache.catalina.ha.session.DeltaManager"  
    expireSessionsOnShutdown="false"  
    notifyListenersOnReplication="true"/>  
    -->  
    <!--Channel负责对tomcat集群的IO层进行配置-->  
    <Channel className="org.apache.catalina.tribes.group.GroupChannel">  
        <!--Membership用于发现集群中的其他节点,这里的address用的是组播地址(Multicast address,了解更多组播地址详情请参见http://zyycaesar.javaeye.com/admin/blogs/296501),使用同一个组播地址和端口的多个节点同属一个子集群,因此通过自定义组播地址和端口就可将一个大的tomcat集群分成多个子集群-->  
        <Membership className="org.apache.catalina.tribes.membership.McastService"  
            address="228.0.0.4"  
            port="45564"  
            frequency="500"  
            dropTime="3000"/>  
        <!--Receiver用于各个节点接收其他节点发送的数据,在默认配置下tomcat会从4000-4100间依次选取一个可用的端口进行接收,自定义配置时,如果多个tomcat节点在一台物理服务器上注意要使用不同的端口-->  
        <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"  
            address="auto"  
            port="5001"  
            selectorTimeout="100"  
            maxThreads="6"/>  
        <!--Sender用于向其他节点发送数据,具体实现通过Transport配置,PooledParallelSender是从tcp连接池中获取连接,可以实现并行发送,即集群中的多个节点可以同时向其他所有节点发送数据而互不影响-->  
        <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">  
            <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>  
        </Sender>  
        <!---Interceptor有点类似下面将要解释的Valve,起到一个阀门的作用,在数据到达目的节点前进行检测或其他操作,如TcpFailureDetector用于检测在数据的传输过程中是否发生了tcp错误。--->  
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>  
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>  
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>  
  
    </Channel>  
    <!--Valve用于在节点向客户端响应前进行检测或进行某些操作,ReplicationValve就是用于用于检测当前的响应是否涉及Session数据的更新,如果是则启动Session拷贝操作,filter用于过滤请求,如客户端对图片,css,js的请求就不会涉及Session,因此不需检测,默认状态下不进行过滤,监测所有的响应.JvmRouteBinderValve会在前端的Apache mod_jk发生错误时保证同一客户端的请求发送到集群的同一个节点-->  
    <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"  
    filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>  
    <!--Deployer用于集群的farm功能,监控应用中文件的更新,以保证集群中所有节点应用的一致性,如某个用户上传文件到集群中某个节点的应用程序目录下,Deployer会监测到这一操作并把这一文件拷贝到集群中其他节点相同应用的对应目录下以保持所有应用的一致。这是一个相当强大的功能,不过很遗憾,tomcat集群目前并不能做到这一点,开发人员正在努力实现它,这里的配置只是预留了一个接口-->  
    <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"  
        tempDir="/tmp/war-temp/"  
        deployDir="/tmp/war-deploy/"  
        watchDir="/tmp/war-listen/"  
        watchEnabled="false"/>  
  
    <!--Listener用于跟踪集群中节点发出和收到的数据,也有点类似Valve的功能。-->  
    <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>  
  
</Cluster>  
最后在Web.xml里面加上<distributable/>,官方文档没有这个,但我觉得还是应该加上,因为按照标准的tomcat启动,当Host对象被创建时,一个Cluster对象(默认配置下是SimpleTcpCluster)也同时被关联到这个Host对象。当某个应用在web.xml中设置了distributable时,Tomcat将为此应用的上下文环境创建一个DeltaManager。SimpleTcpCluster启动membership服务和Replication服务。

---

extra/httpd-mpm.conf 模块  

上边一样的就不贴了,主要是下边的配置,因为我用了mod_security模块,所以要做一些配置,这里不做解释了,写的很详细,我比较喜欢在配置文件里把容易忘记的地方写上文档。毕竟这东西配完了就不再动了,很容易忘记

# WinNT MPM

# ThreadsPerChild: constant number of worker threads in the server process

# MaxRequestsPerChild: maximum  number of requests a server process serves

#注意:ThreadLimit指令应当放在ThreadsPerChild之前,否则ThreadsPerChild指令生效后ThreadLimit会失效,而导致不必要的错误 ThreadLimit必须大于等于ThreadsPerChild

#对于mpm_winnt,ThreadLimit的默认值是1920;对于其他MPM这个值是64

#ThreadLimit 这个指令设置了每个子进程可配置的线程数ThreadsPerChild上限。任何在重启期间对这个指令的改变都将被忽略,但对ThreadsPerChild的修改却会生效。

#ThreadLimit 使用这个指令时要特别当心。如果将ThreadLimit设置成一个高出ThreadsPerChild实际需要很多的值,将会有过多的共享内存被分配。

#如果将ThreadLimit和ThreadsPerChild设置成超过系统的处理能力,Apache可能无法启动,或者系统将变得不稳定。该指令的值应当和ThreadsPerChild大致保持一致

#ThreadsPerChild 每个子进程建立的常驻的执行线程数。默认值是25。子进程在启动时建立这些线程后就不再建立新的线程了。

<IfModule mpm_winnt_module>

    ThreadLimit            2000

    ThreadsPerChild        2000

    MaxRequestsPerChild    2000

</IfModule>


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


网站导航: