【问题标题】:Hazelcast Connection Refused to Address xHazelcast 连接拒绝地址 x
【发布时间】:2016-07-19 04:42:24
【问题描述】:

我有一个非常简单的 Hazelcast 客户端,用于连接到集群实例。看到我正在连接到 localhost (127.0.0.1) 以及远程服务器 (xxx.xx.xx.x)。

public HazelcastCacheClient(String mapName, Map<K,V> cacheMap) {

    Config cfg = new Config();
    NetworkConfig networkConfig = cfg.getNetworkConfig();
    networkConfig.setPort(5701);
    networkConfig.setPortCount(1);

    JoinConfig joinConfig = networkConfig.getJoin();
    joinConfig.getMulticastConfig().setEnabled(false);
    joinConfig.getAwsConfig().setEnabled(false);
    joinConfig.getTcpIpConfig()
                    .addMember("127.0.0.1, xxx.xx.xx.x").setEnabled(true);

    HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);

    Map<String, Integer> map = instance.getMap(mapName);
}

我在 CentOS 服务器 (xxx.xx.xx.x) 上打开了 5701-5710 端口,但在日志中看到以下内容:

com.hazelcast.instance.DefaultAddressPicker
INFO: [LOCAL] [dev] [3.5.5] Resolving domain name 'xxx.xx.xx.x' to address(es): [xxx.xx.xx.x]
com.hazelcast.instance.DefaultAddressPicker
INFO: [LOCAL] [dev] [3.5.5] Interfaces is disabled, trying to pick one address from TCP-IP config addresses: [xxx.xx.xx.x/xxx.xx.xx.x, 127.0.0.1]
com.hazelcast.instance.DefaultAddressPicker
INFO: [LOCAL] [dev] [3.5.5] Picked Address[127.0.0.1]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
com.hazelcast.spi.OperationService
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Backpressure is disabled
com.hazelcast.spi.impl.operationexecutor.classic.ClassicOperationExecutor
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Starting with 4 generic operation threads and 8 partition operation threads.
com.hazelcast.system
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Hazelcast 3.5.5 (20160122 - 6805b8e) starting at Address[127.0.0.1]:5701
com.hazelcast.system
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
 com.hazelcast.instance.Node
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Creating TcpIpJoiner
com.hazelcast.core.LifecycleService
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Address[127.0.0.1]:5701 is STARTING
com.hazelcast.nio.tcp.SocketConnector
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Connecting to xxx.xx.xx.x/xxx.xx.xx.x:5701, timeout: 0, bind-any: true
com.hazelcast.nio.tcp.SocketConnector
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Connecting to xxx.xx.xx.x/xxx.xx.xx.x, timeout: 0, bind-any: true
com.hazelcast.nio.tcp.SocketConnector
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Connecting to /127.0.0.1:5703, timeout: 0, bind-any: true
com.hazelcast.nio.tcp.SocketConnector
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Connecting to /127.0.0.1:5702, timeout: 0, bind-any: true
com.hazelcast.nio.tcp.SocketConnector
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Connecting to xxx.xx.xx.x/xxx.xx.xx.x:5703, timeout: 0, bind-any: true
com.hazelcast.nio.tcp.SocketConnector
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Could not connect to: /127.0.0.1:5702. Reason: SocketException[Connection refused to address /127.0.0.1:5702]
com.hazelcast.nio.tcp.SocketConnector
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Could not connect to: /127.0.0.1:5703. Reason: SocketException[Connection refused to address /127.0.0.1:5703]
com.hazelcast.cluster.impl.TcpIpJoiner
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Address[127.0.0.1]:5702 is added to the blacklist.
com.hazelcast.cluster.impl.TcpIpJoiner
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Address[127.0.0.1]:5703 is added to the blacklist.
com.hazelcast.nio.tcp.SocketConnector
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Could not connect to: xxx.xx.xx.x/xxx.xx.xx.x:5701. Reason: SocketException[Connection refused to address xxx.xx.xx.x/xxx.xx.xx.x:5701]
com.hazelcast.cluster.impl.TcpIpJoiner
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Address[xxx.xx.xx.x]:5701 is added to the blacklist.
com.hazelcast.cluster.impl.TcpIpJoiner
INFO: [127.0.0.1]:5701 [dev] [3.5.5] 


Members [1] {
    Member [127.0.0.1]:5701 this
}

Jul 19, 2016 12:32:45 AM com.hazelcast.core.LifecycleService
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Address[127.0.0.1]:5701 is STARTED

如您所见,连接到localhost(127.0.0.1)没有问题,但是无法连接到远程服务器xxx.xx.xx.x。我已在 CentOS 服务器上为 5701 启用了可通过防火墙访问的端口。

请特别注意以下行: 信息:[127.0.0.1]:5701 [dev] [3.5.5] 无法连接到:xxx.xx.xx.x/xxx.xx.xx.x:5701。原因:SocketException[连接拒绝地址xxx.xx.xx.x/xxx.xx.xx.x:5701]

【问题讨论】:

  • 您是在尝试连接到已经运行的集群还是在集群中添加其他成员?从代码块中,我看到您正在启动一个新的集群本身。除非您使用完全相同的配置在 xxx.xx.xx.x:5701 启动节点,否则它将无法加入该节点以形成集群,而是会启动自己的集群。
  • 如果你只是打算启动一个客户端然后使用ClientConfig & ClientNetworkConfig 并开始使用HazelcastClient.newHazelcastClient(clientConfig)

标签: java cluster-computing hazelcast


【解决方案1】:

您的配置看起来不错,但我认为它是伪代码,因为没有 var-arg 方法 addMember。您可以多次调用addMember 方法或使用setMembers 方法添加几个成员。

您没有发布第一个节点的配置。您需要具有相同的配置 - 包括集群名称和密码(如果您已定义它们)。

也可能是防火墙问题 - 试试telnet xxx.xxxx.xxx.xx 5701 看看是否可以成功打开连接。

【讨论】:

    【解决方案2】:

    马特,

    这是创建新客户端的方法

    import com.hazelcast.client.HazelcastClient;
    import com.hazelcast.client.config.ClientConfig;
    
    public void HazelcastCacheClient(String mapName, Map cacheMap) {
    
        ClientConfig cfg = new ClientConfig();
        cfg.getNetworkConfig().addAddress("xxx.xx.xx.x");
    
        HazelcastInstance instance = HazelcastClient.newHazelcastClient(cfg);
    
        cacheMap = instance.getMap(mapName);
    
    }
    

    使用您使用的 API,您只需在 localhost 上启动成员。 您需要确保在 xxx.xx.xx.x:5701(默认端口)上运行 Hazelcast 成员。

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2013-04-14
      • 2016-01-16
      • 1970-01-01
      • 2015-07-27
      • 2015-12-25
      • 1970-01-01
      相关资源
      最近更新 更多