使用Docker的AWS上的Hazelcast群集

您好尝试通过AWSconfigurationhazelcast集群。

我正在docker容器中运行hazelcast并使用–net = host来使用主机networkingconfiguration。

当我看着榛树日志,我明白了

[172.17.0.1]:5701 [herald] [3.8] Established socket connection between /[node2]:5701 and /[node1]:47357 04:24:22.595 [hz._hzInstance_1_herald.IO.thread-out-0] DEBUG chntSocketWriterInitializerImpl - [172.17.0.1]:5701 [herald] [3.8] Initializing SocketWriter WriteHandler with Cluster Protocol 04:24:22.595 [hz._hzInstance_1_herald.IO.thread-in-0] WARN chnio.tcp.TcpIpConnectionManager - [172.17.0.1]:5701 [herald] [3.8] Wrong bind request from [172.17.0.1]:5701! This node is not requested endpoint: [node2]:5701 04:24:22.595 [hz._hzInstance_1_herald.IO.thread-in-0] INFO c.hazelcast.nio.tcp.TcpIpConnection - [172.17.0.1]:5701 [herald] [3.8] Connection[id=40, /[node2]:5701->/[node1]:47357, endpoint=null, alive=false, type=MEMBER] closed. Reason: Wrong bind request from [172.17.0.1]:5701! This node is not requested endpoint: [node2]:5701 

我可以看到错误,说明绑定请求从172.17.0.1到node1,而node1不接受这个请求。

  final Config config = new Config(); config.setGroupConfig(clientConfig().getGroupConfig()); final NetworkConfig networkConfig = new NetworkConfig(); final JoinConfig joinConfig = new JoinConfig(); final TcpIpConfig tcpIpConfig = new TcpIpConfig(); final MulticastConfig multicastConfig = new MulticastConfig(); multicastConfig.setEnabled(false); final AwsConfig awsConfig = new AwsConfig(); awsConfig.setEnabled(true); // awsConfig.setSecurityGroupName("xxxx"); awsConfig.setRegion("xxxx"); awsConfig.setIamRole("xxxx"); awsConfig.setTagKey("type"); awsConfig.setTagValue("xxxx"); awsConfig.setConnectionTimeoutSeconds(120); joinConfig.setAwsConfig(awsConfig); joinConfig.setMulticastConfig(multicastConfig); joinConfig.setTcpIpConfig(tcpIpConfig); networkConfig.setJoin(joinConfig); final InterfacesConfig interfaceConfig = networkConfig.getInterfaces(); interfaceConfig.setEnabled(true).addInterface("172.29.238.71"); config.setNetworkConfig(networkConfig); 

以上是configurationAWSConfig的代码请帮我解决这个问题。

谢谢

您遇到了默认Hazelcast绑定地址select机制中的问题(#11795) 。

有几个解决方法可用:

解决方法1:系统属性

您可以通过提供正确的IP地址作为hazelcast.local.localAddress系统属性来设置绑定地址:

 java -Dhazelcast.local.localAddress=[yourCorrectIpGoesHere] 

要么

 System.setProperty("hazelcast.local.localAddress", "[yourCorrectIpGoesHere]") 

在Hazelcast参考手册的“ 系统属性”一章中阅读详细信息。

解决方法2:Hazelcastnetworkingconfiguration

Hazelcastnetworkingconfiguration允许您指定可以使用哪些IP地址绑定服务器。

hazelcast.xml声明:

 <hazelcast> ... <network> ... <interfaces enabled="true"> <interface>10.3.16.*</interface> <interface>10.3.10.4-18</interface> <interface>192.168.1.3</interface> </interfaces> </network> ... </hazelcast> 

程序化:

 Config config = new Config(); NetworkConfig network = config.getNetworkConfig(); InterfacesConfig interfaceConfig = network.getInterfaces(); interfaceConfig.setEnabled(true).addInterface("192.168.1.3"); HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config); 

阅读Hazelcast参考手册的“ 接口”部分的详细信息。

更新:使用前面的步骤,您可以设置一个正确的绑定地址 – 本地的ip addr show返回的实例。 然而,如果您在本地IP和公共IP不同的环境(云,docker)中运行Hazelcast,则可能不够。

下一步:configuration公共地址

在其他节点的报告的本地地址下,群集节点彼此不会看到彼此的环境中,此步骤是必需的。 您必须设置公共地址 – 这是节点能够到达的地址(可选地指定端口)。

 networkConfig.setPublicAddress("172.29.238.71"); // or if a non-default Hazelcast port is used - eg9991 networkConfig.setPublicAddress("172.29.238.71:9991");