kafka清理topic

服务组件版本信息

项目 Value
zookeeper 3.4.6
kafka 2.13

注:

  • 如果当前topic没有使用过即没有传输过信息:可以彻底删除
  • 如果当前topic有使用过即有过传输过信息:并没有真正删除topic只是把这个topic标记为删除(marked for deletion)。

彻底删除topic (本文将要删除的topic名称为test)

  1. 删除kafka相关的数据目录
    数据目录请参考目标机器上的kafka配置:server.properties 中的配置项 log.dirs 如下图所示

在这里插入图片描述

cd  /usr/local/kafka_2.13-2.4.1/logs/
rm -r  test
  1. 查看zookeeper 集群
grep 'zookeeper.connect' config/server.properties

在这里插入图片描述

删除kafka topic
/home/kafka/bin/kafka-topics.sh --delete --zookeeper xx:2181,xx:2181,xx:2181( 上图查询到的集群连接地址 ) --topic test

*此时并没有完全删除只是把相应topic的状态改为marked for deletion

删除zookeeper相关的路径
打开zookeeper client
/home/ZooKeeper/bin/zkCli.sh
执行下面的命令
把test替换成你要删除的topic

#删除topic test的consumer group,如果有消费记录的话

rmr /brokers/topics/【topic name】即可,此时topic被彻底删除。

完成
重启zookeeper和kafka可以用下面命令查看相关的topic还在不在:

bin/kafka-topics.sh --list --zookeeper xx:2181,xx:2181,xx:2181

猜你喜欢

转载自blog.csdn.net/qq_31024251/article/details/108275305