与 Docker 容器中的 Kafka 代理的连接失败 [重复]
Posted
技术标签:
【中文标题】与 Docker 容器中的 Kafka 代理的连接失败 [重复]【英文标题】:Connection to Kafka broker in Docker container fails [duplicate] 【发布时间】:2021-10-05 17:00:27 【问题描述】:我正在尝试运行一个简单的 Debezium 堆栈(使用 Docker Compose),但与 Kafka 代理的连接失败。
这是我的简化版docker-compose.yml
:
version: "3"
services:
zookeeper:
image: debezium/zookeeper:1.6
ports:
- "2181:2181"
- "2888:2888"
- "3888:3888"
kafka:
image: debezium/kafka:1.6
links:
- zookeeper
ports:
- "9092:9092"
environment:
BROKER_ID: 1
KAFKA_LISTENERS: LISTENER_BOB://kafka:29092,LISTENER_FRED://localhost:9092
KAFKA_ADVERTISED_LISTENERS: LISTENER_BOB://kafka:29092,LISTENER_FRED://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_BOB:PLAINTEXT,LISTENER_FRED:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_BOB
ZOOKEEPER_CONNECT: zookeeper:2181
您可能会注意到,我根据Kafka Listeners - Explained 添加了侦听器。但是当我使用kafkacat -b localhost:9092 -L
检索代理的元数据时,会出现以下错误。
%6|1627623916.693|FAIL|rdkafka#producer-1| [thrd:localhost:9092/bootstrap]: localhost:9092/bootstrap: Disconnected while requesting ApiVersion: might be caused by incorrect security.protocol configuration (connecting to a SSL listener?) or broker version is < 0.10 (see api.version.request) (after 2ms in state APIVERSION_QUERY)
%6|1627623916.961|FAIL|rdkafka#producer-1| [thrd:localhost:9092/bootstrap]: localhost:9092/bootstrap: Disconnected while requesting ApiVersion: might be caused by incorrect security.protocol configuration (connecting to a SSL listener?) or broker version is < 0.10 (see api.version.request) (after 3ms in state APIVERSION_QUERY, 1 identical error(s) suppressed)
% ERROR: Failed to acquire metadata: Local: Broker transport failure
当我按照 Debezium 的建议 here 配置 Kafka 时,Kafka 甚至无法启动。
2021-07-30 05:48:38,591 - WARN [Controller-1-to-broker-1-send-thread:NetworkClient@780] - [Controller id=1, targetBrokerId=1] Connection to node 1 (/localhost:9092) could not be established. Broker may not be available.
我做错了什么? 提前感谢您的帮助!
【问题讨论】:
【参考方案1】:您已将侦听器设置为仅是本地的,而不是外部的。
改成
KAFKA_LISTENERS: LISTENER_BOB://kafka:29092,LISTENER_FRED://0.0.0.0:9092
【讨论】:
以上是关于与 Docker 容器中的 Kafka 代理的连接失败 [重复]的主要内容,如果未能解决你的问题,请参考以下文章
从 Docker 容器将 PySpark 连接到 Kafka
如何修复 Kafka Docker 容器抛出 0.0.0.0/0.0.0.0:2181:连接被拒绝?
避免Kafka客户端无法连接Docker上运行的Kafka,又名:Docker如何添加hosts映射