Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Hazelcast nodes installed in docker on different aws instances interact with each other?

I have three aws machines on which I have setup three docker containers having hazelcast-3.5.4 installed on them(ubuntu).With aws configuration set as what I do normally with Hazelcast(without docker).The nodes are not discovering each other. How to make them interact or discover each other?

Hazelcast.xml file looks like this:

    <join>
        <multicast enabled="false">
            <multicast-group>224.2.2.3</multicast-group>
            <multicast-port>54327</multicast-port>
        </multicast>
        <tcp-ip enabled="false">
            <interface>127.0.0.1</interface>
            <member-list>
                <member>127.0.0.1</member>
            </member-list>
        </tcp-ip>
        <aws enabled="true">
            <access-key>Some_key</access-key>
            <secret-key>Secret_key</secret-key>
            <!--optional, default is us-east-1 -->
            <region>us-east-1</region>
            <!--optional, default is ec2.amazonaws.com. If set, region shouldn't be set as it will override this property -->
            <host-header>ec2.amazonaws.com</host-header>
            <!-- optional, only instances belonging to this group will be discovered, default will try all running instances -->
            <!--security-group-name>hazelcast-sg</security-group-name-->
            <tag-key>type</tag-key>
            <tag-value>hz-nodes</tag-value>
        </aws>
    </join>

 <public-address>private-ip-of-aws-node</public-address>
<properties>
  <property name="hazelcast.local.localAddress">private-ip-of-aws-node</property>
</properties>

Also I have added two more entries as suggested in a similar post somewhere which doesn't seem to work for me.

like image 644
user2966021 Avatar asked Feb 08 '23 00:02

user2966021


1 Answers

You need to run your hazelcast docker image with --net=host option. I tested with docker image published by hazelcast (https://hub.docker.com/r/hazelcast/hazelcast/) with version 3.5.4 with two instances on aws ec2. My Docker version is Docker version 1.9.1, build a34a1d5 and ami I used on ec2 is Ubuntu Server 14.04 LTS (HVM), SSD Volume Type - ami-fce3c696 and here is my hazelcast.xml :

<?xml version="1.0" encoding="UTF-8"?>
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.5.xsd"
           xmlns="http://www.hazelcast.com/schema/config"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <group>
        <name>dev</name>
        <password>dev-pass</password>
    </group>
    <management-center enabled="false">http://localhost:8080/mancenter</management-center>
    <network>
        <port auto-increment="true" port-count="100">5701</port>
        <outbound-ports>
            <!--
            Allowed port range when connecting to other nodes.
            0 or * means use system provided port.
            -->
            <ports>0</ports>
        </outbound-ports>
        <join>
            <multicast enabled="false">
                <multicast-group>224.2.2.3</multicast-group>
                <multicast-port>54327</multicast-port>
            </multicast>
            <tcp-ip enabled="false">
                <interface>127.0.0.1</interface>
                <member-list>
                    <member>127.0.0.1</member>
                </member-list>
            </tcp-ip>
            <aws enabled="true">
                <access-key>your-acces-key</access-key>
                <secret-key>your-secret-key</secret-key>
            </aws>
        </join>
        <public-address>private-ip-address-of-ec2-instance</public-address>
    </network>
    <properties>
       <property name="hazelcast.local.localAddress">private-ip-address-of-ec2-instance</property>
   </properties>
</hazelcast>

This is my docker command for running hazelcast image with custom config file : docker run --net=host -e JAVA_OPTS="-Dhazelcast.config=/configFolder/hazelcast.xml" -v ~/configFolder:/configFolder -ti hazelcast/hazelcast

If --net=host option does not work, make sure that in your security group config ports used by hazelcast are open as inbound ports. Also you can enable debugging to see more details about nodes discovered by ec2 discovery.

Please see Debugging section under hazelcast ec2 discovery section : http://docs.hazelcast.org/docs/latest-dev/manual/html-single/index.html#discovering-members-within-ec2-cloud

like image 98
ibrahim gürses Avatar answered Feb 12 '23 10:02

ibrahim gürses