如何使用McastService绑定进行Tomcat集群?

时间:2014-02-15 21:08:14

标签: tomcat tomcat7 cluster-computing multicast

我正在尝试在我的VM附加到的几个网络中的一个上集群Tomcat实例。使用默认配置,我在我感兴趣的网络上看不到任何多播流量。

所以,我正在尝试使用bind中的McastService属性告诉Tomcat要使用哪个网络接口。

当我使用IPv4或IPv6 bind网络接口地址时,我看到3个数据包通过正确的多播地址/端口,但Tomcat会抛出异常:

Feb 15, 2014 8:22:45 PM org.apache.catalina.ha.tcp.SimpleTcpCluster startInternal
SEVERE: Unable to start cluster.
org.apache.catalina.tribes.ChannelException: java.io.IOException: Invalid argument; No faulty members identified.
        at org.apache.catalina.tribes.group.ChannelCoordinator.internalStart(ChannelCoordinator.java:178)
        at org.apache.catalina.tribes.group.ChannelCoordinator.start(ChannelCoordinator.java:99)
        at org.apache.catalina.tribes.group.ChannelInterceptorBase.start(ChannelInterceptorBase.java:162)
        at org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor.start(MessageDispatchInterceptor.java:157)
        at org.apache.catalina.tribes.group.ChannelInterceptorBase.start(ChannelInterceptorBase.java:162)
        at org.apache.catalina.tribes.group.ChannelInterceptorBase.start(ChannelInterceptorBase.java:162)
        at org.apache.catalina.tribes.group.GroupChannel.start(GroupChannel.java:419)
        at org.apache.catalina.ha.tcp.SimpleTcpCluster.startInternal(SimpleTcpCluster.java:685)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1106)
        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:691)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:456)
Caused by: java.io.IOException: Invalid argument
        at java.net.PlainDatagramSocketImpl.send(Native Method)
        at java.net.DatagramSocket.send(DatagramSocket.java:676)
        at org.apache.catalina.tribes.membership.McastServiceImpl.send(McastServiceImpl.java:503)
        at org.apache.catalina.tribes.membership.McastServiceImpl.send(McastServiceImpl.java:480)
        at org.apache.catalina.tribes.membership.McastServiceImpl.start(McastServiceImpl.java:269)
        at org.apache.catalina.tribes.membership.McastService.start(McastService.java:386)
        at org.apache.catalina.tribes.group.ChannelCoordinator.internalStart(ChannelCoordinator.java:167)
        ... 22 more

我知道多播正在运行并启用,因为我能够看到包含tcpdump并使用mcsender发送数据包的数据包。我试过禁用IPv6,但没有帮助。

如何将Tomcat连接到正确的网络接口以进行群集。我需要将它连接到:

eth2      Link encap:Ethernet  HWaddr bc:76:4e:05:5b:22
          inet addr:192.168.3.4  Bcast:192.168.3.255  Mask:255.255.255.0
          inet6 addr: fe80::be76:4eff:fe05:5b22/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:70 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:4160 (4.1 KB)  TX bytes:648 (648.0 B)

运行Tomcat 7.0.42。我一直尝试使用的配置(主要是默认值+ bind)是:

<Engine name="Catalina" defaultHost="localhost" jvmRoute="main4">

    <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"
                    bind="192.168.3.4"
                    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"/>

      <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
      <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
    </Cluster>

3 个答案:

答案 0 :(得分:1)

删除以下行:

bind="192.168.3.4"

答案 1 :(得分:0)

我发现这与多宿主计算机上的一个错误有关,它同时启用了IPv4和IPv6。

在我的情况下,我能够通过禁用IPv6来解决这个问题,对我来说,这是通过使用一些sysctl命令,http://wiki.centos.org/FAQ/CentOS6#head-d47139912868bcb9d754441ecb6a8a10d41781df

答案 2 :(得分:0)

另一个选择可能是要求java运行时使用IPv4这个启动参数: -Djava.net.preferIPv4Stack=true