欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

kafka删除topic

程序员文章站 2022-04-24 16:20:16
删除已经创建的topic 删除toipc主要使用:kafka-topics --delete --zookeeper zkip:zkport --topic topicname命令删除;但是如果server.properties文件中delete.topic.enable设置的值是false(默认f ......

删除已经创建的topic

  删除toipc主要使用:kafka-topics  --delete --zookeeper  zkip:zkport  --topic topicname命令删除;但是如果server.properties文件中delete.topic.enable设置的值是false(默认false),则这个命令只是对topic进行了标记删除,并没有真正的删除对应的文件,这时需要手动去清理文件,具体方法;

1 删除server.properties文件中log.dirs配置的对应目录下的topic文件夹。如果是集群部署的话每个节点都需要自己手动删除;

2 进入zk客户端:zkCli.sh  -server  zkip:zkport,找到对应的topic,执行rmr  /brokers/topic/topicname, rmr  /config/topics/topic-name

经过以上两步,就可以彻底清楚topic

如果server.properties中配置了delete.topic.enable=true,那么直接通过kafka-topics  --delete --zookeeper  zkip:zkport  --topic topicname就可以删除;

另外,测试发现(kafka_2.11-0.10.0.0)如果开始delete.topic.enable=false,然后执行kafka-topics  --delete --zookeeper  zkip:zkport  --topic topicname命令删除了topic,接下来不去zk客户端删除相关的配置以及kafka相关的topic文件,而是将delete.topic.enable修改为true,重启kafka后,会自动删除相关的文件,日志如下:

[2018-08-11 14:24:11,378] INFO Deleting index /shif/data/kafkaData/sf1-0/00000000000000000000.index (kafka.log.OffsetIndex)
[2018-08-11 14:24:11,381] INFO Deleted log for partition [sf1,0] in /shif/data/kafkaData/sf1-0. (kafka.log.LogManager)
[2018-08-11 14:24:11,410] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions [sf2,2] (kafka.server.ReplicaFetcherManager)
[2018-08-11 14:24:11,413] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions [sf2,1] (kafka.server.ReplicaFetcherManager)
[2018-08-11 14:24:11,419] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions [sf2,0] (kafka.server.ReplicaFetcherManager)
[2018-08-11 14:24:11,422] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions [sf2,2] (kafka.server.ReplicaFetcherManager)
[2018-08-11 14:24:11,430] INFO Deleting index /shif/data/kafkaData/sf2-2/00000000000000000000.index (kafka.log.OffsetIndex)
[2018-08-11 14:24:11,430] INFO Deleted log for partition [sf2,2] in /shif/data/kafkaData/sf2-2. (kafka.log.LogManager)
[2018-08-11 14:24:11,582] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions [sf2,1] (kafka.server.ReplicaFetcherManager)
[2018-08-11 14:24:11,591] INFO Deleting index /shif/data/kafkaData/sf2-1/00000000000000000000.index (kafka.log.OffsetIndex)
[2018-08-11 14:24:11,591] INFO Deleted log for partition [sf2,1] in /shif/data/kafkaData/sf2-1. (kafka.log.LogManager)
[2018-08-11 14:24:11,600] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions [sf2,0] (kafka.server.ReplicaFetcherManager)
[2018-08-11 14:24:11,604] INFO Deleting index /shif/data/kafkaData/sf2-0/00000000000000000000.index (kafka.log.OffsetIndex)
[2018-08-11 14:24:11,605] INFO Deleted log for partition [sf2,0] in /shif/data/kafkaData/sf2-0. (kafka.log.LogManager)

其中sf1,sf2为我创建的topic