Hazelcast 在多节点 docker 环境中使用 TCPIP [英] Hazelcast in multinode docker environments with TCPIP

查看:58
本文介绍了Hazelcast 在多节点 docker 环境中使用 TCPIP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在努力解决以下问题:

I am currently struggling with the following problem:

我有一个 Java EE 应用程序,它应该能够在集群中运行(实际上确实如此).对于节点之间的数据交换,我使用 Hazelcast 3.3.3.由于我们的客户害怕 UDP,我们使用 TCP.所以我为每个节点配置了 3 个 hazelcast 参数:要使用的网络接口、端口和集群成员.在现实生活中(不是 docker 环境)一切正常.现在我想将我的 Java EE 服务器放入 docker 容器(每个节点一个),并通过 Hazelcast 链接它们.

I have a Java EE application that shall be able to run in a cluster (it actually does). For the data exchange between the nodes I use Hazelcast 3.3.3. Since our customers are afraid of UDP we use TCP. So I configure 3 hazelcast parameters per node: The network interface to use, the port and the members of the cluster. In real life (not a docker environment) everything works. Now I want to put my Java EE servers into docker containers (one per node) and also link them via Hazelcast.

我所做的是:

在运行 docker 容器的主机上,我创建了几个虚拟网络接口 (172.21.0.X).对于每个 docker 容器,我都提供了网络映射,如 -p 172.21.0.X:5190:5190(5190 是我用于 Hazelcast 的端口)

On the host machine running the docker containers I created several virtual network interfaces (172.21.0.X). for each docker container I gave network mappings like -p 172.21.0.X:5190:5190 (5190 is the port I use for Hazelcast)

在容器内的 Java EE 应用程序中,我将 hazelcast 配置为侦听接口 172.21.0.X,端口 5190 成员 172.21.0.X:5190,......现在的问题是:docker 会为每个 cointainer 分配一个内部 IP 号.事先我无法确定 docker 会分配哪个 IP 号码.它绝对不是我想使用的 IP (172.21.0.X).Hazelcast 启动并告诉我:找不到匹配的接口.当然不是.Hazelcast 将检查 docker 容器的 IP 接口,类似于 172.4.XX.这不适合我给 hazelcast 的配置(使用 172.21.X.X).

In my Java EE application within the container I configured hazelcast to listen to interface 172.21.0.X, port 5190 members 172.21.0.X:5190,...... The problem now is: docker will assign an internal IP number to each cointainer. In advance I cannot be sure which IP number docker will assign. It definitly is not the IP I would like to use (172.21.0.X). Hazelcast starts up and tells me: no matching interface found. Of course not. Hazelcast will check the IP interfaces of the docker container which is something like 172.4.XX. This does not fit to the config I gave to hazelcast (use 172.21.X.X).

目前似乎无法指定 docker 容器的内部 IP 号.我可以从正在运行的容器中查询它,但为时已晚,因为我需要在启动容器之前配置我的 Java EE 服务器.

So far it seems not to be possible to specify the internal IP number of a docker container. I could query it from a running container, but that is too late since I need to do the configuration of my Java EE server BEFORE I start the container.

对此有任何提示吗?是否可以使用 TCPIP 运行 Hazelcast?

Any hints on that? Is it possible to get the Hazelcast running with TCPIP?

推荐答案

此线程提供了答案和示例:https://groups.google.com/d/msg/orient-database/ehfKcInWZXs/wxs8xLUOGB8J

This thread provides an answer and an example: https://groups.google.com/d/msg/orient-database/ehfKcInWZXs/wxs8xLUOGB8J

基本上你在你的hazelcast文件中使用hazelcast变量,即

Basically you use hazelcast variables in your hazelcast file, i.e.

<property name="hazelcast.local.localAddress">${hazelcast.ip}</property>

然后,当您运行包含的 docker 时,您添加:

Then when you're running the docker contained you add:

-e IP=`ip route | awk '/default/ { print  $9 }'`

在 docker 容器中设置环境变量.然后在那里你做这样的事情:

Which sets an environment variable in the docker container. Then in there you do something like this:

CMD ["java", "-Dhazelcast.ip=${IP}", ...

因此,它采用 docker env 变量,并将其作为定义粉碎到 java 中,然后hazelcast 在运行时挑选并替换到它的配置文件中.

So it's taking the docker env variable, and smashing into java as a definition, which hazelcast then picks out and substitutes into it's config file at runtime.

这篇关于Hazelcast 在多节点 docker 环境中使用 TCPIP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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