1. 故障现象

kafka版本:kafka_2.13-3.1.0
执行命令

/apps/kafka/bin/kafka-topics.sh --create --zookeeper 192.168.31.51:2181,192.168.31.52:2181,192.168.31.53:2181 --partitions 3 --replication-factor 3 --topic pana

时出现以下错误

Exception in thread "main" joptsimple.UnrecognizedOptionException: zookeeper is not a recognized option
	at joptsimple.OptionException.unrecognizedOption(OptionException.java:108)
	at joptsimple.OptionParser.handleLongOptionToken(OptionParser.java:510)
	at joptsimple.OptionParserState$2.handleArgument(OptionParserState.java:56)
	at joptsimple.OptionParser.parse(OptionParser.java:396)
	at kafka.admin.TopicCommand$TopicCommandOptions.<init>(TopicCommand.scala:567)
	at kafka.admin.TopicCommand$.main(TopicCommand.scala:47)
	at kafka.admin.TopicCommand.main(TopicCommand.scala)

2. 解决方法

用–bootstrap-server 192.168.31.51:9092 替代原先的–zookeeper 192.168.31.51:2181,192.168.31.52:2181,192.168.31.53:2181参数

/apps/kafka/bin/kafka-topics.sh --bootstrap-server 192.168.31.51:9092 --create --partitions 3 --replication-factor 3 --topic pana

故障排除

[2022-04-19 08:44:10,180] INFO Creating topic pana with configuration {} and initial partition assignment HashMap(0 -> ArrayBuffer(2, 3, 1), 1 -> ArrayBuffer(3, 1, 2), 2 -> ArrayBuffer(1, 2, 3)) (kafka.zk.AdminZkClient)
[2022-04-19 08:44:10,212] INFO [ReplicaFetcherManager on broker 1] Removed fetcher for partitions Set(pana-2) (kafka.server.ReplicaFetcherManager)
[2022-04-19 08:44:10,224] INFO [LogLoader partition=pana-2, dir=/apps/kafka/logs] Loading producer state till offset 0 with message format version 2 (kafka.log.UnifiedLog$)
[2022-04-19 08:44:10,228] INFO Created log for partition pana-2 in /apps/kafka/logs/pana-2 with properties {} (kafka.log.LogManager)
[2022-04-19 08:44:10,228] INFO [Partition pana-2 broker=1] No checkpointed highwatermark is found for partition pana-2 (kafka.cluster.Partition)
[2022-04-19 08:44:10,230] INFO [Partition pana-2 broker=1] Log loaded for partition pana-2 with initial high watermark 0 (kafka.cluster.Partition)
[2022-04-19 08:44:10,235] INFO [LogLoader partition=pana-1, dir=/apps/kafka/logs] Loading producer state till offset 0 with message format version 2 (kafka.log.UnifiedLog$)
[2022-04-19 08:44:10,237] INFO Created log for partition pana-1 in /apps/kafka/logs/pana-1 with properties {} (kafka.log.LogManager)
[2022-04-19 08:44:10,238] INFO [Partition pana-1 broker=1] No checkpointed highwatermark is found for partition pana-1 (kafka.cluster.Partition)
[2022-04-19 08:44:10,238] INFO [Partition pana-1 broker=1] Log loaded for partition pana-1 with initial high watermark 0 (kafka.cluster.Partition)
[2022-04-19 08:44:10,242] INFO [LogLoader partition=pana-0, dir=/apps/kafka/logs] Loading producer state till offset 0 with message format version 2 (kafka.log.UnifiedLog$)
[2022-04-19 08:44:10,244] INFO Created log for partition pana-0 in /apps/kafka/logs/pana-0 with properties {} (kafka.log.LogManager)
[2022-04-19 08:44:10,245] INFO [Partition pana-0 broker=1] No checkpointed highwatermark is found for partition pana-0 (kafka.cluster.Partition)
[2022-04-19 08:44:10,245] INFO [Partition pana-0 broker=1] Log loaded for partition pana-0 with initial high watermark 0 (kafka.cluster.Partition)
[2022-04-19 08:44:10,246] INFO [ReplicaFetcherManager on broker 1] Removed fetcher for partitions HashSet(pana-1, pana-0) (kafka.server.ReplicaFetcherManager)
[2022-04-19 08:44:10,247] INFO [ReplicaFetcherManager on broker 1] Added fetcher to broker 3 for partitions Map(pana-1 -> InitialFetchState(Some(ihTvt12WScm21VhcD5XS-A),BrokerEndPoint(id=3, host=192.168.31.53:9092),0,0)) (kafka.server.ReplicaFetcherManager)
[2022-04-19 08:44:10,247] INFO [ReplicaFetcherManager on broker 1] Added fetcher to broker 2 for partitions Map(pana-0 -> InitialFetchState(Some(ihTvt12WScm21VhcD5XS-A),BrokerEndPoint(id=2, host=192.168.31.52:9092),0,0)) (kafka.server.ReplicaFetcherManager)
Created topic pana.
[2022-04-19 08:44:10,481] INFO [ReplicaFetcher replicaId=1, leaderId=3, fetcherId=0] Truncating partition pana-1 with TruncationState(offset=0, completed=true) due to local high watermark 0 (kafka.server.ReplicaFetcherThread)
[2022-04-19 08:44:10,481] INFO [UnifiedLog partition=pana-1, dir=/apps/kafka/logs] Truncating to 0 has no effect as the largest offset in the log is -1 (kafka.log.UnifiedLog)
[2022-04-19 08:44:10,526] INFO [ReplicaFetcher replicaId=1, leaderId=2, fetcherId=0] Truncating partition pana-0 with TruncationState(offset=0, completed=true) due to local high watermark 0 (kafka.server.ReplicaFetcherThread)
[2022-04-19 08:44:10,526] INFO [UnifiedLog partition=pana-0, dir=/apps/kafka/logs] Truncating to 0 has no effect as the largest offset in the log is -1 (kafka.log.UnifiedLog)

此时可以通过工具确认topic是否被正确创建
在这里插入图片描述
通过命令验证

/apps/kafka/bin/kafka-topics.sh --bootstrap-server 192.168.31.51:9092 --describe --topic pana
Topic: pana	TopicId: ihTvt12WScm21VhcD5XS-A	PartitionCount: 3	ReplicationFactor: 3	Configs: segment.bytes=1073741824
	Topic: pana	Partition: 0	Leader: 2	Replicas: 2,3,1	Isr: 2,3,1
	Topic: pana	Partition: 1	Leader: 3	Replicas: 3,1,2	Isr: 3,1,2
	Topic: pana	Partition: 2	Leader: 1	Replicas: 1,2,3	Isr: 1,2,3
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐