本次實驗使用的tomcat版本爲apache-tomcat-7.0.73。web
1、拷貝兩份tomcat文件,注意端口號的修改。apache
2、修改每一個tomcat下server.xml配置文件的<Engine></Engine>中加入以下配置(此配置也是tomcat配置集羣的默認配置):tomcat
<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"/> <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="/temp/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>
配置注意事項:網絡
3、在項目的web.xml文件中配置<distributable/>,而後就能夠運行測試了。session
4、集羣配置屬性詳解異步
2:Channel.SEND_OPTIONS_USE_ACK(確認發送)
4:Channel.SEND_OPTIONS_SYNCHRONIZED_ACK(同步發送)
8:Channel.SEND_OPTIONS_ASYNCHRONOUS(異步發送)
在異步模式下,能夠經過加上確認發送(Acknowledge)來提升可靠性,此時可將channelSendOptions設爲10。 tcp
BackupManager:集羣下產生的全部Session都將放到一個備份節點,集羣下的全部節點均可以訪問此備份節點,每一個節點部署的應用能夠不同。
DeltaManager:集羣下某個節點建立、改動的Session,都將複製到其餘節點,每一個節點部署的應用要同樣。這個管理器是tomcat默認的集羣配置,適用於通常的小型集羣。工具