gpt4 book ai didi

docker - 为什么我应该将docker image “confluentinc/kafka”用于kafka集群?

转载 作者:行者123 更新时间:2023-12-02 19:21:11 25 4
gpt4 key购买 nike

我做了

docker-compose up

在我的本地进行kafka集群。

每当我要创建主题时,检索我拥有的主题或搜索存储在我使用的主题中的数据
docker run --net=host --rm confluentinc/cp-kafka:latest kafka-topics --describe --topic bar --zookeeper localhost:32181

在官方的Kafka群集部署站点上。

但是我真的想在我的本地存储中使用Kafka而不是像kafka docker镜像那样
kafka-topics --describe --topic bar --zookeeper localhost:32181

如果我使用上面的代码,我会遇到此错误。
Exception in thread "main" kafka.zookeeper.ZooKeeperClientTimeoutException: Timed out waiting for connection while in state: CONNECTING
at kafka.zookeeper.ZooKeeperClient.$anonfun$waitUntilConnected$3(ZooKeeperClient.scala:258)

此外,如果我检查 netstat -anp tcp
kafka集群没有监听端口。

我应该做些什么 ?
并请让我知道我现在对Docker缺少什么(因为我对docker :()真的很陌生

这是Yaml配置
---
version: '2'
services:
zookeeper-1:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_SERVER_ID: 1
ZOOKEEPER_CLIENT_PORT: 22181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
network_mode: host
extra_hosts:
- "moby:127.0.0.1"

zookeeper-2:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_SERVER_ID: 2
ZOOKEEPER_CLIENT_PORT: 32181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
network_mode: host
extra_hosts:
- "moby:127.0.0.1"

zookeeper-3:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_SERVER_ID: 3
ZOOKEEPER_CLIENT_PORT: 42181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
network_mode: host
extra_hosts:
- "moby:127.0.0.1"

kafka-1:
image: confluentinc/cp-kafka:latest
network_mode: host
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: localhost:22181,localhost:32181,localhost:42181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:19092
extra_hosts:
- "moby:127.0.0.1"

kafka-2:
image: confluentinc/cp-kafka:latest
network_mode: host
"docker-compose.yml" 83L, 2321C

最佳答案

如果您在主机上运行Kafka(和Zookeeper),那么,不,您根本不需要Docker。

您不应在容器的任何连接字符串中使用localhost,而应使用容器的外部服务名称并从配置中删除network_mode

注意:在一台机器上的多个经纪人/动物园管理员没有任何帮助。

or search data stored in the topic



您不应该使用Zookeeper来做到这一点

关于docker - 为什么我应该将docker image “confluentinc/kafka”用于kafka集群?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59609677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com