- <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.0.0.4"
- port="45564"
- frequency="500"
- dropTime="3000"
- bind="127.0.0.1"/>
- <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
- address="auto"
- 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=""/>
- <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>
红色加粗的两个参数 表示 同一个集群;全部节点必须一致!!linux
bind参数指定本机与集群通讯使用的ip地址web
(当一机多个ip是须要指定,多数会集群会由于内外网而早成tomcat session不一样步)apache
Tomcat集群除了能够进行Session数据的拷贝,还可进行Context属性的拷贝,经过修改context.xml的Context配置能够实现,使用
<Context className="org.apache.catalina.ha.context.ReplicatedContext"/>替换默认Context便可,固然也可再加上distributable="true"属性。tomcat
注意点:
- linux 下的组播功能的开启
- 由于tomcat的session同步功能须要用到组播,windows默认状况下是开通组播服务的,可是linux默认状况下并无开通,能够通 过指令打开
- route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
- 或(根据本身的网卡设备名)
- route add -net 224.0.0.0 netmask 240.0.0.0 dev eth1(本次试验所用)
- 若是须要服务器启动时即开通组播需在
- /etc/sysconfig/static-routes(没测试)
- 文件内加入:eth0 net 224.0.0.0 netmask 240.0.0.0
- eth1 net 224.0.0.0 netmask 240.0.0.0
- 本人 是在/etc/rc.d/rc.local中添加:
- route add -net 224.0.0.0 netmask 240.0.0.0 dev eth1
- 具体组播概念请查阅CCNP相关内容。
- 能够经过netstate -g 来查看组播状态,也能够在route -e 命令中看到
另注意:tomcat的server.xml的host节点的name全部的集群节点都要名称一致(这次试验使用localhost)
<Host name="localhost" appBase="/home/web/ddg_ditu"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false"> ide <Context path="" docBase="/home/web/ddg_ditu/ROOT" />
</Host>
|