怎么彻底删除kafka的topic,然后重建?

网上都说用kafka-run-class.shkafka.admin.DeleteTopicCommand 命令删除topic,但是并没有成功,用
kafka-topics.sh命令查看依然可以查看到topic,应该怎样才能彻底删除topic?
2016-01-01 添加评论

2 个回复

 

OpenSkill - OpenSkill官方账号

赞同来自: Ansiblebeing

**kafka 0.8.1.1以及之前版本**都无法使用类似一条命令就彻底删除topic,此命令不过只是在zookeeper注销信息而已,但是实际的日志内容还是保存在kafka log中,如果想彻底删除topic,过程如下:
1、从zookeerer删除信息
./bin/kafka-run-class.sh kafka.admin.DeleteTopicCommand --zookeeper 10.0.1.10:2181,10.0.1.11:2181,10.0.1.12:2181 --topic test成功后返回信息:deletion succeeded!
2、利用JPS命令查看kafka和zookeeper进程,kill掉QuorumPeerMain和Kafka进程
3、从kafka的log.dirs目录删除文件,可以看到多个子目录名字如test-0,test-1…test-n(就是你topic的partition个数)
进入到kafka的log.dirs目录,执行
rm –fr test-0……test-n(4)  修改日志目录的recovery-point-offset-checkpoint和replication-offset-checkpoint文件(要小心删除,否则待会kafka不能正常启动起来)
replication-offset-checkpoint格式如下:
0
4(partition总数)
test 0 0
test 3 0
hehe 0 0
hehe 1 0
修改后如下:
0
2(partition总数)
hehe 0 0
hehe 1 0
把含有test行全部去掉,并且把partition总数修改为减去test的partition的剩余数目,同理recovery-point-offset-checkpoint也是这样修改。
完成后就可以正常启动zookeeper和kafka。**从kafka 0.8.2.1**开始可以直接删除topic,步骤如下:
kafka 0.8.1.1之前版本,kafka-topics.sh命令连--delete                                Delete a topic参数都没有,如下:
# ./kafka-topics.sh --help
Command must include exactly one action: --list, --describe, --create or --alter
Option Description 
------ ----------- 
--alter Alter the configuration for the topic. 
--config <name=value> A topic configuration override for the 
topic being created or altered. 
--create Create a new topic. 
--deleteConfig <name> A topic configuration override to be 
removed for an existing topic 
--describe List details for the given topics. 
--help Print usage information. 
--list List all available topics. 
--partitions <Integer: # of partitions> The number of partitions for the topic 
being created or altered (WARNING: 
If partitions are increased for a 
topic that has a key, the partition 
logic or ordering of the messages 
will be affected 
--replica-assignment A list of manual partition-to-broker 
<broker_id_for_part1_replica1 : assignments for the topic being 
broker_id_for_part1_replica2 , created or altered. 
broker_id_for_part2_replica1 : 
broker_id_for_part2_replica2 , ...> 
--replication-factor <Integer: The replication factor for each 
replication factor> partition in the topic being created.
--topic <topic> The topic to be create, alter or 
describe. Can also accept a regular 
expression except for --create option
--topics-with-overrides if set when describing topics, only 
show topics that have overridden 
configs 
--unavailable-partitions if set when describing topics, only 
show partitions whose leader is not 
available 
--under-replicated-partitions if set when describing topics, only 
show under replicated partitions 
--zookeeper <urls> REQUIRED: The connection string for 
the zookeeper connection in the form 
host:port. Multiple URLS can be 
given to allow fail-over. 
# **而kafka 0.8.2.1**新增加了这个参数

删除过程:
1、在kafka配置文件中添加删除参数
delete.topic.enable=true2、利用命令删除需要删除的topic
bin/kafka-topics.sh --zookeeper zk_host:port/chroot --delete --topic my_topic_namehttp://kafka.apache.org/documentation.html#gettingStarted如下:

 
2016-01-0121

  • being • 2016-01-03 18:52

    好回答,总结不错!

chris - 喜欢自由散漫的我

版本不一样,删除方法不一样,最好是升级到新版较稳定的比较好。
 

最新文章

  1. Java 清除数组相同元素
  2. xampp安装
  3. javaScript学习(入门)
  4. 转载:回编译APK出错:java.nio.char set.MalformedInputException: Input length = 1
  5. 深入浅出设计模式——单例模式(Singleton Pattern)
  6. [Z]CS权威会议
  7. HDU 1533 &amp; KM模板
  8. POJ 3710 Christmas Game
  9. Tuple元祖
  10. Intellij Idea 创建Web项目入门(一)
  11. 简单分析什么是SQL注入漏洞
  12. I.MX6 linux Qt 同时支持Touch、mouse
  13. light oj 1078 - Integer Divisibility
  14. 【转】linux中的sort命令
  15. Cookie的前后台应用
  16. WCF 无法生成 client
  17. JavaScript之数组去重
  18. FileReader读取本地文件
  19. JavaSE| 泛型
  20. 1.4 flask request和session

热门文章

  1. Maven报错: Missing artifact jdk.tools:jdk.tools:jar:1.7
  2. 【BZOJ-1260】涂色paint 区间DP
  3. 【BZOJ-2006】超级钢琴 ST表 + 堆 (一类经典问题)
  4. 【bzoj2809】 Apio2012—dispatching
  5. wrapper for lua
  6. sersync2 安装,配置
  7. [Java 实现AES加密解密]
  8. LuaLaTeX \documemtclass{standalone} 编译错误
  9. WebStorm工具插件下载安装
  10. InteropBitmap指定内存,绑定WPF的Imag控件时刷新问题。