如何为不同的Zookeeper Docker容器设置不同的管理员端口?

huangapple go评论72阅读模式
英文:

How to set different admin ports for different Zookeeper Docker containers?

问题

以下是已翻译好的内容:

我正在在单个系统上创建一个由三个Zookeeper Docker容器组成的集群。
第一个Zookeeper Docker的管理服务器正在使用端口8080上运行,因此对于其他两个Zookeeper容器,它会出现“无法绑定到/0.0.0.0:8080,地址已在使用中”的错误。我正在使用Zookeeper版本“zookeeper:3.5.6”。

现在我的问题是如何为Zookeeper管理服务器分配不同于8080的不同管理端口?

我尝试了不同的选项来设置不同的端口,但都没有起作用。

1) - zookeeper.admin.serverPort=8078
2) - ZOO_CFG_EXTRA="admin.serverPort=8077"
3) - admin.serverPort=8078

以下是一个Zookeeper的Docker Compose配置。

 zk2:
  hostname: ${LOCAL_HOST}
  image: ${ZOOKEEPER_IMAGE}
  environment:
    - u=${USER}:${USER}
    - JVM_OPTS=-Xmx12g -Xms12g -XX:MaxPermSize=2048m
    - ZOO_MY_ID=${ZOO_MY_ID2}
    - ZOO_SERVERS=${ZOO_SERVER_1} ${ZOO_SERVER_2} ${ZOO_SERVER_3}
    - ZOO_ADMINSERVER_ENABLED=true
    - ZOO_STANDALONE_ENABLED=false
    - zookeeper.admin.serverPort=8078
  volumes:
    - ${VOLUMES_PATH}/zk2/data:/data
    - ${VOLUMES_PATH}/zk2/logs:/datalog
  network_mode: "host"
  ports:
    - ${ZOOK_CL_PORT2}:${ZOOK_CL_PORT2}
    - ${ZOOK_SR_PORT2}:${ZOOK_SR_PORT2}
    - ${ZOOK_EL_PORT2}:${ZOOK_EL_PORT2}
    - ${ZOOK_ADM_PORT2}:8078"

有人可以建议我如何实现这一点吗?

英文:

I am creating a cluster of three zookeeper docker containers on a Single system.
Admin server of the first zookeeper docker is up using port 8080, so for other two Zoo containers, it is giving "Failed to bind to /0.0.0.0:8080, address in use". I am using zoo version as "zookeeper:3.5.6".

Now my question is how to assign different admin port to the zookeeper admin server other than 8080?

I have tried different options to set the admin server on different ports, but nothing worked.

1) - zookeeper.admin.serverPort=8078
2) - ZOO_CFG_EXTRA="admin.serverPort=8077"
3) - admin.serverPort=8078

Below is the docker compose for one zookeeper.

 zk2:
  hostname: ${LOCAL_HOST}
  image: ${ZOOKEEPER_IMAGE}
  environment:
    - u=${USER}:${USER}
    - JVM_OPTS=-Xmx12g -Xms12g -XX:MaxPermSize=2048m
    - ZOO_MY_ID=${ZOO_MY_ID2}
    - ZOO_SERVERS=${ZOO_SERVER_1} ${ZOO_SERVER_2} ${ZOO_SERVER_3}
    - ZOO_ADMINSERVER_ENABLED=true
    - ZOO_STANDALONE_ENABLED=false
    - zookeeper.admin.serverPort=8078
  volumes:
    - ${VOLUMES_PATH}/zk2/data:/data
    - ${VOLUMES_PATH}/zk2/logs:/datalog
  network_mode: "host"
  ports:
    - ${ZOOK_CL_PORT2}:${ZOOK_CL_PORT2}
    - ${ZOOK_SR_PORT2}:${ZOOK_SR_PORT2}
    - ${ZOOK_EL_PORT2}:${ZOOK_EL_PORT2}
    - ${ZOOK_ADM_PORT2}:8078"

Can anyone suggest me how to do that?

答案1

得分: 1

考虑你发布的 Docker Compose 文件,有问题的部分是 network_mode: "host"。引用官方文档:

https://docs.docker.com/network/host/

> 如果你为一个容器使用主机网络模式,该容器的网络堆栈与 Docker 主机(容器与主机共享网络命名空间)不隔离,并且该容器不会被分配独立的 IP 地址。例如,如果你运行一个绑定到 80 端口的容器,并且使用主机网络,那么容器的应用将在主机的 IP 地址上的 80 端口上可用。

因此,实际上,你启动的这三个 Zookeeper 集群成员都在竞争分配 8080 端口,忽略了后面你定义的端口绑定。

英文:

Considering the docker compose file you posted, the problematic element is the
network_mode: "host". Citing the official documentation:

https://docs.docker.com/network/host/

> If you use the host network mode for a container, that container’s network stack is not isolated from the Docker host (the container shares the host’s networking namespace), and the container does not get its own IP-address allocated. For instance, if you run a container which binds to port 80 and you use host networking, the container’s application is available on port 80 on the host’s IP address.

So, in fact, every one of the three zookeeper quorum members that you fire up is competing on allocating the 8080 port, ignoring the port binding you defined later on.

答案2

得分: 0

Admin服务器端口8080仅在容器内部可用,直到您通过端口映射将其暴露出来。如果要将该端口暴露给Docker主机,您应该为您的两个Zookeeper容器分配不同的端口映射。

在这种情况下,您正在尝试更改容器的内部管理员服务器端口,这是不必要的。您可以参考以下Docker Compose文件的示例 -

version: '3.4'

services:
  zoo1:
    image: 'zookeeper'
    ports:
      - '2181:2181'
      - '8080:8080'
    environment:
      ZOO_SERVER_ID: 1
      ALLOW_ANONYMOUS_LOGIN: "yes"
      ZOO_ADMINSERVER_ENABLED: "true"
      ZOO_SERVERS: "zoo1:2888:3888,zoo2:2888:3888"
  zoo2:
    image: 'zookeeper'
    ports:
      - '3181:2181'
      - '8078:8080'
    environment:
      ZOO_SERVER_ID: 2
      ALLOW_ANONYMOUS_LOGIN: "yes"
      ZOO_ADMINSERVER_ENABLED: "true"
      ZOO_SERVERS: "zoo1:2888:3888,zoo2:2888:3888"

zoo1 - 端口8080在容器内部可用,我们将相同的端口暴露给Docker主机。
zoo2 - 端口8080在容器内部可用,但我们将不同的端口(8078)暴露给Docker主机。

现在,您可以通过端口8080访问第一个容器的界面,并通过端口8078访问第二个容器的界面,从您的Docker主机。

英文:

Admin server port 8080 is available only inside the container until you expose it with port mappings. If you want to expose the port to docker host you should assign different port mappings to both of your zookeeper container.

In this case, you are trying to change the container's internal admin server port which is not required. You can take the example of following docker-compose file -

version: '3.4'

services:
  zoo1:
    image: 'zookeeper'
    ports:
      - '2181:2181'
      - '8080:8080'
    environment:
      ZOO_SERVER_ID: 1
      ALLOW_ANONYMOUS_LOGIN: "yes"
      ZOO_ADMINSERVER_ENABLED: "true"
      ZOO_SERVERS: "zoo1:2888:3888,zoo2:2888:3888"
  zoo2:
    image: 'zookeeper'
    ports:
      - '3181:2181'
      - '8078:8080'
    environment:
      ZOO_SERVER_ID: 2
      ALLOW_ANONYMOUS_LOGIN: "yes"
      ZOO_ADMINSERVER_ENABLED: "true"
      ZOO_SERVERS: "zoo1:2888:3888,zoo2:2888:3888"

zoo1 - Port 8080 is available inside the container and we are exposing the same port to the docker host.
zoo2 - Port 8080 is available inside the container but we are exposing different port(8078) to the docker host.

Now you can access the interface using port 8080 for first container and 8078 for the second container from your docker host.

答案3

得分: 0

容易的方法是这样的:

ZOO_ADMIN_SERVER_PORT_NUMBER:9999

> ZOO_ADMIN_SERVER_PORT_NUMBER:管理服务器端口。默认值:8080

bitnami/zookeeper 参考链接

英文:

Easy way to do this

ZOO_ADMIN_SERVER_PORT_NUMBER:9999 

> ZOO_ADMIN_SERVER_PORT_NUMBER: Admin server port. Default: 8080

bitnami/zookeeper Reference URL

huangapple
  • 本文由 发表于 2020年10月8日 20:06:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/64262177.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定