- <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>
|