在多个 ec2 节点上设置 zookeeper 集群时 0.0.0.0 是什么意思

What's the meaning of 0.0.0.0 when setting up zookeeper cluster on multiple ec2 nodes

我在为 hyperledger fabric 排序器设置 zookeeper 集群 时遇到了困难。通过 docker zookeeper 用户论坛[https://forums.docker.com/t/cannot-get-zookeeper-to-work-running-in-docker-using-swarm-mode/27109],它说我必须使用 0.0.0.0 作为主机服务器。

我不明白为什么 127.0.0.1 或本地主机不工作。此外,如果 0.0.0.0 用作子网掩码,则 255.255.255.0 或 0.0.0.1 也不起作用。

那么主机上服务器的 docker zookeeper 上的 0.0.0.0 是什么意思。

version: '2'
services:
    zk-1:
        extends:
            file: docker-compose-zkbase.yml # common setting for zookeepers
            service: zookeeper
        container_name: zk-1
        hostname: zk-1
        environment:
            - ZOO_MY_ID=1
            - ZOO_SERVERS=server.1=0.0.0.0:2888:3888 server.2=13.125.46.185:2888:3888 server.3=54.180.152.130:2888:3888

终于 0.0.0.0 对我有好处了,但我仍然不明白 docker zookeeper 的 0.0.0.0 的确切含义。

Finally 0.0.0.0 is good for me, but I still don't understand the exact meaning of 0.0.0.0 for docker zookeeper.

例如,如果它使用了本地主机网络 127.0.0.1,那么 zookeeper 将无法在端口 2888.

上的容器外部访问

这个 answer 很好地解释了 0.0.0.0 和 127.0.0.1 之间的区别。

What's the difference between 127.0.0.1 and 0.0.0.0?

  • 127.0.0.1 is the loopback address (also known as localhost).
  • 0.0.0.0 is a non-routable meta-address used to designate an invalid, >unknown or non applicable target (a no particular address placeholder).

In the context of a route entry, it usually means the default route.

In the context of servers, 0.0.0.0 means "all IPv4 addresses on >the >local machine". If a host has two ip addresses, 192.168.1.1 and >10.1.2.1, >and a server running on the host listens on 0.0.0.0, it will be >reachable >at both of those IPs.

这就是网络的全部内容。当你 "open" 一个套接字时,这意味着你创建了任何类型的 tcp/udp 服务器,你 bind 将套接字连接到本地 PC 上的某个接口。

这意味着您告诉您的服务器只接受来自指定接口的连接。例如,您可能有多个板载以太网卡,并且您希望您的 Web 服务器仅在特定的一个上可用。

要实现这一点,您 bind 您的服务器到该接口,指定 IP 地址。

同时出现了一些特殊的值,分别是:

0.0.0.0 - 表示您的服务可以在 所有 接口上访问。您可以从本地计算机和任何连接到任何以太网适配器的 PC 进行连接。

localhost/127.0.0.1 - 表示您在 本地 打开您的服务。这使您的服务仅适用于来自本地 PC 的连接。不接受外部连接。出于安全原因,此选项很有价值。它通常用于反向代理架构,当不安全的 (http) 连接在本地打开并且安全 (https) - 在 0.0.0.0nginx 绑定作为反向代理时主持人。