Hazelcast cluster over AWS using Docker

蓝咒 提交于 2019-12-08 23:14:29

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

There are several workarounds available:

Workaround 1: System property

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

java -Dhazelcast.local.localAddress=[yourCorrectIpGoesHere]

or

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

Read details in System properties chapter of Hazelcast Reference Manual.

Workaround 2: Hazelcast Network configuration

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

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>

Programmatic:

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);

Read details in Interfaces section of Hazelcast Reference Manual.

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).

Next Step: Configure public address

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");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!