J2cache, jgroups部署到阿里云、微软云、浪潮云等云服务器不能加入同一个JChannel实现UDP组播,如何配置?

gtd 发布于 2015/09/26 10:17
阅读 1K+
收藏 0

将J2Cache或jgroups的测试程序部署到阿里云(windows系统两台,内网IP能ping通)、浪潮云(三台linux,内网IP连着),微软云虚拟机(三台linux,内网IP连着),发现都无法连通,具体表现在不同机器跑的同一程序不能加入到同一个 JChannel 中,viewAccepted不触发。  同样的程序在公司局域网、一所学校的内网服务器都没问题。

测试代码很简单

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.ReceiverAdapter;
import org.jgroups.View;

public class SimpleChat extends ReceiverAdapter {
  JChannel channel;

  public void viewAccepted(View new_view) {
    System.out.println("** view: " + new_view);
  }

  public void receive(Message msg) {
    String line = "[" + msg.getSrc() + "]: " + msg.getObject();
    System.out.println(line);
  }

  /** Method called from other app, injecting channel */
  public void start(JChannel ch) throws Exception {
    channel = ch;
    channel.setReceiver(this);
    channel.connect("ChatCluster");
    eventLoop();
    channel.close();
  }

  private void start(String props, String name) throws Exception {
    channel = new JChannel(props);
    if (name != null) {
      channel.name(name);
    }
    channel.setReceiver(this);
    channel.connect("ChatCluster");
    eventLoop();
    channel.close();
  }

  private void eventLoop() {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    while (true) {
      try {
        System.out.print("> ");
        System.out.flush();
        String line = in.readLine().toLowerCase();
        if (line.startsWith("quit") || line.startsWith("exit")) {
          break;
        }
        Message msg = new Message(null, null, line);
        channel.send(msg);
      } catch (Exception e) {
      }
    }
  }

  public static void main(String[] args) throws Exception {
    String props = "udp.xml";
    String name = null;

    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-props")) {
        props = args[++i];
        continue;
      }
      if (args[i].equals("-name")) {
        name = args[++i];
        continue;
      }
      help();
      return;
    }

    new SimpleChat().start(props, name);
  }

  protected static void help() {
    System.out.println("SimpleChat [-props XML config] [-name name]");
  }
}


配置文件udp.xml:

<config xmlns="urn:org:jgroups"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/JGroups-3.4.xsd">

    <UDP
         mcast_addr="${jgroups.udp.mcast_addr:235.6.6.6}"
         mcast_port="${jgroups.udp.mcast_port:45588}"
         tos="8"
         ucast_recv_buf_size="5M"
         ucast_send_buf_size="1M"
         mcast_recv_buf_size="5M"
         mcast_send_buf_size="1M"
         loopback="true"
         max_bundle_size="64K"
         max_bundle_timeout="30"
         ip_ttl="${jgroups.udp.ip_ttl:2}"
         enable_diagnostics="true"
         thread_naming_pattern="cl"

         timer_type="new"
         timer.min_threads="4"
         timer.max_threads="10"
         timer.keep_alive_time="3000"
         timer.queue_max_size="500"

         thread_pool.enabled="true"
         thread_pool.min_threads="2"
         thread_pool.max_threads="8"
         thread_pool.keep_alive_time="5000"
         thread_pool.queue_enabled="true"
         thread_pool.queue_max_size="10000"
         thread_pool.rejection_policy="discard"

         oob_thread_pool.enabled="true"
         oob_thread_pool.min_threads="1"
         oob_thread_pool.max_threads="8"
         oob_thread_pool.keep_alive_time="5000"
         oob_thread_pool.queue_enabled="false"
         oob_thread_pool.queue_max_size="100"
         oob_thread_pool.rejection_policy="Run"/>

    <PING timeout="2000" num_initial_members="3"/>
    <MERGE2 max_interval="30000" min_interval="10000"/>
    <FD_SOCK/>
    <FD_ALL/>
    <VERIFY_SUSPECT timeout="1500"  />
    <BARRIER />
    <pbcast.NAKACK use_mcast_xmit="true"
                   retransmit_timeout="300,600,1200"
                   discard_delivered_msgs="true"/>

    <pbcast.STABLE stability_delay="1000" 
    			   desired_avg_gossip="50000"
                   max_bytes="4M"/>
    <pbcast.GMS print_local_addr="true"
    			print_physical_addrs="true"
    		    join_timeout="3000"
                view_bundling="true"
                max_join_attempts="3"/>
                
    <UFC max_credits="2M" min_threshold="0.4"/>
    <MFC max_credits="2M" min_threshold="0.4"/>
    <FRAG2 frag_size="60K"  />
    <pbcast.STATE_TRANSFER />

</config>

使用的是组播UDP,  运行java也加上 -Djava.net.preferIPv4Stack=true 参数

请教各位,在这些云服务器上部署jgroups的分布式程序,能使用UDP组播方式吗? 需要服务商做什么配置或购买的机器有什么要求,才能使用?

如果不能使用,应该如何修改配置文件,把这个SimpleChat连通?

@红薯




加载中
0
guor
guor

云服务器上,端口的权限默认没有开放,你可以用jgroups自带测试程序看看是否能通讯,先在一台服务器上启动McastReceiverTest

java org.jgroups.tests.McastReceiverTest -mcast_addr 235.6.6.6 -port 45588

然后去另外一个服务器上启动McastSenderTest

java org.jgroups.tests.McastSenderTest -mcast_addr 235.6.6.6 -port 45588

如果在sender端发消息在receiver端能收到,说明是能够通讯的

0
lxrjszl
lxrjszl
碰到了类似的问题,现在有准确说法了吗?
0
虎子牙
虎子牙
我们在阿里去上部署的,我也遇到相同的问题,请问有解决方案吗?
gtd
gtd
不用组播,用点对点的配置方式应该可以解决。 我们的产品需要部署到多个客户的服务器上,因为配置较麻烦,后来放弃这种缓存方式
gtd
gtd
据说可以用tcp的方式配置,别用广播
返回顶部
顶部