koill 发表于 2013-12-4 08:59:39

tomcat 集群配置,Session复制共享

本配置在tomcat7上验证通过。通过此方法配置的集群,session信息将会被自动复制到各个节点。

1、配置Server.xml

在Server.xml中,找到被注释<Cluster/>节点,修改为如下:


<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"
bind="127.0.0.1"
address="228.0.0.4"<!--保留ip,用于广播-->
port="45564"
frequency="500"
dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="4001"<!--如果是在同一台机器上的两个tomcat做负载,则此端口则不能重复-->
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=""/>
<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>



2、修改web.xml

在web.xml中,标志为 <distributable/>

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<display-name>session</display-name>
<distributable/>
</web-app>


什么没有 发表于 2013-12-5 06:54:13

请让硪带着祢曾给的那一丝阳光、陪硪度过这寒冬吧!

renran421 发表于 2013-12-6 01:57:25

请不要拥抱我、我的心是凉的,别再说对不起。

15468 发表于 2013-12-6 13:28:37

其实我很想有一个人能够一直守护着我

bestu 发表于 2013-12-7 06:36:46

我不怕生命有挫折,就怕回忆会有皱褶。

andy27367451 发表于 2013-12-7 20:51:57

在我最悲伤难过的时候.你居然一声不响的离开了我.

crespo09 发表于 2013-12-8 07:50:07

执子之手、与子偕老?你演给我看吧.
页: [1]
查看完整版本: tomcat 集群配置,Session复制共享