Openshift堆栈上的Infinispan和jgroups实现

时间:2016-05-20 06:30:00

标签: infinispan jgroups

问题-1

我正在尝试在Openshift Tomcat齿轮上运行Infinispan集群。节点位于两个不同的主机上。我使用TCP作为数据传输协议,使用MPING作为发现协议。

如果我尝试使用任何JGROUPS提供的关键字作为绑定地址,如GLOBAL,SITE_LOCAL,LINK_LOCAL,NON_LOOPBACK,match-interface,match-host,match-address,除LOOPBACK外,它将服务绑定到公共IP( 64.XXX)和LOOPBACK它将它绑定到127.0.0.1。这不是我想要实现的。

我希望它在Openshift提供的自定义IP地址上运行JGROUPS服务,看起来像127.2.155.1。如果我能够在给定的IP中运行它,那么我将很容易编写端口转发规则,以便集群成员即使它们存在于不同的主机中也能够相互发现。

使用环境属性

Map<String, String> envKeys = System.getenv();
    for (String keys : envKeys.keySet()) {
        System.out.println(keys + ":" + envKeys.get(keys));
        if (keys.equalsIgnoreCase("OPENSHIFT_JBOSSEWS_IP")) {
            System.setProperty("OPENSHIFT_JBOSSEWS_IP",  envKeys.get(keys));
        }
    }

在执行上述操作时失败,说无法找到IP地址或127.2.155.1是无效的IP地址。请在我的项目中找到我正在使用的示例jgroups.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">
<TCP
    bind_addr="${OPENSHIFT_JBOSSEWS_IP}"
    bind_port="${jgroups.tcp.port:7800}"
    port_range="0"
    recv_buf_size="20m"
    send_buf_size="640k"
    max_bundle_size="31k"
    use_send_queues="true"
    enable_diagnostics="false"
    bundler_type="sender-sends-with-timer"

    thread_naming_pattern="pl"

    thread_pool.enabled="true"
    thread_pool.min_threads="2"
    thread_pool.max_threads="30"
    thread_pool.keep_alive_time="60000"
    thread_pool.queue_enabled="true"
    thread_pool.queue_max_size="100"
    thread_pool.rejection_policy="Discard"

    oob_thread_pool.enabled="true"
    oob_thread_pool.min_threads="2"
    oob_thread_pool.max_threads="30"
    oob_thread_pool.keep_alive_time="60000"
    oob_thread_pool.queue_enabled="false"
    oob_thread_pool.queue_max_size="100"
    oob_thread_pool.rejection_policy="Discard"

    internal_thread_pool.enabled="true"
    internal_thread_pool.min_threads="2"
    internal_thread_pool.max_threads="4"
    internal_thread_pool.keep_alive_time="60000"
    internal_thread_pool.queue_enabled="true"
    internal_thread_pool.queue_max_size="100"
    internal_thread_pool.rejection_policy="Discard"
    />

   <!-- Ergonomics, new in JGroups 2.11, are disabled by default in TCPPING until JGRP-1253 is resolved -->
   <!--
   <TCPPING timeout="3000"
        initial_hosts="localhost[7800],localhost[7801]"
        port_range="5"
        num_initial_members="3"
        ergonomics="false"
    />
   -->

  <MPING bind_addr="{OPENSHIFT_JBOSSEWS_IP}" 
  break_on_coord_rsp="true"
  mcast_addr="${jgroups.mping.mcast_addr:228.2.4.6}"
  mcast_port="${jgroups.mping.mcast_port:43376}"
  ip_ttl="${jgroups.udp.ip_ttl:2}"
  num_initial_members="3"/>
  <MERGE3/>

 <FD_SOCK/>
 <FD timeout="3000" max_tries="5"/>
 <VERIFY_SUSPECT timeout="1500"/>

 <pbcast.NAKACK2 use_mcast_xmit="false"
               xmit_interval="1000"
               xmit_table_num_rows="100"
               xmit_table_msgs_per_row="10000"
               xmit_table_max_compaction_time="10000"
               max_msg_batch_size="100"/>
 <UNICAST3 xmit_interval="500"
         xmit_table_num_rows="20"
         xmit_table_msgs_per_row="10000"
         xmit_table_max_compaction_time="10000"
         max_msg_batch_size="100"
         conn_expiry_timeout="0"/>

 <pbcast.STABLE stability_delay="500" desired_avg_gossip="5000" max_bytes="1m"/>
 <pbcast.GMS print_local_addr="false" join_timeout="3000" view_bundling="true"/>
 <tom.TOA/> <!-- the TOA is only needed for total order transactions-->

 <MFC max_credits="2m" min_threshold="0.40"/>
 <FRAG2 frag_size="30k"/>
 <RSVP timeout="60000" resend_interval="500" ack_on_delivery="false" />
 </config>

问题-2

当Infinispan成功启动时,它会在端口7800上运行2个java进程,如上面的配置文件中所述,以及另一个在Infinispan随机选择的端口号上运行。我想更多地了解这些过程。

**COMMAND   PID     USER   FD   TYPE     DEVICE SIZE/OFF NODE NAME**
java     5640     1334   44u  IPv4 1556890779      0t0  TCP 127.2.155.1:7800 (LISTEN)
java     5640     1334   44u  IPv4 1556890779      0t0 TCP 127.2.155.1:20772 (LISTEN)

1 个答案:

答案 0 :(得分:3)

问题-1:

将bind_addr设置为127.2.155.1应该选择正确的地址(127.2.155.1)。 执行ifconfig后会bind_addr显示吗?

问题2:

第二个端口可能是由FD_SOCK打开的。您可以通过在start_port中设置属性FD_SOCKimport java.util.*; public class test { static Scanner sc = new Scanner(System.in); // add all the words you need into this array static String [] wordArr = new String[] { "yes", "hello", "boo" }; // this converts the array to a List static final List<String> WORDS = new ArrayList<String>(Arrays.asList(wordArr)); public static void main(String[] args) { System.out.println("Choose a word"); String userEntry = sc.next().toLowerCase(); // check if the word is in the list if (WORDS.contains(userEntry)) { System.out.println("We found a match"); } else { System.out.println("We did not find a match"); } } } 来控制这一点。

[1] http://www.jgroups.org/manual/index.html#CommonProps