Hazelcast AWS ec2自动发现

时间:2018-10-30 13:32:05

标签: java amazon-web-services amazon-ec2 hazelcast

尝试通过以下具有自动发现功能的简单配置从AWS ec2实例运行Hazelcast成员。

hazelcast.xml

<hazelcast xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.hazelcast.com/schema/config
                                   http://www.hazelcast.com/schema/config/hazelcast-config-3.11.xsd"
               xmlns="http://www.hazelcast.com/schema/config">
        <properties>
            <property name="hazelcast.diagnostics.enabled">true</property>
        </properties>

        <network>
            <join>
                <multicast enabled="false" />
                <tcp-ip enabled="false"/>
                <aws enabled="true">
                    <access-key>xxxxxxx</access-key>
                    <secret-key>xxxxxxx</secret-key>
                    <region>eu-west-1a</region>
                    <security-group-name>my-group</security-group-name>
                    <tag-key>type</tag-key>
                    <tag-value>hz-node</tag-value>
                </aws>
            </join>
        </network>
    </hazelcast>

Member.java

import com.hazelcast.core.Hazelcast;

public class Member {
    public static void main(String[] args) {
        Hazelcast.newHazelcastInstance();
    }
}

但是当我从ec2实例执行程序时,得到以下信息:

ubuntu@ip-172-31-19-20:~$ java -jar sdsi.jar
Oct 30, 2018 1:25:09 PM com.hazelcast.config.XmlConfigLocator
INFO: Loading 'hazelcast.xml' from classpath.
Oct 30, 2018 1:25:10 PM com.hazelcast.instance.AddressPicker
INFO: [LOCAL] [dev] [3.11] Prefer IPv4 stack is true, prefer IPv6 addresses is f                     alse
Oct 30, 2018 1:25:10 PM com.hazelcast.instance.AddressPicker
INFO: [LOCAL] [dev] [3.11] Picked [172.31.19.20]:5701, using socket ServerSocket                     [addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
Oct 30, 2018 1:25:11 PM com.hazelcast.system
INFO: [172.31.19.20]:5701 [dev] [3.11] Hazelcast 3.11 (20181023 - 1500bbb) start                     ing at [172.31.19.20]:5701
Oct 30, 2018 1:25:11 PM com.hazelcast.system
INFO: [172.31.19.20]:5701 [dev] [3.11] Copyright (c) 2008-2018, Hazelcast, Inc.                      All Rights Reserved.
Oct 30, 2018 1:25:11 PM com.hazelcast.instance.Node
INFO: [172.31.19.20]:5701 [dev] [3.11] A non-empty group password is configured                      for the Hazelcast member. Starting with Hazelcast version 3.8.2, members with th                     e same group name, but with different group passwords (that do not use authentic                     ation) form a cluster. The group password configuration will be removed complete                     ly in a future release.
Oct 30, 2018 1:25:11 PM com.hazelcast.spi.impl.operationservice.impl.Backpressur                     eRegulator
INFO: [172.31.19.20]:5701 [dev] [3.11] Backpressure is disabled
Oct 30, 2018 1:25:12 PM com.hazelcast.instance.Node
INFO: [172.31.19.20]:5701 [dev] [3.11] Activating Discovery SPI Joiner
Oct 30, 2018 1:25:12 PM com.hazelcast.spi.impl.operationexecutor.impl.OperationE                     xecutorImpl
INFO: [172.31.19.20]:5701 [dev] [3.11] Starting 2 partition threads and 3 generi                     c threads (1 dedicated for priority tasks)
Oct 30, 2018 1:25:12 PM com.hazelcast.internal.diagnostics.Diagnostics
INFO: [172.31.19.20]:5701 [dev] [3.11] Diagnostics started
Oct 30, 2018 1:25:12 PM com.hazelcast.internal.diagnostics.BuildInfoPlugin
INFO: [172.31.19.20]:5701 [dev] [3.11] Plugin:active
Oct 30, 2018 1:25:12 PM com.hazelcast.internal.diagnostics.SystemPropertiesPlugi                     n
INFO: [172.31.19.20]:5701 [dev] [3.11] Plugin:active
Oct 30, 2018 1:25:12 PM com.hazelcast.internal.diagnostics.ConfigPropertiesPlugi                     n
INFO: [172.31.19.20]:5701 [dev] [3.11] Plugin:active
Oct 30, 2018 1:25:12 PM com.hazelcast.internal.diagnostics.MetricsPlugin
INFO: [172.31.19.20]:5701 [dev] [3.11] Plugin:active, period-millis:60000
Oct 30, 2018 1:25:12 PM com.hazelcast.internal.diagnostics.SlowOperationPlugin
INFO: [172.31.19.20]:5701 [dev] [3.11] Plugin:active, period-millis:60000
Oct 30, 2018 1:25:12 PM com.hazelcast.internal.diagnostics.MemberHazelcastInstan                     ceInfoPlugin
INFO: [172.31.19.20]:5701 [dev] [3.11] Plugin:active, period-millis:60000
Oct 30, 2018 1:25:12 PM com.hazelcast.internal.diagnostics.SystemLogPlugin
INFO: [172.31.19.20]:5701 [dev] [3.11] Plugin:active: logPartitions:false
Oct 30, 2018 1:25:12 PM com.hazelcast.internal.diagnostics.MemberHazelcastInstan                     ceInfoPlugin
INFO: [172.31.19.20]:5701 [dev] [3.11] Plugin:active, period-millis:10000
Oct 30, 2018 1:25:12 PM com.hazelcast.internal.diagnostics.OperationHeartbeatPlu                     gin
INFO: [172.31.19.20]:5701 [dev] [3.11] Plugin:active: period-millis:10000 max-de                     viation:33%
Oct 30, 2018 1:25:12 PM com.hazelcast.core.LifecycleService
INFO: [172.31.19.20]:5701 [dev] [3.11] [172.31.19.20]:5701 is STARTING
Oct 30, 2018 1:25:14 PM com.hazelcast.aws.utility.RetryUtils
WARNING: Couldn't connect to the AWS service, [1] retrying in 1 seconds...
Oct 30, 2018 1:25:15 PM com.hazelcast.aws.utility.RetryUtils
WARNING: Couldn't connect to the AWS service, [2] retrying in 2 seconds...
Oct 30, 2018 1:25:18 PM com.hazelcast.aws.utility.RetryUtils
WARNING: Couldn't connect to the AWS service, [3] retrying in 3 seconds...
Oct 30, 2018 1:25:21 PM com.hazelcast.aws.utility.RetryUtils
WARNING: Couldn't connect to the AWS service, [4] retrying in 5 seconds...
Oct 30, 2018 1:25:26 PM com.hazelcast.aws.utility.RetryUtils
WARNING: Couldn't connect to the AWS service, [5] retrying in 7 seconds...
Oct 30, 2018 1:25:34 PM com.hazelcast.aws.utility.RetryUtils
WARNING: Couldn't connect to the AWS service, [6] retrying in 11 seconds...

有什么解决方法吗?还是我在配置中缺少任何内容? 重试继续进行。启用的诊断消息,仍然无法找出问题所在。

1 个答案:

答案 0 :(得分:3)

您需要将区域用作eu-west-1,因为AWS端点是按区域而不是按可用区的。因此,您的配置应为:

<hazelcast xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.hazelcast.com/schema/config
                                   http://www.hazelcast.com/schema/config/hazelcast-config-3.11.xsd"
               xmlns="http://www.hazelcast.com/schema/config">
        <properties>
            <property name="hazelcast.diagnostics.enabled">true</property>
        </properties>

        <network>
            <join>
                <multicast enabled="false" />
                <tcp-ip enabled="false"/>
                <aws enabled="true">
                    <access-key>xxxxxxx</access-key>
                    <secret-key>xxxxxxx</secret-key>
                    <region>eu-west-1</region>
                    <security-group-name>my-group</security-group-name>
                    <tag-key>type</tag-key>
                    <tag-value>hz-node</tag-value>
                </aws>
            </join>
        </network>
    </hazelcast>