gpt4 book ai didi

docker - 在 DCOS/Marathon 和 docker 上发现 Hazelcast TCP/IP

转载 作者:行者123 更新时间:2023-12-02 18:56:12 25 4
gpt4 key购买 nike

我在马拉松上部署了一个 dockerized dropwizard 服务。我使用 Hazelcast 作为分布式缓存,我开始使用它是我的 dropwizard 服务的一部分。我设置了一个约束来确保每个容器都在唯一的主机上启动。

   "constraints": [
[
"hostname",
"UNIQUE"
]
],

我在我的 docker 容器上暴露了 2 个端口, 10012为我的服务和 10013榛树。我正在使用 Zookeeper 进行 Dropwizard 服务发现。因此,当我启动我的 Hazelcast 实例时,我可以访问运行我的 docker 容器的所有机器的主机名,并按如下方式添加它们。
TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
// finder is a handle to a service discovery service and the following gets me all the hosts on which my docker containers will run.
List<ServiceNode<ShardInfo>> nodes = finder.getAllNodes();
nodes.stream()
.peek(serviceNode -> log.info("Adding " + serviceNode.representation() + " to hazelcast."))
.map(serviceNode -> serviceNode.getHost())
.forEach(host -> tcpIpConfig.addMember(host));
tcpIpConfig.setRequiredMember(null).setEnabled(true);

现在问题:
如果我在 Marathon 上部署时使用网络类型作为 BRIDGE,那么我不知道 docker 容器主机,因此我的 2 个 docker 容器彼此不认识。它看起来像这样:
ip-10-200-2-219.ap-southeast-1.compute.internal (docker host) - 172.12.1.18 (docker container ip)

ip-10-200-2-220.ap-southeast-1.compute.internal (docker host) - 172.12.1.20 (docker container ip)

从 zookeeper 我得到 docker 主机 IP,但没有 docker 容器 IP。

如果我使用网络类型作为主机,那么一切正常,但问题是我必须确保我的 docker 容器运行的端口始终具有可用的端口 1001 和 10013。 (使用 BRIDGE,docker 容器端口绑定(bind)到随机端口)。

最佳答案

分析:

这两个 docker 容器位于它们自己的网络中,本地化为从站。他们需要使用从机的公共(public) IP 和 5701 的桥接端口(或您使用的任何 hazelcast 端口)来识别彼此。

解决方案

在 TCP/IP 配置中,在启动实例时设置公共(public)地址和端口。所有实例都将执行此操作,它们将使用马拉松从 IP 和用于它的随机端口相互通信。

使用 marathon 提供的并在容器内可用的 HOST 和 PORT_5701 变量来执行此操作。

Config hzConfig = new Config();
hzConfig.getNetworkConfig().setPublicAddress(
String.format("%s:%s",
System.getenv("HOST"),
System.getenv("PORT_5701")));

引用 hazelcast network config documentation了解更多关于公共(public)地址选项的信息。

关于docker - 在 DCOS/Marathon 和 docker 上发现 Hazelcast TCP/IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33845653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com