我的配置:
public Config getConfig() {
Config cfg = new Config();
cfg.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
cfg.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true).addMember("10.0.0.1");
cfg.getNetworkConfig().setPort(5900).setPortAutoIncrement(true);
cfg.getNetworkConfig().getInterfaces().setEnabled(true).addInterface( "192.168.43.225" );
cfg.getManagementCenterConfig().setEnabled(true).setUrl("http://localhost:5901/mancenter");
return cfg;
}
public HazelcastInstance getHazelcastInstance() {
try {
hazelcastInstance = Hazelcast.newHazelcastInstance(getConfig());
}catch (Exception e){
System.out.println("Exception :: " + e);
}
return hazelcastInstance;
}
异常:
2019-10-20 00:07:15.460 信息 12259 --- [cached.thread-3] com.hazelcast.nio.tcp.TcpIpConnector : [192.168.43.225]:5900 [dev] [3.12.2]连接到/10.0.0.1:5902,超时:10000,bind-any:true 2019-10-20 00:07:15.460 INFO 12259 --- [cached.thread-2] com.hazelcast.nio.tcp.TcpIpConnector : [192.168.43.225]:5900 [dev] [3.12.2] 连接到/10.0.0.1:5901,超时:10000,绑定(bind)任意:true 2019-10-20 00:07:15.461 INFO 12259 --- [cached.thread-1] com.hazelcast.nio.tcp.TcpIpConnector : [192.168.43.225]:5900 [dev] [3.12.2] 连接到/10.0.0.1:5900,超时:10000,绑定(bind)任意:true 2019-10-20 00:07:30.817 警告 12259 --- [.IO.thread-in-2] com.hazelcast.nio.tcp.TcpIpConnection : [192.168.43.225]:5900 [dev] [3.12.2]连接[id=3,/192.168.43.225:49045->/10.0.0.1:5900,限定符=null,端点=[10.0.0.1]:5900,alive=false,type=NONE]已关闭。原因:连接中出现异常[id=3,/192.168.43.225:49045->/10.0.0.1:5900,qualifier=null,endpoint=[10.0.0.1]:5900,alive=true,type=NONE],thread= hz._hzInstance_1_dev.IO.thread-in-2
java.io.IOException:连接被对等方重置
最佳答案
cfg.getNetworkConfig().getInterfaces().setEnabled(true).addInterface( "192.168.43.225" );
当主机上有多个网络接口(interface)并且您想要强制 Hazelcast 使用其中一些网络接口(interface)时,请使用接口(interface)配置。请查看Interfaces Section了解更多信息。
[192.168.43.225]:5900 [dev] [3.12.2] Connection[id=3, /192.168.43.225:49045->/10.0.0.1:5900, qualifier=null, endpoint=[10.0.0.1]:5900, alive=false, type=NONE] closed. Reason: Exception in Connection[id=3, /192.168.43.225:49045->/10.0.0.1:5900, qualifier=null, endpoint=[10.0.0.1]:5900, alive=true, type=NONE], thread=hz._hzInstance_1_dev.IO.thread-in-2
这表明您存在连接问题。您需要确保可以从 IP 地址 192.168.43.225 访问 10.0.0.1。
关于java - 如何在hazelcast配置中添加成员ip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58466879/