当前位置: 首页 > 知识库问答 >
问题:

连接到服务器时出现hazelcast客户端异常

解翰采
2023-03-14

我正在尝试使用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

更新:

我切换到这个客户端配置,但客户端仍然出现异常。我复制了服务器和客户端输出——服务器接收到连接请求,但在客户端,我看到了与上面提到的相同的错误“严重:获取集群分区表时出错!”-和上面一样的痕迹。

新客户端配置

<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)

使现代化

我在客户端和服务器上尝试了这一点,但得到了与上面相同的异常——我做错了什么:

Client ClientConfig ClientConfig=new ClientConfig()。地址(“xxx.xxx.xxx.xxx”);HazelcastInstance客户端=HazelcastClient。newHazelcastClient(客户端配置);

服务器

HazelcastInstance hcast = Hazelcast.newHazelcastInstance();

简而言之,请确保服务器和客户端的配置都正确(不要将标签从一组混用到另一组)。对于服务器,确保hazelcast服务器正在侦听外部IP地址(而不是环回地址),并且没有防火墙设置阻止连接(在客户端、服务器或两者之间)。多亏了彼得,我又开始使用hazelcast了,并享受了使用该工具的体验。强烈推荐!

共有3个答案

梅跃
2023-03-14

我将添加一些情况,我在“获取集群分区表时出错”

  • 对于ipv6:检查http://docs.hazelcast.org/docs/latest/manual/html/ipv6.html页如果使用ipv6,请不要忘记在服务器上将“hazelcast.preference.ipv4.stack”设置为true
  • 对于ipv6:由于某些原因,如果不为ipv4设置“”,客户端的所有功能仍然无法正常工作,它将与“enabled=false”一起工作。我只使用一台机器,不需要集群,但需要连接客户端。神奇之处:如果使用ipv4,客户端可以使用“tcp ip enabled=false”连接到服务器,但如果使用ipv6,则无法连接
解河
2023-03-14

您提到的错误似乎来自以下(ClientPartionServiceImpl),它在其中调用GetPartionRequest并传入地址。您可以检查作为地址传入的内容(可能需要使用您正在使用的版本构建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;
    }
}
臧兴学
2023-03-14

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

我通常的做法是:;尝试在同一个JVM上运行服务器和客户端,那么至少您已经确保没有问题
我总是先验证一下基础知识,然后再浪费一秒钟时间解决网络问题。

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

iptables
如果您使用的是iptables,则可以添加以下规则以允许来自端口33000-31000的出站流量:

iptables -A OUTPUT -p TCP --dport 33000:31000 -m state --state NEW -j ACCEPT

控制从任何地址到端口5701的传入流量:

iptables -A INPUT -p tcp -d 0/0 -s 0/0 --dport 5701 -j ACCEPT

以及允许传入的多播流量:

iptables -A INPUT -m pkttype --pkt-type multicast -j ACCEPT

连接测试
如果由于计算机无法加入群集而出现问题,可以检查这两台计算机之间的网络连接。你可以使用一个叫做iperf的工具来实现这一点
在一台机器上执行:

iperf -s -p 5701

这意味着您正在5701端口监听。

在另一台机器上执行以下命令:

iperf -c 192.168.1.107 -d -p 5701

在这里,您将192.168.1.107替换为第一台机器的ip地址。
如果您运行该命令并获得如下输出:

------------------------------------------------------------
Server listening on TCP port 5701
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
------------------------------------------------------------
Client connecting to 192.168.1.107, TCP port 5701
TCP window size: 59.4 KByte (default)
------------------------------------------------------------
[  5] local 192.168.1.105 port 40524 connected with 192.168.1.107 port 5701
[  4] local 192.168.1.105 port 5701 connected with 192.168.1.107 port 33641
[ ID] Interval       Transfer     Bandwidth
[  4]  0.0-10.2 sec  55.8 MBytes  45.7 Mbits/sec
[  5]  0.0-10.3 sec  6.25 MBytes  5.07 Mbits/sec

您知道这两台机器可以相互连接。
但是,如果您看到这样的内容:

Server listening on TCP port 5701
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
connect failed: No route to host.  

然后你就知道你手上可能有网络连接问题。

 类似资料:
  • 关于:Hazelcast远程缓存服务器-客户端Spring Boot 我也有同样的问题,但对于hazelcast 5.1和java 17: 和用法: 国家类是: 与活动服务器和客户端的通话是正常的,但当我关闭服务器时,我得到了: 没有找到到集群的连接 第5版中有更改或我的配置错误? 谢谢

  • 我试图在我的本地机器上设置Hazelcast服务器和客户端。我还试图通过scala客户端连接到本地Hazelcast服务器。 对于我在下面代码中使用的服务器, Hazelcast的客户是, 在我build.sbt, 我在错误之下陷入依赖问题。 我查阅了hazelcast的文档。我找不到任何好的hazelcast scala示例来理解设置并开始使用。如果有人能帮助解决这个问题,或者分享非常好的sca

  • 我在集群中有一个Hazelcast客户端和两个Hazelcast服务器,每个服务器包含单个复制的Map。 我给客户端2个hazelcast服务器节点,以便从replicatedMap中读取。 我是否可以将连接优先级赋予一台服务器,并在连接处于活动状态时从该服务器读取数据? 为了澄清,假设有MasterServer、SlaveServer和Client。 如果复制地图操作之间存在连接,我们是否可以强

  • 我在Amazon EC2上设置了一个2节点hazelcast集群。在其中一个节点上,我有一个连接到集群并运行原子长计数器增量的客户端程序 如何找出客户端连接并运行增量AndGet操作的Hazelcast服务器节点? 谢谢

  • 当我尝试使用套接字将物理设备连接到服务器时,我遇到了一个问题。在服务器端,它似乎不接受任何连接,而在客户端,套接字超时。你知道为什么会这样吗? 我在下面提供我的代码 服务器代码: 客户端: 11-16 23:32:11.016:W/系统。错误(24213):java.net。ConnectException:无法连接到/192.168.1.116(端口9090):连接失败:ETIMEDOUT(连接

  • 我有一个示例Spring启动应用程序来运行图形QL服务器,具有作为客户端,我的pom有以下依赖项: 当我尝试从客户端连接时,出现以下错误: 狩猎决议好心建议。 我还有几个问题: 我应该使用SimpleGraphQLHttpServlet将请求路由到endpoint吗 我正在React UI上使用apollo client,那么它是强制使用apollo server还是spring boot可以工作