您正在尝试通过AWS配置hazelcast群集。
我在docker容器中运行hazelcast并使用--net = host来使用主机网络配置。
当我查看淡褐色日志时,我看到了
[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 c.h.n.t.SocketWriterInitializerImpl - [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 c.h.nio.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);
以上是配置AWSConfig的代码 请帮我解决这个问题。
由于
答案 0 :(得分:2)
您在默认的Hazelcast绑定地址选择机制中遇到issue (#11795)。
有几种解决方法可供选择:
您可以通过提供正确的IP地址作为hazelcast.local.localAddress
系统属性来设置绑定地址:
java -Dhazelcast.local.localAddress=[yourCorrectIpGoesHere]
或
System.setProperty("hazelcast.local.localAddress", "[yourCorrectIpGoesHere]")
阅读Hazelcast参考手册的System properties章节中的详细信息。
Hazelcast Network配置允许您指定可用于绑定服务器的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参考手册的Interfaces部分中的详细信息。
<强>更新强>
使用前面的步骤,您可以设置正确的绑定地址 - 例如ip addr show
返回的本地地址。然而,如果您在本地IP和公共IP不同的环境(云,码头)中运行Hazelcast,则可能不够。
此步骤在环境中是必需的,其中群集节点在另一个节点的报告本地地址下不会彼此看到。您必须设置公共地址 - 它是节点能够到达的公共地址(可选择指定端口)。
networkConfig.setPublicAddress("172.29.238.71");
// or if a non-default Hazelcast port is used - e.g.9991
networkConfig.setPublicAddress("172.29.238.71:9991");