LEADER_NOT_AVAILABLE - 码头集装箱
Posted
技术标签:
【中文标题】LEADER_NOT_AVAILABLE - 码头集装箱【英文标题】:LEADER_NOT_AVAILABLE - docker container 【发布时间】:2019-01-05 18:13:39 【问题描述】:设置 docker 容器(kafka、zookeeper)并尝试从另一个容器(发布和)消费,收到以下错误:
KafkaErrorcode=LEADER_NOT_AVAILABLE,val=5,str="Broker: Leader not available"
发布或消费时没有额外的错误提示。在测试与telnet 172.18.0.3 9092
的连接时,我收到了预期的结果。
In [2]: c.list_topics()
Out[2]: ClusterMetadata(9ToJF8nPQC-rCTXGxuUalw)
In [3]: l = c.list_topics()
In [4]: l.brokers
Out[4]: 1010: BrokerMetadata(1010, 172.18.0.3:9092)
In [7]: l.orig_broker_name
Out[7]: u'172.18.0.3:9092/1010'
In [8]: l.topics
Out[8]:
'__consumer_offsets': TopicMetadata(__consumer_offsets, 50 partitions),
'item': TopicMetadata(item, 1 partitions),
'mytopic': TopicMetadata(mytopic, 1 partitions)
In [9]: i =l.topics['item']
In [10]: i.partitions
Out[10]: 0: PartitionMetadata(-1, KafkaErrorcode=LEADER_NOT_AVAILABLE,val=5,str="Broker: Leader not available")
docker-compose.yml:
version: '2'
services:
zookeeper:
restart: always
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
restart: always
depends_on:
- zookeeper
image: wurstmeister/kafka
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: "172.18.0.3"
KAFKA_ADVERTISED_PORT: "9092"
KAFKA_CREATE_TOPICS: "item:1:1"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ubuntu@STAGE:~/docker/kafka# sudo docker network inspect kafka_default
[
"Name": "kafka_default",
"Id": "fc8afcde4318599b66f540ebd6221cffe57382a70b43ed1d58eda7fe059e7a18",
"Created": "2018-07-25T13:29:56.034567548Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM":
"Driver": "default",
"Options": null,
"Config": [
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
]
,
"Internal": false,
"Attachable": false,
"Containers":
"7776db25d1ca9a3ec98775ff0dabe356409dda9f782a771c9b1f7ae4e04f3453":
"Name": "test",
"EndpointID": "204158f6f167b12c06b2dcdda856992c5ea75adc80b06ac00f9abebb4f0179ba",
"MacAddress": "02:42:ac:12:00:04",
"IPv4Address": "172.18.0.4/16",
"IPv6Address": ""
,
"b4869e44cf136a129701413c5a5dd371d15d6158bfaf577d30aeb6ad66b63263":
"Name": "kafka_zookeeper_1", DEPTH_PRIORITY = 1
"EndpointID": "229b2587d92c8593d933d2583e09e669aa6f9a9c04e5b94ebf5a25be57aad27f",
"MacAddress": "02:42:ac:12:00:02",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
,
"f682fd27ef52a40abf501348b5b16e59b48440041d1e4827ddb15a0ef8dbdd14":
"Name": "kafka_kafka_1",
"EndpointID": "b17874d64c699635c471a1bcb515cb1441d22b2896e98a113115a4239caed460",
"MacAddress": "02:42:ac:12:00:03",
"IPv4Address": "172.18.0.3/16",
"IPv6Address": ""
,
"Options": ,
"Labels":
]
【问题讨论】:
1) 您是否尝试过使用 Confluent Docker 镜像 2) 可以 telnet 并且端口打开并不意味着 Kafka 协议可以正常工作 @cricket_007 不,我不熟悉 Confluent Docker 映像。你有链接吗?谢谢 他们在 DockerHub 上 confluentinc 下 具体到 wurstmeister 的图像,您可以在这里查看我的答案:***.com/a/50525419/3224238(以及其他提示)通常应该可以从容器外部访问 ADVERTISED_HOST_NAME 如果您向不存在的主题生成消息,则会收到此错误。请看这里:***.com/a/52189159/1545425 【参考方案1】:始终尝试在 KAFKA_ADVERTISED_HOST_NAME 中使用公共 ip,您可以使用 KAFKA_HOST_NAME 指定实例的主机名。
此外,如果您使用的是最新的 kafka 版本,请使用 listeners 和 Advertisementd.listeners 而不是使用 host.name 和 Advertisementd.host.name。
【讨论】:
以上是关于LEADER_NOT_AVAILABLE - 码头集装箱的主要内容,如果未能解决你的问题,请参考以下文章
Apache Kafka LEADER_NOT_AVAILABLE
Kafka - 获取具有相关 ID 的元数据时出错 - LEADER_NOT_AVAILABLE
Debezium:无法在 Kafka-Connect Docker 容器上设置观察程序。获取相关 ID 为 2 的元数据时出错 ... LEADER_NOT_AVAILABLE