24.2.3. 配置 TCPPING

此流程创建一个新的 JGroups 堆栈,它使用 TCPPING 协议来定义静态集群成员资格列表。系统提供了基础脚本,该脚本可创建 tcpping 堆栈并将默认 频道 设置为使用此新堆栈。此脚本中的管理 CLI 命令必须为您的环境自定义,并将作为批处理处理。

  1. 将以下脚本复制到文本编辑器中,并将它保存到本地文件系统。

    # Define the socket bindings
    /socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=jgroups-host-a:add(host=HOST_A,port=7600)
    /socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=jgroups-host-b:add(host=HOST_B,port=7600)
    batch
    # Add the tcpping stack
    /subsystem=jgroups/stack=tcpping:add
    /subsystem=jgroups/stack=tcpping/transport=TCP:add(socket-binding=jgroups-tcp)
    /subsystem=jgroups/stack=tcpping/protocol=TCPPING:add(socket-bindings=[jgroups-host-a,jgroups-host-b])
    /subsystem=jgroups/stack=tcpping/protocol=MERGE3:add
    /subsystem=jgroups/stack=tcpping/protocol=FD_SOCK:add
    /subsystem=jgroups/stack=tcpping/protocol=FD_ALL:add
    /subsystem=jgroups/stack=tcpping/protocol=VERIFY_SUSPECT:add
    /subsystem=jgroups/stack=tcpping/protocol=pbcast.NAKACK2:add
    /subsystem=jgroups/stack=tcpping/protocol=UNICAST3:add
    /subsystem=jgroups/stack=tcpping/protocol=pbcast.STABLE:add
    /subsystem=jgroups/stack=tcpping/protocol=pbcast.GMS:add
    /subsystem=jgroups/stack=tcpping/protocol=MFC:add
    /subsystem=jgroups/stack=tcpping/protocol=FRAG2:add
    # Set tcpping as the stack for the ee channel
    /subsystem=jgroups/channel=ee:write-attribute(name=stack,value=tcpping)
    run-batch
    reload

    请注意,定义的协议的顺序非常重要。您还可以通过传递 add-index 值到 add 命令,将协议插入到特定的索引中。索引基于零,因此以下管理 CLI 命令添加 UNICAST3 协议作为第七个协议:

    /subsystem=jgroups/stack=tcpping/protocol=UNICAST3:add(add-index=6)
  2. 为您的环境修改 脚本。

    • 如果您在受管域中运行,则必须通过 /profile= PROFILE_NAME/subsystem=jgroups 命令之前指定要更新的配置集
    • 根据您的环境调整以下属性:

      • 套接字绑定: 以逗号分隔的主机和端口组合列表,这些组合被视为众所周知的,并可用于查找初始成员身份。有关定义套接字绑定的更多信息,请参阅配置套接字绑定
      • initial_hosts :以逗号分隔的主机和端口组合列表,使用语法 HOST[PORT ] 这些 [ PORT ] 被视为广为人知且可用于查找初始成员资格,如 host1[1000],host2[2000]
      • port_range :此属性用于将 initial_hosts 端口范围扩展为指定的值。例如,如果您将 initial_hosts 设置为 host1[1000],host2[2000],并且 port_range 设为 1,则 initial_hosts 设置将扩展到 host1[1000],host1[1001],host2[2000],host2[2001]。此属性仅适用于 initial_hosts 属性。
  3. 通过将 脚本文件传递到管理 CLI 来运行 脚本。

    $ EAP_HOME/bin/jboss-cli.sh --connect --file=/path/to/SCRIPT_NAME

TCPPING 堆栈现已可用,TCP 用于网络通信。

24.2.3.1. 在独立模式中配置 TCPPING

此流程可帮助您在独立模式下为集群应用程序配置 TCP 堆栈和节点。

流程

  1. 在 JGroups 子系统中将默认堆栈从 udp 改为 tcp :

    <channel name="ee" stack="tcp" cluster="ejb"/>
  2. 将 TCP 堆栈配置为使用 TCPPING 协议代替默认的 MPING 协议。在以下代码中,initial_hosts 属性与群集内所有节点的列表相关联,而 7600 表示默认的 jgroups-tcp 端口可以根据您的配置和环境而变化。

    <stack name="tcp">
      <transport type="TCP" socket-binding="jgroups-tcp"/>
      <protocol type="TCPPING">
        <property name="initial_hosts">192.168.1.5[7600],192.168.1.9[7600]</property>
        <property name="port_range">0</property>
      </protocol>
      <protocol type="MERGE3"/>
      <protocol type="FD_SOCK" socket-binding="jgroups-tcp-fd"/>
      <protocol type="FD_ALL"/>
      <protocol type="VERIFY_SUSPECT"/>
      <protocol type="pbcast.NAKACK2"/>
      <protocol type="UNICAST3"/>
      <protocol type="pbcast.STABLE"/>
      <protocol type="pbcast.GMS"/>
      <protocol type="MFC"/>
      <protocol type="FRAG3"/>
    </stack>
    注意

    initial_hosts 中设置的端口号 7600 必须与 jgroups-tcp 套接字绑定定义中定义的端口号相同。如果将 port-offset 功能用于 socket-binding,则需要在 initial_hosts 中指定偏移后相同的值。

  3. 设置专用接口的 IP 地址,供 JGroups 组件使用。IP 地址应与 initial_hosts 中指定的 IP 地址之一相关联:

    <interface name="private">
      <inet-address value="${jboss.bind.address.private:192.168.1.5}"/>
    </interface>
  4. 重复上述步骤来配置集群中的其他节点。配置节点时,启动每个节点并部署集群应用。

验证

  • 您可以检查日志以验证节点是否已启动并在运行:

    INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (thread-2,ee,node_1) ISPN000094: Received new cluster view for channel server: [node_1|1] (2) [node_1, node_2]
    INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (thread-2,ee,node_1) ISPN000094: Received new cluster view for channel web: [node_1|1] (2) [node_1, node_2]