为什么我不能在Kafka中创建一个主题?

t5zmwmid  于 2021-06-06  发布在  Kafka
关注(0)|答案(4)|浏览(456)

遵循《apache kafka快速入门指南》,我完成了以下步骤:
下载和解压 kafka_2.11-2.1.0.tgz cd kafka_2.11-2.1.0 bin/zookeeper-server-start.sh config/zookeeper.properties 在同一方向的另一个终端,
bin/kafka-server-start.sh config/server.properties bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test . 跑步 echo $? 之后显示此命令以状态退出 0 现在是关键时刻。导游说:
如果运行list topic命令,现在可以看到该主题:

bin/kafka-topics.sh --list --zookeeper localhost:2181
> test

但是,这个命令没有输出,我正在测试一个软件,它试图在服务器上发送消息 "test" 主题崩溃,因为它为该主题找到0个分区。
我还有一个ruby程序,可以向kafka发送关于主题的消息 "test" . 它失败并重试,我在kafka日志中看到了当时创建的主题,可以向它发送消息。但即使这样,列出主题的命令也不会返回任何结果。
为什么我不能显式地创建一个主题?为什么我不能列出按需创建的主题?如何排除故障?

日志

以下是我在日志中看到的:https://gist.github.com/nathanl/bea7a45a056b2d44146947ec88c29185

6yjfywim

6yjfywim1#

在mac10.13.6上,我遵循了相同的步骤,这里有一些故障排除步骤供您检查。
当您启动zookeeper时,您应该在标准输出中看到:

INFO binding to port 0.0.0.0/0.0.0.0:2181 (org.apache.zookeeper.server.NIOServerCnxnFactory)

当你开始Kafka你应该看到在标准:

INFO Awaiting socket connections on 0.0.0.0:9092. (kafka.network.Acceptor)
[…]
INFO [SocketServer brokerId=0] Started processors for 1 acceptors (kafka.network.SocketServer)
INFO Kafka version : 2.1.0 (org.apache.kafka.common.utils.AppInfoParser)
INFO Kafka commitId : 809be928f1ae004e (org.apache.kafka.common.utils.AppInfoParser)
INFO [KafkaServer id=0] started (kafka.server.KafkaServer)

这个 kafka-topics 命令应该返回输出(您没有提到任何输出,这可能是某个东西在这个阶段不起作用的迹象):

$ bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
Created topic "test".
$

当你这么做的时候,在Kafka标准中你会看到 Created log for partition test-0 在日志信息中:

INFO [Log partition=test-0, dir=/tmp/kafka-logs] Loading producer state till offset 0 with message format version 2 (kafka.log.Log)
INFO [Log partition=test-0, dir=/tmp/kafka-logs] Completed load of log with 1 segments, log start offset 0 and log end offset 0 in 52 ms (kafka.log.Log)
INFO Created log for partition test-0 in /tmp/kafka-logs with properties {compression.type -> producer, message.format.version -> 2.1-IV2, file.delete.delay.ms -> 60000, max.message.bytes -> 1000012, min.compaction.lag.ms -> 0, message.timestamp.type -> CreateTime, message.downconversion.enable -> true, min.insync.replicas -> 1, segment.jitter.ms -> 0, preallocate -> false, min.cleanable.dirty.ratio -> 0.5, index.interval.bytes -> 4096, unclean.leader.election.enable -> false, retention.bytes -> -1, delete.retention.ms -> 86400000, cleanup.policy -> [delete], flush.ms -> 9223372036854775807, segment.ms -> 604800000, segment.bytes -> 1073741824, retention.ms -> 604800000, message.timestamp.difference.max.ms -> 9223372036854775807, segment.index.bytes -> 10485760, flush.messages -> 9223372036854775807}. (kafka.log.LogManager)
INFO [Partition test-0 broker=0] No checkpointed highwatermark is found for partition test-0 (kafka.cluster.Partition)
INFO Replica loaded for partition test-0 with initial high watermark 0 (kafka.cluster.Replica)
INFO [Partition test-0 broker=0] test-0 starts at Leader Epoch 0 from offset 0. Previous Leader Epoch was: -1 (kafka.cluster.Partition)

主题将显示在列表中:

$ ./bin/kafka-topics.sh --zookeeper localhost:2181 --list
test
kr98yfug

kr98yfug2#

我也面临同样的问题。但是,我发现脚本bin/kafka-topics.sh的内容在untar命令之后是空的。
所以,我再次下载了kafka,untar并检查脚本文件的内容,直到我在那里看到它,然后它就工作了。

hvvq6cgz

hvvq6cgz3#

我在运行vpn时在mac上遇到了同样的问题,这导致了主机名解析失败。
我通过编辑解决了这个问题 server.properties ,添加行:

listeners=PLAINTEXT://localhost:9092
pbpqsu0x

pbpqsu0x4#

我也遇到了同样的问题。
首先检查 bin/kafka-topics.sh 里面有任何内容。
然后继续清除zookeeper和kafka的所有tmp数据
rm -r /tmp/zookeeper rm -r /tmp/kafka-log 然后再开始你的Zookeeper和Kafka。

相关问题