连接到服务器时发生hazelcast客户端异常

时间:2014-09-06 12:01:11

标签: java hazelcast

我正在尝试使用hazelcast v3.2.4(服务器和客户端上的相同版本)。服务器(就像我可以实现的简单实现一样)在服务器上运行。客户端尝试连接到远程服务器 - 服务器打印身份验证请求但我收到以下日志输出(包括异常) - 关于我可以做什么不同的任何想法(复制日志输出和配置文件)。我试图通过TCP / IP连接,我检查网络连接 - 我看不到阻止连接的任何东西。

堆栈中提到的代码行:

final ClientConfig config= new XmlClientConfigBuilder("config/hazelcast.xml").build();
HazelcastInstance hcast = HazelcastClient.newHazelcastClient(config);   //this is mentioned in stack trace

配置

<hazelcast-client xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-client-config-3.1.xsd"
           xmlns="http://www.hazelcast.com/schema/config"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <group>
        <name>dev</name> 
        <password>dev-pass</password> 
    </group>
    <management-center enabled="false">http://localhost:8080/mancenter</management-center>
    <network>
       <cluster-members>
            <address>xxx.xxx.xxx.xxx</address>
        </cluster-members>
        <smart-routing>true</smart-routing>
        <redo-operation>true</redo-operation>
        <connection-pool-size>30</connection-pool-size>

        <port auto-increment="true" port-count="100">5701</port>
        <outbound-ports>
            <ports>0</ports>
        </outbound-ports>
        <join>
            <multicast enabled="false">
                <multicast-group>224.2.2.3</multicast-group>
                <multicast-port>54327</multicast-port>
            </multicast>
            <tcp-ip enabled="false">
                <interface>xxx.xxx.xxx.xxx</interface>
            </tcp-ip>
            <aws enabled="false">
                <access-key>my-access-key</access-key>
                <secret-key>my-secret-key</secret-key>
                <region>us-west-1</region>
                <host-header>ec2.amazonaws.com</host-header>
                <security-group-name>hazelcast-sg</security-group-name>
                <tag-key>type</tag-key>
                <tag-value>hz-nodes</tag-value>
            </aws>
        </join>
        <interfaces enabled="false">
            <interface>10.10.1.*</interface>
        </interfaces>
        <ssl enabled="false" />
        <socket-interceptor enabled="false" />
        <symmetric-encryption enabled="false">
            <algorithm>PBEWithMD5AndDES</algorithm>
            <salt>thesalt</salt>
            <password>thepass</password>
            <iteration-count>19</iteration-count>
        </symmetric-encryption>
    </network>

记录输出

Sep 05, 2014 4:06:02 PM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_dev][3.2.4] is STARTING
Sep 05, 2014 4:06:02 PM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_dev][3.2.4] is STARTED
Sep 05, 2014 4:06:02 PM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_dev][3.2.4] is CLIENT_CONNECTED
Sep 05, 2014 4:06:02 PM com.hazelcast.client.spi.ClientClusterService
INFO: 

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

Sep 05, 2014 4:06:22 PM com.hazelcast.client.spi.ClientPartitionService
SEVERE: Error while fetching cluster partition table!
com.hazelcast.spi.exception.RetryableIOException: java.util.concurrent.ExecutionException: com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused: no further information
    at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl.getOrConnect(ClientConnectionManagerImpl.java:319)
    at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl.tryToConnect(ClientConnectionManagerImpl.java:261)
    at com.hazelcast.client.spi.impl.ClientInvocationServiceImpl.send(ClientInvocationServiceImpl.java:149)
    at com.hazelcast.client.spi.impl.ClientInvocationServiceImpl.invokeOnTarget(ClientInvocationServiceImpl.java:59)
    at com.hazelcast.client.spi.impl.ClientPartitionServiceImpl.getPartitionsFrom(ClientPartitionServiceImpl.java:105)
    at com.hazelcast.client.spi.impl.ClientPartitionServiceImpl.getInitialPartitions(ClientPartitionServiceImpl.java:94)
    at com.hazelcast.client.spi.impl.ClientPartitionServiceImpl.start(ClientPartitionServiceImpl.java:60)
    at com.hazelcast.client.HazelcastClient.start(HazelcastClient.java:223)
    at com.hazelcast.client.HazelcastClient.newHazelcastClient(HazelcastClient.java:186)
    at com.xxx.test.HCastClientAccessor.getHCastInstance(HCastClientAccessor.java:55)
    at com.xxx.test.HCastTest.<clinit>(HCastTest.java:12)
Caused by: java.util.concurrent.ExecutionException: com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused: no further information
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:262)
    at java.util.concurrent.FutureTask.get(FutureTask.java:119)
    at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl.getOrConnect(ClientConnectionManagerImpl.java:316)
    ... 10 more
Caused by: com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused: no further information
    at com.hazelcast.util.ExceptionUtil.rethrow(ExceptionUtil.java:45)
    at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl$ConnectionProcessor.call(ClientConnectionManagerImpl.java:384)
    at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl$ConnectionProcessor.call(ClientConnectionManagerImpl.java:332)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at com.hazelcast.util.executor.CompletableFutureTask.run(CompletableFutureTask.java:57)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
    at com.hazelcast.util.executor.PoolExecutorThreadFactory$ManagedThread.run(PoolExecutorThreadFactory.java:59)
Caused by: java.net.ConnectException: Connection refused: no further information
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:708)
    at sun.nio.ch.SocketAdaptor.connect(SocketAdaptor.java:115)
    at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl$ConnectionProcessor.call(ClientConnectionManagerImpl.java:365)
    ... 11 more

服务器输出

INFO: [127.0.0.1]:5701 [dev] [3.2.4] Accepting socket connection from /xxx.xxx.xxx.xxx:49705
Sep 05, 2014 4:05:57 PM com.hazelcast.nio.TcpIpConnectionManager
INFO: [127.0.0.1]:5701 [dev] [3.2.4] 5701 accepted socket connection from /xxx.xxx.xxx.xxx:49705
Sep 05, 2014 4:05:57 PM com.hazelcast.client.AuthenticationRequest
INFO: [127.0.0.1]:5701 [dev] [3.2.4] Received auth from Connection [/xxx.xxx.xxx.xxx:49705 -> null] live=true, client=true, type=JAVA_CLIENT, successfully authenticated
Sep 05, 2014 4:09:43 PM com.hazelcast.nio.TcpIpConnection
INFO: [127.0.0.1]:5701 [dev] [3.2.4] Connection [Address[xxx.xxx.xxx.xxx]:49705] lost. Reason: java.io.IOException[Connection reset by peer]
Sep 05, 2014 4:09:43 PM com.hazelcast.client.ClientEngine
INFO: [127.0.0.1]:5701 [dev] [3.2.4] Destroying ClientEndpoint{conn=Connection [/xxx.xxx.xxx.xxx:49705 -> Address[xxx.xxx.xxx.xxx]:49705] live=false, client=true, type=JAVA_CLIENT, uuid='70afcf60-96e0-444d-8981-3aa983530514', firstConnection=true, authenticated=true}
Sep 05, 2014 4:09:43 PM com.hazelcast.nio.ReadHandler
WARNING: [127.0.0.1]:5701 [dev] [3.2.4] hz._hzInstance_1_dev.IO.thread-in-0 Closing socket to endpoint Address[192.168.101.106]:49705, Cause:java.io.IOException: Connection reset by peer

更新

我切换到此客户端配置但我仍然在客户端获得异​​常。我复制了服务器和客户端输出 - 服务器收到连接请求,但随后在客户端,我看到了与上面提到的相同的错误“SEVERE:获取集群分区表时出错!” - 同样的跟踪如上。

新客户端配置

<hazelcast-client xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-client-config-3.2.4.xsd"
           xmlns="http://www.hazelcast.com/schema/config"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <group>
        <name>dev</name> 
        <password>dev-pass</password> 
    </group>
    <management-center enabled="false">http://localhost:8080/mancenter</management-center>
    <network>
       <cluster-members>
            <address>xxx.xxx.xxx.xxx</address>
        </cluster-members>
        <smart-routing>true</smart-routing>
        <redo-operation>true</redo-operation>
        <connection-timeout>60000</connection-timeout>
        <connection-attempt-limit>10</connection-attempt-limit>
        <connection-pool-size>30</connection-pool-size>
    </network>
        <executor-pool-size>40</executor-pool-size> <!-- added -->

</hazelcast-client>

服务器输出:

Sep 07, 2014 5:57:01 PM com.hazelcast.nio.SocketAcceptor
INFO: [127.0.0.1]:5701 [dev] [3.2.4] Accepting socket connection from /xxx.xxx.xxx.xxx:58521
Sep 07, 2014 5:57:01 PM com.hazelcast.nio.TcpIpConnectionManager
INFO: [127.0.0.1]:5701 [dev] [3.2.4] 5701 accepted socket connection from /xxx.xxx.xxx.xxx:58521
Sep 07, 2014 5:57:03 PM com.hazelcast.client.AuthenticationRequest
INFO: [127.0.0.1]:5701 [dev] [3.2.4] Received auth from Connection [/xxx.xxx.xxx.xxx:58521 -> null] live=true, client=true, type=JAVA_CLIENT, successfully authenticated

客户端输出

Sep 07, 2014 5:58:04 PM com.hazelcast.client.spi.ClientPartitionService
SEVERE: Error while fetching cluster partition table!
com.hazelcast.spi.exception.RetryableIOException: java.util.concurrent.ExecutionException: com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused: no further information
    at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl.getOrConnect(ClientConnectionManagerImpl.java:319)
    at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl.tryToConnect(ClientConnectionManagerImpl.java:261)
    at com.hazelcast.client.spi.impl.ClientInvocationServiceImpl.send(ClientInvocationServiceImpl.java:149)
    at com.hazelcast.client.spi.impl.ClientInvocationServiceImpl.invokeOnTarget(ClientInvocationServiceImpl.java:59)
    at com.hazelcast.client.spi.impl.ClientPartitionServiceImpl.getPartitionsFrom(ClientPartitionServiceImpl.java:105)
    at com.hazelcast.client.spi.impl.ClientPartitionServiceImpl.getInitialPartitions(ClientPartitionServiceImpl.java:94)
    at com.hazelcast.client.spi.impl.ClientPartitionServiceImpl.start(ClientPartitionServiceImpl.java:60)
    at com.hazelcast.client.HazelcastClient.start(HazelcastClient.java:223)
    at com.hazelcast.client.HazelcastClient.newHazelcastClient(HazelcastClient.java:186)

更新

我为客户端和服务器尝试了这个,我得到了与上面相同的例外 - 我做错了什么:

客户端         ClientConfig clientConfig = new ClientConfig()。addAddress(“xxx.xxx.xxx.xxx”);           HazelcastInstance客户端= HazelcastClient.newHazelcastClient(clientConfig);

服务器

HazelcastInstance hcast = Hazelcast.newHazelcastInstance();

更新 简而言之,确保服务器和客户端的配置都正确(不要将标签从一个集合混合到另一个集合)。对于服务器,请确保hazelcast服务器正在侦听外部IP地址(而不是环回地址),没有阻止连接的防火墙设置(在客户端,服务器或中间)。感谢Peter - 我回到使用hazelcast并享受使用此工具的经验。强烈推荐!

3 个答案:

答案 0 :(得分:1)

除了客户端的XML问题外,我没有看到任何明显的错误。

我通常采用以下方法;尝试在同一个JVM上运行服务器和客户端,然后至少你确保没有问题。在我开始浪费网络问题之前,我总是先验证基础知识。

验证完毕后,请查看以下部分。我的直觉是防火墙有一些东西。第一部分包含有关iptables的配置信息,第二部分包含第二部分用于测试网络连接。

\ {小节的iptables} 如果您正在使用iptables,则可以添加以下规则以允许来自端口33000-31000的出站流量: \ {开始} lstlisting iptables -A OUTPUT -p TCP --dport 33000:31000 -m state --state NEW -j ACCEPT \ {端} lstlisting 并控制从任何地址到端口5701的传入流量: \ {开始} lstlisting iptables -A INPUT -p tcp -d 0/0 -s 0/0 --dport 5701 -j ACCEPT \ {端} lstlisting 并允许传入的多播流量: \ {开始} lstlisting iptables -A INPUT -m pkttype --pkt-type multicast -j ACCEPT \ {端} lstlisting

\ section {连接测试} 如果由于计算机无法加入群集而遇到麻烦,则可以检查两台计算机之间的网络连接。您可以使用名为iperf的工具。在一台机器上执行: \ {开始} lstlisting iperf -s -p 5701 \ {端} lstlisting 这意味着您正在侦听端口5701。

在另一台计算机上执行以下命令: \ {开始} lstlisting iperf -c 192.168.1.107 -d -p 5701 \ {端} lstlisting 在哪里用你的第一台机器的ip地址替换'192.168.1.107'。如果您运行该命令并得到如下输出:

\开始{lstlisting}

服务器侦听TCP端口5701

TCP窗口大小:85.3 KByte(默认值)


客户端连接到192.168.1.107,TCP端口5701

TCP窗口大小:59.4 KByte(默认值)

[5]本地192.168.1.105端口40524与192.168.1.107端口5701连接 [4]本地192.168.1.105端口5701与192.168.1.107端口33641连接 [ID]间隔传输带宽 [4] 0.0-10.2秒55.8 MBytes 45.7 Mbits / sec [5] 0.0-10.3秒6.25 MBytes 5.07 Mbits / sec \ {端} lstlisting 你知道这两台机器可以相互连接。但是,如果你看到这样的事情: \ {开始} lstlisting 服务器侦听TCP端口5701

TCP窗口大小:85.3 KByte(默认值)

连接失败:无主机路由 \ {端} lstlisting 然后,您知道手上可能存在网络连接问题。

答案 1 :(得分:0)

您提到的错误似乎来自以下(ClientPartitionServiceImpl),它调用GetPartitionRequest并传入地址。你可以检查你传入的地址(可能需要你使用你正在使用的版本构建hazelcast)或者更详细地检查正在使用的接口/配置文件。

public ClientPartitionServiceImpl(HazelcastClient client) {
    this.client = client;
}

public void start() {
    getInitialPartitions();
    client.getClientExecutionService().scheduleWithFixedDelay(new RefreshTask(), INITIAL_DELAY, PERIOD, TimeUnit.SECONDS);
}

public void refreshPartitions() {
    try {
        client.getClientExecutionService().execute(new RefreshTask());
    } catch (RejectedExecutionException ignored) {
        EmptyStatement.ignore(ignored);
    }
}

private class RefreshTask implements Runnable {
    public void run() {
        if (updating.compareAndSet(false, true)) {
            try {
                final ClientClusterService clusterService = client.getClientClusterService();
                final Address master = clusterService.getMasterAddress();
                final PartitionsResponse response = getPartitionsFrom(master);
                if (response != null) {
                    processPartitionResponse(response);
                }
            } catch (HazelcastInstanceNotActiveException ignored) {
                EmptyStatement.ignore(ignored);
            } finally {
                updating.set(false);
            }
        }
    }
}

private void getInitialPartitions() {
    final ClientClusterService clusterService = client.getClientClusterService();
    final Collection<MemberImpl> memberList = clusterService.getMemberList();
    for (MemberImpl member : memberList) {
        final Address target = member.getAddress();
        PartitionsResponse response = getPartitionsFrom(target);
        if (response != null) {
            processPartitionResponse(response);
            return;
        }
    }
    throw new IllegalStateException("Cannot get initial partitions!");
}

private PartitionsResponse getPartitionsFrom(Address address) {
    try {
        final Future<PartitionsResponse> future =
                client.getInvocationService().invokeOnTarget(new GetPartitionsRequest(), address);
        return client.getSerializationService().toObject(future.get());
    } catch (Exception e) {
        LOGGER.severe("Error while fetching cluster partition table!", e);
    }
    return null;
}

<强> GetPartitionsRequest

public final class GetPartitionsRequest extends CallableClientRequest implements Portable, RetryableRequest {

    @Override
    public Object call() throws Exception {
        InternalPartitionService service = getService();
        service.firstArrangement();
        ClusterService clusterService = getClientEngine().getClusterService();
        Collection<MemberImpl> memberList = clusterService.getMemberList();
        Address[] addresses = new Address[memberList.size()];
        Map<Address, Integer> addressMap = new HashMap<Address, Integer>(memberList.size());
        int k = 0;
        for (MemberImpl member : memberList) {
            Address address = member.getAddress();
            addresses[k] = address;
            addressMap.put(address, k);
            k++;
        }
        InternalPartition[] partitions = service.getPartitions();
        int[] indexes = new int[partitions.length];
        for (int i = 0; i < indexes.length; i++) {
            Address owner = partitions[i].getOwnerOrNull();
            int index = -1;
            if (owner != null) {
                final Integer idx = addressMap.get(owner);
                if (idx != null) {
                    index = idx;
                }

            }
            indexes[i] = index;
        }
        return new PartitionsResponse(addresses, indexes);
    }

    @Override
    public String getServiceName() {
        return InternalPartitionService.SERVICE_NAME;
    }

    @Override
    public int getFactoryId() {
        return ClientPortableHook.ID;
    }

    @Override
    public int getClassId() {
        return ClientPortableHook.GET_PARTITIONS;
    }

    @Override
    public Permission getRequiredPermission() {
        return null;
    }
}

答案 2 :(得分:0)

只是会添加一些情况,我在获取集群分区表时遇到了#34;错误&#34;

  • for ipv6:check http://docs.hazelcast.org/docs/latest/manual/html/ipv6.html页面。如果您使用ipv6,请不要设置&#34; hazelcast.prefer.ipv4.stack&#34;在服务器上为true
  • 对于ipv6:出于某些原因,如果你没有设置&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;对于ipv4,它适用于&#34; enabled = false&#34;。我使用一台机器而不需要集群,但需要连接客户端。 Magic:客户端可以使用&#34; tcp-ip enabled = false&#34;连接到服务器。如果使用ipv4,但如果使用ipv6则不能。