我有一个基于 Docker Compose 的 Swarm,其中的 Zookeeper 服务启动正常,但是 Kafka 服务无法启动。
它继续使用默认KAFKA_ADVERTISED_LISTENERS
属性:
debezium_kafka.1.5hhrqfp5kqts@stephane-pc | Using ZOOKEEPER_CONNECT=zookeeper:2181
debezium_kafka.1.5hhrqfp5kqts@stephane-pc | Using KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://10.0.83.239:9092
当然,它无法找到映射中指定的监听器:
debezium_kafka.1.5hhrqfp5kqts@stephane-pc | java.lang.IllegalArgumentException: requirement failed: inter.broker.listener.name must be a listener name defined in advertised.listeners. The valid options based on currently configured listeners are PLAINTEXT
我的docker-compose-dev.yml
文件包含:
kafka:
image: debezium/kafka:1.2
deploy:
mode: global
ports:
- "9094:9094"
- "9095:9095"
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
KAFKA_LISTENERS: FROM_DOCKER_NETWORK://kafka:9092,FROM_HOST://kafka:9094
KAFKA_ADVERTISED_LISTENERS: FROM_DOCKER_NETWORK://kafka:9092,FROM_HOST://localhost:9094
KAFKA_ALLOW_PLAINTEXT_LISTENER: "yes"
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,FROM_DOCKER_NETWORK:PLAINTEXT,FROM_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: FROM_DOCKER_NETWORK
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "false"
答案1
我做错了什么,通过在KAFKA_LISTENERS
属性中指定硬编码的主机名:
KAFKA_LISTENERS: FROM_DOCKER_NETWORK://kafka:9092,FROM_HOST://kafka:9094
kafka
将主机名替换为IP 地址后0.0.0.0
,如下所示:
KAFKA_LISTENERS: FROM_DOCKER_NETWORK://0.0.0.0:9092,FROM_HOST://0.0.0.0:9094
问题已解决,Kafka 服务可以启动。
请注意,公布的侦听器保留从另一个容器访问 Kafka 服务的容器名称,以及localhost
从 Docker 主机访问 Kafka 服务的名称:
KAFKA_ADVERTISED_LISTENERS: FROM_DOCKER_NETWORK://kafka:9092,FROM_HOST://localhost:9094
答案2
@stephane 非常感谢。
我不能使用 kafka 作为名称,但必须将其绑定到 IP 地址(来自 docker 网络)并且它可以工作。