2016-07-19 125 views
0

我有一個非常簡單的Hazelcast客戶端,我正用它來連接集羣實例。看到我連接到本地主機(127.0.0.1)以及遠程服務器(xxx.xx.xx.x)。Hazelcast Connection拒絕地址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); 
} 

我已經打開端口5701-5710 CentOS的服務器(xxx.xx.xx.x)上,但我看到在日誌中以下內容:

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 

正如你所看到的,連接到本地主機(127.0.0.1)沒有問題,但無法連接到遠程服務器xxx.xx.xx.x.我已經啓用該端口通過CentOS的服務器上的防火牆5701

請特別注意下面一行訪問: 信息:[127.0.0.1]:5701 [開發] [3.5.5]無法連接到:xxx.xx.xx.x/xxx.xx.xx.x:5701。原因:SocketException [連接拒絕地址xxx.xx.xx.x/xxx.xx.xx.x:5701]

+0

您是試圖連接到已經運行的羣集或添加另一個成員到羣集?從代碼塊中,我看到你正在開始一個新的羣集。除非您使用完全相同的配置在xxx.xx.xx.x:5701上啓動節點,否則它將無法加入該節點以形成一個集羣,而是會啓動它自己的集羣。 –

+0

如果你只是打算啓動一個客戶端,然後利用'ClientConfig'&ClientNetworkConfig'並開始使用'HazelcastClient.newHazelcastClient(clientConfig)' –

回答

0

你的配置看起來不錯,但我認爲它是一個僞代碼,因爲沒有var -arg方法addMember。您可以多次調用addMember方法或使用setMembers方法添加幾個成員。

您沒有發佈第一個節點的配置。你需要有相同的配置 - 包括集羣名稱和密碼(如果你已經定義了它們)。

它也可能是一個防火牆問題 - 嘗試做telnet xxx.xxxx.xxx.xx 5701以查看連接是否可以成功打開。

0

馬特,

這就是你如何創建新的客戶端

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你使用,你剛開始成員在本地主機上。 您需要確保您在xxx.xx.xx.x:5701(默認端口)上運行Hazelcast成員。

謝謝