代码 如下:
- <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
- channelSendOptions="8">
- <Manager className="org.apache.catalina.ha.session.DeltaManager"
- expireSessionsOnShutdown="false"
- notifyListenersOnReplication="true"/>
- <Channel className="org.apache.catalina.tribes.group.GroupChannel">
- <Membership className="org.apache.catalina.tribes.membership.McastService"
- address="228.50.10.1" bind="172.16.10.3" port="45564"
- frequency="500" dropTime="3000"/>
- <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
- address="172.16.10.3" port="4000" autoBind="100"
- selectorTimeout="5000" maxThreads="6"/>
- <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
- <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
- </Sender>
- <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
- <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
- </Channel>
- <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
- filter=".*\.gif;.*\.js;.*\.jpg;.*\.htm;.*\.html;.*\.txt;"/>
- <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
- <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
- tempDir="/tmp/war-temp/" deployDir="/tmp/war-deploy/"
- watchDir="/tmp/war-listen/" watchEnabled="false"/>
- <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
- <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
- </Cluster>
注意:
- 应用程序的中添加web.xml文件,即
- 在/webapps/sess目录中需要如下目录和文件
- index.jsp WEB-INF/ classes lib web.xml
- 且在web.xml中添加 <distributable/>
在其server.xml文件的<Engine> </Engine>之间添加如下代码实现Tomcat集群功能
- TomcatB配置

- 应用程序的中添加web.xml文件,即
- 在/webapps/sess目录中需要如下目录和文件
- index.jsp WEB-INF/ classes lib web.xml
- 且在web.xml中添加 <distributable/>
- 重启Apache Tomcat服务验证,用户的session_id是否永久保持
![]()
- 结果可以看出,用户的Session-id 在tomcatA和tomcatB上始终没有发生改变
- 监控worker的工作状态信息:
![]()
由于时间匆促,如有错误,欢迎指正,交流,谢谢!
- 说明:其中一台tomcat服务器down机
- 使用tomcat的status监控服务主机,status页面反应较慢,
- 不能将后端服务器的监控状况及时的反应到前端监控主机上,这时一个缺点,建议使用其他方式


