Hazelcast:连接到远程群集 [英] Hazelcast: connecting to remote cluster

查看:229
本文介绍了Hazelcast:连接到远程群集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个Hazelcast节点集群都在一个远程系统上运行(具有许多节点的单个物理系统)。我们想从外部客户端连接到这个集群 - 一个使用以下代码连接到Hazelcast的Java应用程序:

We have a cluster of Hazelcast nodes all running on one remote system (single physical system with many nodes). We would like to connect to this cluster from an external client - a Java application which uses code as below to connect to Hazelcast:

        ClientConfig clientConfig = new ClientConfig();
        clientConfig.addAddress(config.getHost() + ":" + config.getPort());

        client = HazelcastClient.newHazelcastClient(clientConfig);

其中,host是远程IP,端口是5701。

where, host is the IP of remote and port is 5701.

这仍然连接到本地主机(127.0.0.1)。我缺少什么?

This still connects to the local host (127.0.0.1). What am I missing?

编辑:

如果java客户端是只有在本地系统上运行的hazelcast应用程序,它无法连接并抛出异常: java.lang.IllegalStateException:无法获取初始分区!

If the java client is the only hazelcast app running on the local system, it fails to connect and throws the exception: java.lang.IllegalStateException: Cannot get initial partitions!

来自日志:


14:58:26.717 [main] INFO cmbpssHazelcastCacheClient - 创建
新的Hazelcast实例

14:58:26.717 [main] INFO c.m.b.p.s.s.HazelcastCacheClient - creating new Hazelcast instance

14:58:26.748 [main] INFO com.hazelcast.core.LifecycleService -
HazelcastClient [hz.client_0_dev] [3.2.1]正在开始

14:58:26.748 [main] INFO com.hazelcast.core.LifecycleService - HazelcastClient[hz.client_0_dev][3.2.1] is STARTING

14:58:27.029 [main] INFO com.hazelcast.core.LifecycleService -
HazelcastClient [hz.client_0_dev] [3.2.1]是已开始

14:58:27.029 [main] INFO com.hazelcast.core.LifecycleService - HazelcastClient[hz.client_0_dev][3.2.1] is STARTED

14:58:27.061 [hz.client_0_dev.cluster-listener] INFO
com.hazelcast.core.LifecycleService -
HazelcastClient [hz .client_0_dev] [3.2.1]是CLIENT_CONNECTED

14:58:27.061 [hz.client_0_dev.cluster-listener] INFO com.hazelcast.core.LifecycleService - HazelcastClient[hz.client_0_dev][3.2.1] is CLIENT_CONNECTED

14:58:27.061 [hz.client_0_dev.cluster-listener] INFO
chclient.spi.ClientClusterService -

14:58:27.061 [hz.client_0_dev.cluster-listener] INFO c.h.client.spi.ClientClusterService -

成员[5] {成员[127.0.0.1]:5701成员[127.0.0.1]:5702
成员[127.0.0.1]:5703成员[127.0.0.1]:5704成员
[127.0.0.1]:5705}

Members [5] { Member [127.0.0.1]:5701 Member [127.0.0.1]:5702 Member [127.0.0.1]:5703 Member [127.0.0.1]:5704 Member [127.0.0.1]:5705 }

14:58:47.278 [ main] ERROR chcspi.ClientPartitionService - 在获取集群分区表时出错

14:58:47.278 [main] ERROR c.h.c.spi.ClientPartitionService - Error while fetching cluster partition table!

com.hazelcast.spi.exception.RetryableIOException:
java。 util.concurrent.ExecutionException:
com.hazelcast.core.HazelcastException:java.net.ConnectException:
连接被拒绝:没有进一步的信息......引起:
java.util.concurrent。 ExecutionException:
com.hazelcast.core.HazelcastException:java.net.ConnectException:
连接被拒绝:没有进一步的信息

com.hazelcast.spi.exception.RetryableIOException: java.util.concurrent.ExecutionException: com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused: no further information ... Caused by: java.util.concurrent.ExecutionException: com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused: no further information

在java.util。 concurrent.FutureTask.report(未知来源)
~ [na:1.8.0_31]

at java.util.concurrent.FutureTask.report(Unknown Source) ~[na:1.8.0_31]

at java.util.concurrent.FutureTask.get(Unknown Source) 〜[na:1.8.0_31]

at java.util.concurrent.FutureTask.get(Unknown Source) ~[na:1.8.0_31]

at
com.hazelcast.client.connection.nio.ClientConnectionManagerImpl.getOrConnect(ClientConnectionManagerImpl.java:282)
~ [BRBASE-service-manager-1.0.0- jar-with-dependencies.jar:na]

at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl.getOrConnect(ClientConnectionManagerImpl.java:282) ~[BRBASE-service-manager-1.0.0-jar-with-dependencies.jar:na]

...省略了14个常见帧

... 14 common frames omitted

引起: com.hazelcast.core.HazelcastException:
java.net.ConnectException:连接被拒绝:没有更多信息

Caused by: com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused: no further information

at com.hazelcast.util.ExceptionUtil.rethrow( ExceptionUtil.java:45)
~ [BRBASE-service-manager-1.0.0-jar-with-dependencies.jar:na] ...

at com.hazelcast.util.ExceptionUtil.rethrow(ExceptionUtil.java:45) ~[BRBASE-service-manager-1.0.0-jar-with-dependencies.jar:na] ...


推荐答案

要连接到远程群集,请确保群集使用外部IP而不是 127.0.0.1 。在我们的例子中,我们有一个物理系统,有多个节点,启用了 tcp-ip 模式。 hazelcast.xml 具有以下配置:

To connect to the remote cluster, make sure the cluster uses the external IP and not 127.0.0.1. In our case we have a single physical system, with multiple nodes, with tcp-ip mode enabled. The hazelcast.xml has the configuration:

        <tcp-ip enabled="true">
            <!-- This should be external IP -->
            <interface>172.x.x.x</interface>
        </tcp-ip>

这篇关于Hazelcast:连接到远程群集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆