Delete topic in Kafka 0.8.1.1

2019-01-08 05:56发布

I need to delete the topic test in Apache Kafka 0.8.1.1.

As expressed in the documentation here, I have executed:

bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic test

However, this results in the following message:

Command must include exactly one action: --list, --describe, --create or --alter

How can I delete this topic?

12条回答
Root(大扎)
2楼-- · 2019-01-08 06:34

Steps to Delete 1 or more Topics in Kafka

To delete topics in kafka the delete option needs to be enabled in Kafka server.

1. Go to {kafka_home}/config/server.properties
2. Uncomment delete.topic.enable=true

Delete one Topic in Kafka enter the following command

kafka-topics.sh --delete --zookeeper localhost:2181 --topic

To Delete more than one topic from kafka

(good for testing purposes, where i created multiple topics & had to delete them for different scenarios)

  1. Stop the Kafka Server and Zookeeper
  2. go to /tmp folder where the logs are stored and delete the kafkalogs and zookeeper folder manually
  3. Restart the zookeeper and kafka server and try to list topics,

bin/kafka-topics.sh --list --zookeeper localhost:2181

if no topics are listed then the all topics have been deleted successfully.If topics are listed, then the delete was not successful. Try the above steps again or restart your computer.

查看更多
贪生不怕死
3楼-- · 2019-01-08 06:35

It seems that the deletion command was not officially documented in Kafka 0.8.1.x because of a known bug (https://issues.apache.org/jira/browse/KAFKA-1397).

Nevertheless, the command was still shipped in the code and can be executed as:

bin/kafka-run-class.sh kafka.admin.DeleteTopicCommand --zookeeper localhost:2181 --topic test

In the meantime, the bug got fixed and the deletion command is now officially available from Kafka 0.8.2.0 as:

bin/kafka-topics.sh --delete --zookeeper localhost:2181 --topic test
查看更多
冷血范
4楼-- · 2019-01-08 06:37

Add below line in ${kafka_home}/config/server.properties

delete.topic.enable=true

Restart the kafka server with new config:

${kafka_home}/bin/kafka-server-start.sh ~/kafka/config/server.properties

Delete the topics you wish to:

${kafka_home}/bin/kafka-topics.sh --delete  --zookeeper localhost:2181  --topic daemon12
查看更多
Bombasti
5楼-- · 2019-01-08 06:37

You can delete a specific kafka topic (example: test) from zookeeper shell command (zookeeper-shell.sh). Use the below command to delete the topic

rmr {path of the topic}

example:

rmr /brokers/topics/test
查看更多
太酷不给撩
6楼-- · 2019-01-08 06:37

This steps will delete all topics and data

  • Stop Kafka-server and Zookeeper-server
  • Remove the tmp data directories of both services, by default they are C:/tmp/kafka-logs and C:/tmp/zookeeper.
  • then start Zookeeper-server and Kafka-server
查看更多
何必那么认真
7楼-- · 2019-01-08 06:39

Adding to above answers one has to delete the meta data associated with that topic in zookeeper consumer offset path.

bin/zookeeper-shell.sh zookeeperhost:port

rmr /consumers/<sample-consumer-1>/offsets/<deleted-topic>

Otherwise the lag will be negative in kafka-monitoring tools based on zookeeper.

查看更多
登录 后发表回答