当前位置:web 服务器 > Tomcat >>

Tomcat集群Cluster配置

<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> 
 红色加粗的两个参数 表示 同一个集群;所有节点必须一致!!
bind参数指定本机与集群通信使用的ip地址
(当一机多个ip是需要指定,多数会集群会因为内外网而早成tomcat session不同步)
 Tomcat集群除了可以进行Session数据的拷贝,还可进行Context属性的拷贝,通过修改context.xml的Context配置可以实现,使用
<Context className="org.apache.catalina.ha.context.ReplicatedContext"/>替换默认Context即可,当然也可再加上distributable="true"属性。
注意点:

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">         
       <Context path="" docBase="/home/web/ddg_ditu/ROOT" />
     </Host>

作者“林清杨--技术博客”

补充:软件开发 , Java ,
Apache
IIS
Nginx
Tomcat
如果你遇到web 服务器难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,