3

I am using hazelcast 3.3 in my software for caching in clusters. I based my code on the following example Stackoverflow tcp hazelcast example. (Update 2) Now I face the following problem: The host I run my program on has various network cards (=> multiple IP Numbers). I would like to start various instances of my program on the same machine using different interfaces (IP Numbers) The tcp config for this seems to be

network.getInterfaces().setEnabled(true).addInterface("<MY IP NUMBER>");

No matter what IP I give here, on the OS side hazelcast always binds to 0.0.0.0 (all IPs). Is this wanted? I would expect that hazelcast only binds to a specific IP. Does hazelcast do the packet filtering on its own and therefore binds to all interfaces the same time? That means I cannot use the same port number for my various running program instances since the binding to 0.0.0.0 will of course fail starting the second client (which actually happens)

Community
  • 1
  • 1
magicroomy
  • 395
  • 1
  • 6
  • 19

2 Answers2

3

Studying the Hazelcast documentation (Networking) It was definitly said that Hazelcast by default binds to ALL network interfaces. To change that there is this System property: hazelcast.socket.bind.any The documentation says: set to false and it will only bind to the specified interfaces. I did not check it out but it it sounds like the solution to my problem.

EDIT: I tried now and it worked. Hazelcast only connected to the given interface.

magicroomy
  • 395
  • 1
  • 6
  • 19
1

run "ipconfig" on windows (or "ifconfig" on Linux, etc) to see all network interfaces. You should see at least 127.0.0.1 and some others. If your machine is multi-homed (has multiple network cards connected to multiple networks), make sure to select the correct one.

Bottom line, put the interface IP and not YOUR IP in:

network.getInterfaces().setEnabled(true).addInterface("<INTERFACE IP>");

For XML configs, it would be like this:

<network>
       ... snip...
    <join>
       ... snip... 
    </join>
       ... snip... 
    <interfaces enabled="true">
        <interface> <INTERFACE IP> </interface>
    </interfaces>
       ... snip... 
</network>

ALSO: be careful to put the < interface > element under the < network > element. You could also put the < interface > element inside the < tcp-ip > element but if you put it there, it means something else: if you put the < interface > element inside the < tcp-ip > element, it will be treated as an alias/synonym to the < member > tag, which is something totally different! So, put it under < network > otherwise it won't work!!!

Pierre
  • 2,335
  • 22
  • 40