【帖子】怎么彻底删除kafka的topic,然后重建?

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

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

时间: 2024-07-31 22:37:37

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

0022-如何永久删除Kafka的Topic

温馨提示:要看高清无码套图,请使用手机打开并单击图片放大查看. 1.问题描述 使用kafka-topics --delete命令删除topic时并没有真正的删除,而是把topic标记为:"marked for deletion",导致重新创建相同名称的Topic时报错"already exists". 2.问题复现 1.登录Kafka集群所在的服务器,创建一个test的topic [[email protected] ~]# kafka-topics --creat

手动删除Kafka Topic

一.删除Kafka topic 运行./bin/kafka-topics  --delete --zookeeper [zookeeper server]  --topic [topic name]:如果kafaka启动时加载的配置文件中server.properties没有配置delete.topic.enable=true,那么此时的删除并不是真正的删除,而是把topic标记为:marked for deletion 可以通过命令:./bin/kafka-topics --zookeeper

如何彻底删除Kafka中的topic (marked for deletion)

工作中因为各种原因, 例如topic中消息堆积的太多,或者kafka所在磁盘空间满了等等,可能需要彻底清理一下kafka topic,那么如何彻底删除topic?方法一(配置delete.topic.enable=true)  修改kafaka配置文件server.properties, 添加delete.topic.enable=true,重启kafka,之后通过kafka命令行就可以直接删除topic  通过命令行删除topic:     ./bin/kafka-topics.sh --de

彻底删除Kafka中的Topic

0:关闭Kafka 1:登录zookeeper客户端 [[email protected] zookeeper01]# ./bin/zkCli.sh (1)查看topic信息 ls /brokers/topics (2)删除所有topic deleteall /brokers/topics 2:删除kafka日志文件 rm kafka/log/* -rf 然后删除log.dirs文件夹下的所有日志文件. 3:启动Kafka 原文地址:https://www.cnblogs.com/yshyee/

Kafka中Topic级别配置

一.Kafka中topic级别配置 1.Topic级别配置 配置topic级别参数时,相同(参数)属性topic级别会覆盖全局的,否则默认为全局配置属性值. 创建topic参数可以设置一个或多个--config "Property(属性)",下面是创建一个topic名称为"my-topic"例子,它设置了2个参数max message size 和 flush rate. (A)创建topic时配置参数 bin/kafka-topics.sh --zookeeper

kafka delete topic

Don't think it is supported yet. Take a look at this JIRA tracking Delete Topic. For delete manually Shutdown the cluster Clean kafka log dir (specified by the log.dir attribute in kafka config file ) as well the zookeeper data Restart the cluster Fo

【转】Kafka某topic无法消费解决方案&amp;Kafka某Topic数据清理

由于项目原因,最近经常碰到Kafka消息队列某topic在集群宕机重启后无法消费的情况.碰到这种情况,有三步去判断原因所在: step A:如果用kafka串口(即console-consumer)是可以正常消费该topic,则排除kafka集群出现故障 step B:若平台业务能正常消费其他topic的消息,则排除平台业务代码逻辑问题 step C:不到万不得已,则只能手动删除kafka的对应topic的Log,但是清理Kafka Log又不能单纯的去删除中间环节产生的日志,中间关联的很多东西

Kafka消息topic分区

kafka是为分布式环境设计的,因此如果日志文件,其实也可以理解成消息数据库,放在同一个地方,那么必然会带来可用性的下降,一挂全挂,如果全量拷贝到所有的机器上,那么数据又存在过多的冗余,而且由于每台机器的磁盘大小是有限的,所以即使有再多的机器,可处理的消息还是被磁盘所限制,无法超越当前磁盘大小.因此有了partition的概念. kafka对消息进行一定的计算,通过hash来进行分区.这样,就把一份log文件分成了多份.如上面的分区读写日志图,分成多份以后,在单台broker上,比如快速上手中,

【kafka】Topic管理

1.查看已经创建的Topic cd /usr/local/kafka ./bin/kafka-topics.sh --list --zookeeper 10.1.44.186:2181,10.1.44.187:2181,10.1.44.188:2181 186                    187                    188 ------------------     ------------------     ------------------ __consum