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

本秂侑毒 提交于 2019-11-30 22:03:40

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

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