tomcat cluster配置实战注意事项

关于tomcat cluster的实现原理,详见:https://tomcat.apache.org/tomcat-7.0-doc/cluster-howto.html#How_it_Works。
在这里只是对在实际实际配置中遇到的问题做一个总结。

配置说明


通常,tomcat cluster配置都是在$CATALINA_HOME/conf/server.xml文件中,配置在节点下。
这里以tomcat 7.0.59配置示例说明,配置片段如下所示:

<Engine name="Catalina" defaultHost="localhost">
      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->
      ...
<Engine>

配置实例


<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=".*\.gif|.*\.js|.*\.jpeg|.*\.jpg|.*\.png|.*\.htm|.*\.html|.*\.css|.*\.txt"/>
    <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>

注意事项


  1. tomcat cluser在jdk1.5及以上版本才被支持。

  2. 系统必须允许广播,Tomcat通过广播机制传递session复制信息。
    启动报错:
    plain 严重: Unable to start cluster. org.apache.catalina.tribes.ChannelException: java.net.SocketException: 没有那个设备; No faulty members identified.
    添加广播路由:
    plain [root@centosx64_tomcat1 ~]# route add -host 228.0.0.4 dev eth0(eth0为实际网卡名称) [root@centosx64_tomcat1 ~]# route -en Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 228.0.0.4 0.0.0.0 255.255.255.255 UH 0 0 0 eth2 192.168.70.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2

  3. 检查Tomcat集群内的主机防火墙是否开启
    解决报错:java.net.NoRouteToHostException: No route to host (Host unreachable)
    如果防火墙打开,需要允许4000端口访问(tomcat cluster使用4000进行集群内通信):
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 4000 -j ACCEPT

  4. 确保java.net.InetAddress.getLocalHost().getHostAddress()返回值不为127.0.0.1
    tomcat cluser使用java.net.InetAddress.getLocalHost().getHostAddress()作为广播地址,所以要确保在主机上该方法返回值不能为127.0.0.1,否则无法正常组件集群。
    具体来说,检查/etc/hosts文件内容,确保hostname不会被解析到127.0.0.1

  5. tomcat cluster使用广播消息的方式进行集群通信,所以一定要确保同一个集群内的主机都使用相同的广播端口号,默认值为:45564。

  6. 为了能正常使用tomcat cluser的session复制功能,需要在web应用web.xml中添加配置节点:<distributable/>

  7. Tomcat官方推荐只在小规模集群时使用。原因在于:tomcat cluster使用广播方式传递session消息,特别是使用org.apache.catalina.ha.session.DeltaManager时,会对集群内所有节点进行广播,这就限制了集群规模不能很大。否则,广播流量的负担会降低集群整体性能。另外,由于session数据都是存放在内存中,且每个节点都会保存集群中所有session对象的完整副本,随着集群规模的增大,会影响节点的性能。具体能够使用多大的集群规模,应该根据实际部署环境进行性能测试,当集群性能不会随着节点的增加而增大时,说明已经是可以部署的最大集群规模。但通常而言,对于tomcat cluster的集群规模,应该限制在个位数。

【参考】
http://5880861.blog.51cto.com/5870861/1671622 Tomcat集群问题记录
http://blog.csdn.net/q_l_s/article/details/52015296 tomcat - 报错 No such device; No faulty members identified.
https://wiki.apache.org/tomcat/FAQ/Clustering The cluster doesn't work under Linux with two nodes on two boxes.

转载于:https://www.cnblogs.com/nuccch/p/7448162.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值