怎么彻底删除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 - 喜欢自由散漫的我

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

【帖子】怎么彻底删除kafka的topic,然后重建?的更多相关文章

  1. 删除kafka的topic及kafka基本命令

    kafka的topic默认是不允许被删除的,删除后在topic后会出现”marked for deletion”字样,实际并未删除,现在创建同样的topic会提示topic已经存在. 解决办法: se ...

  2. Kafka学习笔记之如何永久删除Kafka的Topic

    0x00 问题描述 使用kafka-topics --delete命令删除topic时并没有真正的删除,而是把topic标记为:“marked for deletion”,导致重新创建相同名称的Top ...

  3. 删除Kafka的topic

    刚接触Kafka,开始认为删除一个topic只是运行一下Kafka-topic.sh的delete命令就行了,但是,事实却不是这样,会出现两种情况:(1) 如果topic没有使用过即没有传输过消息,可 ...

  4. 如何删除Kafka的Topic

    在server.properties文件中添加配置:delete.topic.enable=true 创建kafka主题: kafka-topics.sh --create --zookeeper 1 ...

  5. 删除Kafka中topic

    步骤: 1.编辑Kafka启动时加载的配置文件server.properties,添加一行:delete.topic.enable=true 2.重启Zookeeper和Kafka 3.执行: ./b ...

  6. 彻底删除Kafka中的topic

    1.删除kafka存储目录(server.properties文件log.dirs配置,默认为"/tmp/kafka-logs")相关topic目录 2.Kafka 删除topic ...

  7. [Spark][kafka]kafka 的topic 创建和删除试验

    kafka 的topic 创建和删除试验 zookeeper和kafka 的安装,参考: http://www.cnblogs.com/caoguo/p/5958608.html 参考上述URL后,在 ...

  8. 删除kafka topic

    1.因为项目原因,kakfa通道中经常造成数据阻塞,导致kafka通道中数据量过大,因此我需要将kakfa通道中数据清除(个人项目原因,一直使用一个消费者,只要保证当前消费者不在消费之前很久的数据就可 ...

  9. 手动删除Kafka Topic

    一.删除Kafka topic 运行./bin/kafka-topics  --delete --zookeeper [zookeeper server]  --topic [topic name]: ...

随机推荐

  1. GraphX 的属性图

    package main.scala import org.apache.spark.graphx.{Edge, Graph, VertexId} import org.apache.spark.rd ...

  2. 【BZOJ-4561】圆的异或并 set + 扫描线

    4561: [JLoi2016]圆的异或并 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 254  Solved: 118[Submit][Statu ...

  3. 【bzoj1433】 ZJOI2009—假期的宿舍

    http://www.lydsy.com/JudgeOnline/problem.php?id=1433 (题目链接) 题意 一个暑假,有人去大学里面探望朋友,有些人回家了,有些人留下了,每个人都要在 ...

  4. TortoiseGit与GitHub项目关联设置

    一.常规克隆GitHub上的项目: 1.在本地硬盘上放置项目的地方上[右键]->[Git 克隆]->在[url地址]上输入https的GitHub的链接,然后就是等待完成,之后即可完成拉取 ...

  5. shell实现的守护进程

    代码本来是别人那里拿来的,自己又改了下,给busybox用. #! /bin/sh PRO_PATH=/opt/myapp PROGRAM=packet_analyzer while true ; d ...

  6. MVC5-6 帮助类

    视图帮助类 HtmlHelper HtmlHelper给我们封装了大量的常用方法,使我们的开发更具高效.那么其中有哪里是我们常用的呢? BingForm 生成form表单 上图简单的使用了Html.B ...

  7. HDU 5923 Prediction

    这题是2016 CCPC 东北四省赛的B题, 其实很简单. 现场想到的就是正解, 只是在合并两个并查集这个问题上没想清楚. 做法 并查集合并 + 归并 对每个节点 \(u\), 将 \(u\) 到根的 ...

  8. HDU 4223 Dynamic Programming?(最小连续子序列和的绝对值O(NlogN))

    传送门 Description Dynamic Programming, short for DP, is the favorite of iSea. It is a method for solvi ...

  9. Visual Studio 2013小技巧

    Ctrl + F10 可以直接运行到光标处,而不用F10 逐过程 F11 逐语句了 当有多个断点时,按F5可以切换到下一个断点.

  10. MYSQL入门(三)

    索引简介 索引是对数据库表中一个或多个列(例如,employee 表的姓名 (name) 列)的值进行排序的结构.如果想按特定职员的姓来查找他或她,则与在表中搜索所有的行相比,索引有助于更快地获取信息 ...