Tomcat 6 多机实现Session复制,Tomcat 6 多机实现Session复制实战教程
时间:
2015-11-22 20:01:43
阅读:
469
评论:
收藏:
0
[点我收藏+]
session复制
session复制是指tomcat彼此之间通过组播方式将session发到各个tomcat实例上,如果其中一个访问出错,则另外tomcat仍然具有有效的session内容,从而能正常接管其session。坏处是当tomcat实例很多,或者用户在session中有大量操作时,组播发送的信息量十分惊人。
Tomcat的session复制目前有两种类型,他们的配置稍有区别
分别为:org.apache.catalina.ha.session.DeltaManager和org.apache.catalina.ha.session.BackupManager
DeltaManager复制并发送Session数据到集群下所有的节点,这个实现类被证明非常可靠、运行得非常好。不过有个局限性就是集群的节点类型要相同,而且要部署相同的应用程序。
测试环境
Using CATALINA_BASE: "C:\tomcat_6_1"
Using CATALINA_HOME: "C:\tomcat_6_1"
Using CATALINA_TMPDIR: "C:\tomcat_6_1\temp"
Using JRE_HOME: "E:\Program Files\Java\jdk1.6.0_21"
Using CLASSPATH: "C:\tomcat_6_1\bin\bootstrap.jar"
Server version: Apache Tomcat/6.0.26
JVM Version: 1.6.0_21-b07
JVM Vendor: Sun Microsystems Inc.
一.DeltaManager
1.<distributable/> 配置
修改${CATALINA_HOME}\conf\web.xml文件,加入标签
<distributable/>
直接加在</web-app>之前
2.修改\conf\server.xml
修改:
- <!--
- <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
- -->
为:
- <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" [color=darkred]bind="127.0.0.1"[/color] address="228.0.0.4" port="45564" frequency="500" dropTime="3000" />
- <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="192.168.1.148" port="4005" 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|.*\.jpeg|.*\.jpg|.*\.png|.*\.htm|.*\.html|.*\.css|.*\.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>
二.DeltaManager
1.修改:
- <!--
- <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
- -->
为:
- <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6">
- <Manager className="org.apache.catalina.ha.session.BackupManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true" mapSendOptions="6"/>
- <Channel className="org.apache.catalina.tribes.group.GroupChannel">
- <Membership className="org.apache.catalina.tribes.membership.McastService"
- [color=red] bind="127.0.0.1" [/color]
- address="228.0.0.4"
- port="45564"
- frequency="500"
- dropTime="3000"/>
- <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
- address="auto"
- port="4001"
- selectorTimeout="100"
- maxThreads="6"/>
- <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
- <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" timeout="60000"/>
- </Sender>
- <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 className="org.apache.catalina.ha.tcp.ReplicationValve"
- filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>
- <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
- </Cluster>
2.<distributable/> 配置
修改web应用里面WEB-INF目录下的web.xml文件,加入标签
<distributable/>
直接加在</web-app>之前
三.最后,其他可能操作,开启网卡组播功能:
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
Tomcat 6 多机实现Session复制,Tomcat 6 多机实现Session复制实战教程
原文:http://www.cnblogs.com/chen57long/p/4986427.html