5.2. 集群发现协议


Data Grid 支持不同的协议,允许节点在网络上自动找到并形成集群。

Data Grid 可以使用两种发现机制:

  • 在大多数网络上工作且不依赖于外部服务的通用发现协议。
  • 依赖于外部服务的发现协议来存储和检索 Data Grid 集群的拓扑信息。
    例如,DNS_PING 协议通过 DNS 服务器记录执行发现。
注意

在托管平台上运行 Data Grid 需要使用针对各个云提供商实施的网络限制的发现机制。

5.2.1. PING

PING 或 UDPPING 是一种通用 JGroups 发现机制,它使用 UDP 协议的动态多播。

加入后,节点将 PING 请求发送到 IP 多播地址,以发现已在 Data Grid 集群中的其他节点。每个节点通过包含协调器节点地址的数据包以及自己的地址来响应 PING 请求。C=coordinator 的地址和 A=own 地址。如果没有节点响应 PING 请求,则加入节点会成为新集群中的协调节点。

PING 配置示例

<PING num_discovery_runs="3"/>
Copy to Clipboard Toggle word wrap

5.2.2. TCPPING

TCPPING 是一种通用 JGroups 发现机制,它对群集成员使用静态地址列表。

使用 TCPPING 时,您可以手动将 Data Grid 集群中每个节点的 IP 地址或主机名指定为 JGroups 堆栈的一部分,而不是让节点动态发现其他节点。

TCPPING 配置示例

<TCP bind_port="7800" />
<TCPPING timeout="3000"
         initial_hosts="${jgroups.tcpping.initial_hosts:hostname1[port1],hostname2[port2]}"
         port_range="0"
         num_initial_members="3"/>
Copy to Clipboard Toggle word wrap

5.2.3. MPING

MPING 使用 IP 多播来发现 Data Grid 集群的初始成员资格。

您可以使用 MPING 将 TCPPING 发现替换为 TCP 堆栈,并使用 multicasing 进行发现,而不使用初始主机的静态列表。但是,您还可以将 MPING 与 UDP 堆栈一起使用。

MPING 配置示例

<MPING mcast_addr="${jgroups.mcast_addr:239.6.7.8}"
       mcast_port="${jgroups.mcast_port:46655}"
       num_discovery_runs="3"
       ip_ttl="${jgroups.udp.ip_ttl:2}"/>
Copy to Clipboard Toggle word wrap

5.2.4. TCPGOSSIP

gossip 路由器在网络上提供一个中央位置,用于您的数据网格集群可以检索其他节点的地址。

您可以将 Gossip 路由器的地址(IP:PORT)注入 Data Grid 节点,如下所示:

  1. 将 address 作为系统属性传递给 JVM;例如,-DGossipRouterAddress="10.10.2.4[12001]"
  2. 在 JGroups 配置文件中引用该系统属性。

gossip 路由器配置示例

<TCP bind_port="7800" />
<TCPGOSSIP timeout="3000"
           initial_hosts="${GossipRouterAddress}"
           num_initial_members="3" />
Copy to Clipboard Toggle word wrap

5.2.5. JDBC_PING2

JDBC_PING2 使用共享数据库存储关于 Data Grid 集群的信息。此协议支持任何可以使用 JDBC 连接的数据库。

节点将其 IP 地址写入共享数据库,以便加入节点可以在网络上找到 Data Grid 集群。当节点离开 Data Grid 集群时,它们会从共享数据库中删除其 IP 地址。

JDBC_PING2 配置示例

<JDBC_PING connection_url="jdbc:mysql://localhost:3306/database_name"
           connection_username="user"
           connection_password="password"
           connection_driver="com.mysql.jdbc.Driver"/>
Copy to Clipboard Toggle word wrap

重要

将适当的 JDBC 驱动程序添加到 classpath 中,以便 Data Grid 可以使用 JDBC_PING2。

5.2.5.1. 将服务器数据源用于 JDBC_PING2 发现

将受管数据源添加到 Data Grid 服务器,并使用它来为集群传输 JDBC_PING2 发现协议提供数据库连接。

先决条件

  • 安装 Data Grid Server 集群。

流程

  1. 将 JDBC 驱动程序 JAR 部署到 Data Grid Server server/lib 目录中
  2. 为您的数据库创建数据源。

    <server xmlns="urn:infinispan:server:15.0">
      <data-sources>
         <!-- Defines a unique name for the datasource and JNDI name that you
              reference in JDBC cache store configuration.
              Enables statistics for the datasource, if required. -->
         <data-source name="ds"
                      jndi-name="jdbc/postgres"
                      statistics="true">
            <!-- Specifies the JDBC driver that creates connections. -->
            <connection-factory driver="org.postgresql.Driver"
                                url="jdbc:postgresql://localhost:5432/postgres"
                                username="postgres"
                                password="changeme">
               <!-- Sets optional JDBC driver-specific connection properties. -->
               <connection-property name="name">value</connection-property>
            </connection-factory>
            <!-- Defines connection pool tuning properties. -->
            <connection-pool initial-size="1"
                             max-size="10"
                             min-size="3"
                             background-validation="1000"
                             idle-removal="1"
                             blocking-timeout="1000"
                             leak-detection="10000"/>
         </data-source>
      </data-sources>
    </server>
    Copy to Clipboard Toggle word wrap
  3. 创建 JGroups 堆栈,它将使用 JDBC_PING2 协议进行发现。
  4. 通过使用 server:data-source 属性指定数据源的名称,将集群传输配置为使用数据源。

    <infinispan>
        <jgroups>
            <stack name="jdbc" extends="tcp">
                <JDBC_PING stack.combine="REPLACE" stack.position="MPING" />
            </stack>
        </jgroups>
        <cache-container>
            <transport stack="jdbc" server:data-source="ds" />
        </cache-container>
    </infinispan>
    Copy to Clipboard Toggle word wrap

5.2.6. DNS_PING

JGroups DNS_PING 查询 DNS 服务器,以便在 Kubernetes 环境中发现数据网格群集成员,如 OKD 和 Red Hat OpenShift。

DNS_PING 配置示例

<dns.DNS_PING dns_query="myservice.myproject.svc.cluster.local" />
Copy to Clipboard Toggle word wrap

5.2.7. 云发现协议

Data Grid 包括默认的 JGroups 堆栈,它使用特定于云提供商的发现协议实现。

Expand
发现协议默认堆栈文件工件Version

aws.S3_PING

default-jgroups-ec2.xml

org.jgroups.aws:jgroups-aws

3.0.0.Final

OOGLE_PING2

default-jgroups-google.xml

org.jgroups.google:jgroups-google

2.0.0.Final

azure.AZURE_PING

default-jgroups-azure.xml

org.jgroups.azure:jgroups-azure

2.0.2.final

为云发现协议提供依赖项

要使用 aws.S3_PINGGOOGLE_PING2azure.AZURE_PING 云发现协议,您需要向 Data Grid 提供依赖的库。

流程

  • 将工件依赖项添加到项目 pom.xml 中。

然后,您可以将云发现协议配置为 JGroups 堆栈文件或系统属性的一部分。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat