Tomcat集羣Cluster配置

 

  
  
  
  
  1. <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" 
  2.  channelSendOptions="8"> 
  3.  
  4.  <Manager className="org.apache.catalina.ha.session.DeltaManager" 
  5.   expireSessionsOnShutdown="false" 
  6.   notifyListenersOnReplication="true"/> 
  7.  
  8. <Channel className="org.apache.catalina.tribes.group.GroupChannel"> 
  9. <Membership className="org.apache.catalina.tribes.membership.McastService" 
  10.                         address="228.0.0.4" 
  11.                         port="45564" 
  12.                         frequency="500" 
  13.                         dropTime="3000" 
  14.                         bind="127.0.0.1"/>      
  15. <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" 
  16.                       address="auto" 
  17.                       port="4000" 
  18.                       autoBind="100" 
  19.                       selectorTimeout="5000" 
  20.                       maxThreads="6"/> 
  21.  
  22. <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter"> 
  23. <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/> 
  24.  </Sender> 
  25.  <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/> 
  26. <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/> 
  27. </Channel> 
  28.  
  29. <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/> 
  30. <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/> 
  31.  
  32. <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer" 
  33.                     tempDir="/tmp/war-temp/" 
  34.                     deployDir="/tmp/war-deploy/" 
  35.                     watchDir="/tmp/war-listen/" 
  36.                     watchEnabled="false"/> 
  37.  
  38. <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/> 
  39. <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/> 
  40. </Cluster>  

 紅色加粗的兩個參數 表示 同一個集羣;全部節點必須一致!!linux

bind參數指定本機與集羣通訊使用的ip地址web

(當一機多個ip是須要指定,多數會集羣會由於內外網而早成tomcat session不一樣步)apache

 Tomcat集羣除了能夠進行Session數據的拷貝,還可進行Context屬性的拷貝,經過修改context.xmlContext配置能夠實現,使用 windows

<Context className="org.apache.catalina.ha.context.ReplicatedContext"/>替換默認Context便可,固然也可再加上distributable="true"屬性。tomcat

注意點: 服務器


  
  
  
  
  1. linux 下的組播功能的開啓 
  2.  
  3. 由於tomcat的session同步功能須要用到組播,windows默認狀況下是開通組播服務的,可是linux默認狀況下並無開通,能夠通 過指令打開 
  4.  
  5. route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0 
  6.  
  7. 或(根據本身的網卡設備名) 
  8.  
  9. route add -net 224.0.0.0 netmask 240.0.0.0 dev eth1(本次試驗所用) 
  10.  
  11.   
  12.  
  13. 若是須要服務器啓動時即開通組播需在 
  14.  
  15. /etc/sysconfig/static-routes(沒測試) 
  16.  
  17. 文件內加入:eth0 net 224.0.0.0 netmask 240.0.0.0 
  18.  
  19.             eth1 net 224.0.0.0 netmask 240.0.0.0 
  20.  
  21. 本人 是在/etc/rc.d/rc.local中添加: 
  22.  
  23. route add -net 224.0.0.0 netmask 240.0.0.0 dev eth1 
  24.  
  25.   
  26.  
  27. 具體組播概念請查閱CCNP相關內容。 
  28.  
  29. 能夠經過netstate -g 來查看組播狀態,也能夠在route -e 命令中看到 

 

另注意:tomcatserver.xmlhost節點的name全部的集羣節點都要名稱一致(這次試驗使用localhost session

<Host name="localhost" appBase="/home/web/ddg_ditu"  app

       unpackWARs="true" autoDeploy="true"  tcp

       xmlValidation="false" xmlNamespaceAware="false">          ide

       <Context path="" docBase="/home/web/ddg_ditu/ROOT" /> 

     </Host>

 

 

本人博客已遷至:http://www.zhougou.net/archives/56

相關文章
相關標籤/搜索