且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Docker的AWS上的Hazelcast集群

更新时间:2023-12-01 15:39:04

您正在遇到问题(#11795)在默认的Hazelcast绑定地址选择机制中.

You are experiencing an issue (#11795) in default Hazelcast bind address selection mechanism.

有几种解决方法:

您可以通过提供正确的IP地址作为hazelcast.local.localAddress系统属性来设置绑定地址:

You can set the bind address by providing correct IP address as a hazelcast.local.localAddress system property:

java -Dhazelcast.local.localAddress=[yourCorrectIpGoesHere]

System.setProperty("hazelcast.local.localAddress", "[yourCorrectIpGoesHere]")

阅读系统中的详细信息属性,参见《 Hazelcast参考手册》.

Read details in System properties chapter of Hazelcast Reference Manual.

Hazelcast网络配置允许您指定可用于绑定服务器的IP地址.

Hazelcast Network configuration allows you to specify which IP addresses can be used to bind the server.

hazelcast.xml中的声明:

Declarative in hazelcast.xml:

<hazelcast>
  ...
  <network>
    ...
    <interfaces enabled="true">
      <interface>10.3.16.*</interface> 
      <interface>10.3.10.4-18</interface> 
      <interface>192.168.1.3</interface>         
    </interfaces>    
  </network>
  ...
</hazelcast>

程序化:

Config config = new Config();
NetworkConfig network = config.getNetworkConfig();
InterfacesConfig interfaceConfig = network.getInterfaces();
interfaceConfig.setEnabled(true).addInterface("192.168.1.3");
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);

界面《 Hazelcast参考手册》的a>部分.

更新: 通过前面的步骤,您可以设置适当的绑定地址-例如ip addr show返回的本地地址.但是,如果您在本地IP和公共IP不同的环境(云,泊坞窗)中运行Hazelcast,这可能是不够的.

Update: With the earlier steps you are able to set a proper bind address - the local one returned by ip addr show for instance. Nevertheless, it could be insufficient if you run Hazelcast in an environment where local IP and public IP differs (clouds, docker).

在群集节点在另一个节点的报告本地地址下看不到彼此的环境中,此步骤是必需的.您必须设置公共地址-这是节点可以访问的地址(可以选择指定端口).

This step is necessary in environments, where cluster nodes doesn't see each other under the reported local address of the other node. You have to set the public address - it's the one which nodes are able to reach (optionally with port specified).

networkConfig.setPublicAddress("172.29.238.71");

// or if a non-default Hazelcast port is used - e.g.9991
networkConfig.setPublicAddress("172.29.238.71:9991");