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>  

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

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

(當一機多個ip是需要指定,多數會集羣會因爲內外網而早成tomcat session不同步)

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

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

注意點:


  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

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

       unpackWARs="true" autoDeploy="true" 

       xmlValidation="false" xmlNamespaceAware="false">          

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

     </Host>

 

 

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章