debezium / zookeeper端口2181已关闭

时间:2020-10-12 08:55:55

标签: docker apache-zookeeper debezium

我有一个来自https://hub.docker.com/r/debezium/zookeeper:1.2映像和我的Compose文件的Zookeeper实例:

version: "3.7"
services:
  zookeeper:
    image: debezium/zookeeper:1.2
    ports:
      - "2181:2181"
      - "2888:2888"
      - "3888:3888"
    networks:
      common:
    volumes:
      - "~/dev/docker/projects/debezium/volumes/zookeeper/data:/zookeeper/data"
      - "~/dev/docker/projects/debezium/volumes/zookeeper/txns:/zookeeper/txns"
      - "~/dev/docker/projects/debezium/volumes/zookeeper/conf:/zookeeper/conf"
      - "~/dev/docker/projects/debezium/volumes/zookeeper/logs:/zookeeper/logs"
    environment:
      HOST_USER_ID: ${CURRENT_UID}
      HOST_GROUP_ID: ${CURRENT_GID}
    deploy:
      replicas: 1
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
        window: 10s
    healthcheck:
      test: curl --fail http://localhost:2181 || exit 1
      interval: 1m
      timeout: 3s
      retries: 3

我可以看到Zookeeper服务器正常启动:

5f7860484b48        debezium/zookeeper:1.2            "/docker-entrypoint.…"   About a minute ago   Up About a minute (health
: starting)   2181/tcp, 2888/tcp, 3888/tcp, 8778/tcp, 9779/tcp   debezium_zookeeper.1.hmdxswlsmqdebqkqvkjqzxnlc

服务器日志显示:

debezium_zookeeper.1.j841dv1adeab@stephane-pc    | 2020-10-12 08:45:15,032 - INFO  [main:ContextHandler@825] - Started o.e.j.s.ServletContextHandler@3f197a46{/,null,AVAILABLE}
debezium_zookeeper.1.j841dv1adeab@stephane-pc    | 2020-10-12 08:45:15,111 - INFO  [main:AbstractConnector@330] - Started ServerConnector@4278a03f{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
debezium_zookeeper.1.j841dv1adeab@stephane-pc    | 2020-10-12 08:45:15,112 - INFO  [main:Server@399] - Started @5046ms
debezium_zookeeper.1.j841dv1adeab@stephane-pc    | 2020-10-12 08:45:15,113 - INFO  [main:JettyAdminServer@112] - Started AdminServer on address 0.0.0.0, port 8080 and command URL /commands
debezium_zookeeper.1.j841dv1adeab@stephane-pc    | 2020-10-12 08:45:15,135 - INFO  [main:ServerCnxnFactory@135] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory
debezium_zookeeper.1.j841dv1adeab@stephane-pc    | 2020-10-12 08:45:15,145 - INFO  [main:NIOServerCnxnFactory@673] - Configuring NIO connection handler with 10s sessionless connection timeout, 1 selector thread(s), 8 worker threads, and 64 kB direct buffers.
debezium_zookeeper.1.j841dv1adeab@stephane-pc    | 2020-10-12 08:45:15,150 - INFO  [main:NIOServerCnxnFactory@686] - binding to port 0.0.0.0/0.0.0.0:2181
debezium_zookeeper.1.j841dv1adeab@stephane-pc    | 2020-10-12 08:45:15,224 - INFO  [main:ZKDatabase@117] - zookeeper.snapshotSizeFactor = 0.33
debezium_zookeeper.1.j841dv1adeab@stephane-pc    | 2020-10-12 08:45:15,320 - INFO  [main:FileSnap@83] - Reading snapshot /zookeeper/data/version-2/snapshot.0
debezium_zookeeper.1.j841dv1adeab@stephane-pc    | 2020-10-12 08:45:15,340 - INFO  [main:FileTxnSnapLog@404] - Snapshotting: 0x0 to /zookeeper/data/version-2/snapshot.0
debezium_zookeeper.1.j841dv1adeab@stephane-pc    | 2020-10-12 08:45:15,408 - INFO  [main:ContainerManager@64] - Using checkIntervalMs=60000 maxPerMinute=10000
debezium_zookeeper.1.j841dv1adeab@stephane-pc    | 2020-10-12 08:46:10,244 - WARN  [NIOWorkerThread-1:NIOServerCnxn@370] - Exception causing close of session 0x0: Len error 1195725856
debezium_zookeeper.1.j841dv1adeab@stephane-pc    | 2020-10-12 08:47:10,884 - WARN  [NIOWorkerThread-2:NIOServerCnxn@370] - Exception causing close of session 0x0: Len error 1195725856
debezium_zookeeper.1.j841dv1adeab@stephane-pc    | 2020-10-12 08:48:12,599 - WARN  [NIOWorkerThread-3:NIOServerCnxn@370] - Exception causing close of session 0x0: Len error 1195725856

但是我无法从主机连接到发布的端口:

stephane@stephane-pc:~$ nmap -p 2181 localhost
Starting Nmap 7.80 ( https://nmap.org ) at 2020-10-12 10:50 CEST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00033s latency).

PORT     STATE  SERVICE
2181/tcp closed eforward

当然,该端口已在防火墙中启用:

sudo ufw allow from any to any port 2181;

stephane@stephane-pc:~$ sudo ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), deny (routed)
New profiles: skip

To                         Action      From
--                         ------      ----
8500                       ALLOW IN    127.0.0.0                 
8500                       ALLOW IN    Anywhere                  
18630                      ALLOW IN    Anywhere                  
2181                       ALLOW IN    127.0.0.0                 
2181                       ALLOW IN    Anywhere                  
9092                       ALLOW IN    Anywhere                  
8500 (v6)                  ALLOW IN    Anywhere (v6)             
18630 (v6)                 ALLOW IN    Anywhere (v6)             
2181 (v6)                  ALLOW IN    Anywhere (v6)             
9092 (v6)                  ALLOW IN    Anywhere (v6)

我可以连接到正在运行的容器:

docker-exec debezium_zookeeper.1.app5h7goosa2cpn4g06azp2xt

并查看服务器状态:

[zookeeper@2f57d1a84ce7 ~]$ bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: standalone

日志确实显示警告:

debezium_zookeeper.1.u0koxm2njw2i@stephane-pc    | 2020-10-12 09:03:47,829 - WARN  [NIOWorkerThread-2:NIOServerCnxn@370] - Exception causing close of session 0x0: Len error 1195725856

似乎是known issue

这与我的封闭港口问题有关吗?

更新:我还尝试将hostname属性作为hostname: zookeeper添加到Compose文件中,并在127.0.1.1 zookeeper文件中添加/etc/hosts条目,但是将{{1} }命令仍显示关闭的端口。

1 个答案:

答案 0 :(得分:1)

我不得不改变健康检查的方式。

healthcheck:
  test: /zookeeper/bin/zkServer.sh print-cmd || exit 1
  interval: 1m
  timeout: 3s
  retries: 3
  start_period: 15s

完整的撰写文件:

version: "3.7"
services:
  zookeeper:
    image: debezium/zookeeper:1.2
    ports:
      - "2181:2181"
      - "2888:2888"
      - "3888:3888"
    networks:
      common:
    volumes:
      - "~/dev/docker/projects/debezium/volumes/zookeeper/data:/zookeeper/data"
      - "~/dev/docker/projects/debezium/volumes/zookeeper/txns:/zookeeper/txns"
      - "~/dev/docker/projects/debezium/volumes/zookeeper/conf:/zookeeper/conf"
      - "~/dev/docker/projects/debezium/volumes/zookeeper/logs:/zookeeper/logs"
    environment:
      HOST_USER_ID: ${CURRENT_UID}
      HOST_GROUP_ID: ${CURRENT_GID}
    deploy:
      resources:
        limits:
          cpus: "0.1"
          memory: 256M
      replicas: 1
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
        window: 10s
    healthcheck:
      test: /zookeeper/bin/zkServer.sh print-cmd || exit 1
      interval: 1m
      timeout: 3s
      retries: 3
      start_period: 15s
  kafka:
    image: debezium/kafka:1.2
    ports:
      - "9092:9092"
    networks:
      common:
    volumes:
      - "~/dev/docker/projects/debezium/volumes/kafka/data:/kafka/data"
      - "~/dev/docker/projects/debezium/volumes/kafka/logs:/kafka/logs"
    environment:
      ZOOKEEPER_CONNECT: zookeeper:2181
      HOST_USER_ID: ${CURRENT_UID}
      HOST_GROUP_ID: ${CURRENT_GID}
    depends_on:
      - zookeeper      
    deploy:
      replicas: 1
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
        window: 10s
    healthcheck:
      test: /kafka/bin/kafka-topics.sh --list --zookeeper zookeeper:2181 || exit 1
      interval: 1m
      timeout: 15s
      retries: 3
      start_period: 15s
networks:
  common:  
    external: true
    name: common