【问题标题】:How to make Hazelcast nodes installed in docker on different aws instances interact with each other?如何使安装在不同aws实例上的docker中的Hazelcast节点相互交互?
【发布时间】:2016-04-24 10:45:06
【问题描述】:

我有三台 aws 机器,在这些机器上我设置了三个安装了 hazelcast-3.5.4 的 docker 容器(ubuntu)。将 aws 配置设置为我通常使用 Hazelcast 所做的(没有 docker)。节点没有发现彼此。如何让他们互动或发现彼此?

Hazelcast.xml 文件如下所示:

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

此外,我还添加了两个条目,如某处类似帖子中所建议的那样,这似乎对我不起作用。

【问题讨论】:

  • 以下是我的 hazelcast.xml 配置
  • 我可以从节点 1 中的 docker 容器 ping 节点 2,反之亦然。

标签: amazon-web-services docker cloud hazelcast


【解决方案1】:

您需要使用 --net=host 选项运行您的 hazelcast docker 映像。我使用 hazelcast (https://hub.docker.com/r/hazelcast/hazelcast/) 发布的 docker 镜像进行了测试,版本为 3.5.4,在 aws ec2 上有两个实例。我的 Docker 版本是 Docker version 1.9.1, build a34a1d5 ,我在 ec2 上使用的 ami 是 Ubuntu Server 14.04 LTS (HVM), SSD Volume Type - ami-fce3c696,这是我的 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>

这是我使用自定义配置文件运行 hazelcast 映像的 docker 命令: docker run --net=host -e JAVA_OPTS="-Dhazelcast.config=/configFolder/hazelcast.xml" -v ~/configFolder:/configFolder -ti hazelcast/hazelcast

如果--net=host 选项不起作用,请确保在您的安全组配置中 hazelcast 使用的端口作为入站端口打开。您还可以启用调试以查看有关 ec2 发现发现的节点的更多详细信息。

请参阅 hazelcast ec2 发现部分下的 Debugging 部分:http://docs.hazelcast.org/docs/latest-dev/manual/html-single/index.html#discovering-members-within-ec2-cloud

【讨论】:

  • 感谢易卜拉欣!我试着按照你说的运行容器,但我仍然无法让 hazelcast 容器相互交互。所有 TCP 端口都在 AWS 安全组中打开。
  • 我可以知道您使用的是哪个 docker 版本吗?
  • 我正在按照您的解释做所有事情。即使使用了您的 hazelcast.xml 文件。我使用的是相同版本的 docker 并且所有入站和出站连接都打开了所有 TCP。我仍然无法让他们互动。
  • 你在 hazelcast 日志中看到的 ip 是什么。您是否看到像 Members [2] { Member [172.31.15.17]:5701 this Member [172.31.2.238]:5701 } 这样的 ec2 实例的私有 ip。你也可以启用调试,当你启用调试时,你应该看到以日志条目Found the following EC2 instances:开头的找到的ec2实例的IP地址。
  • 问题已解决...我没有在两个节点中启用 UFW。现在 sudo ufw enable 后它正在工作..感谢所有帮助。 :)
猜你喜欢
  • 1970-01-01
  • 2014-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-16
  • 2019-10-04
  • 1970-01-01
相关资源
最近更新 更多