刪除已經創建的topic 刪除toipc主要使用:kafka-topics --delete --zookeeper zkip:zkport --topic topicname命令刪除;但是如果server.properties文件中delete.topic.enable設置的值是false(預設f ...
刪除已經創建的topic
刪除toipc主要使用:kafka-topics --delete --zookeeper zkip:zkport --topic topicname命令刪除;但是如果server.properties文件中delete.topic.enable設置的值是false(預設false),則這個命令只是對topic進行了標記刪除,並沒有真正的刪除對應的文件,這時需要手動去清理文件,具體方法;
1 刪除server.properties文件中log.dirs配置的對應目錄下的topic文件夾。如果是集群部署的話每個節點都需要自己手動刪除;
2 進入zk客戶端:zkCli.sh -server zkip:zkport,找到對應的topic,執行rmr /brokers/topic/topicname, rmr /config/topics/topic-name
經過以上兩步,就可以徹底清楚topic
如果server.properties中配置了delete.topic.enable=true,那麼直接通過kafka-topics --delete --zookeeper zkip:zkport --topic topicname就可以刪除;
另外,測試發現(kafka_2.11-0.10.0.0)如果開始delete.topic.enable=false,然後執行kafka-topics --delete --zookeeper zkip:zkport --topic topicname命令刪除了topic,接下來不去zk客戶端刪除相關的配置以及kafka相關的topic文件,而是將delete.topic.enable修改為true,重啟kafka後,會自動刪除相關的文件,日誌如下:
[2018-08-11 14:24:11,378] INFO Deleting index /shif/data/kafkaData/sf1-0/00000000000000000000.index (kafka.log.OffsetIndex)
[2018-08-11 14:24:11,381] INFO Deleted log for partition [sf1,0] in /shif/data/kafkaData/sf1-0. (kafka.log.LogManager)
[2018-08-11 14:24:11,410] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions [sf2,2] (kafka.server.ReplicaFetcherManager)
[2018-08-11 14:24:11,413] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions [sf2,1] (kafka.server.ReplicaFetcherManager)
[2018-08-11 14:24:11,419] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions [sf2,0] (kafka.server.ReplicaFetcherManager)
[2018-08-11 14:24:11,422] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions [sf2,2] (kafka.server.ReplicaFetcherManager)
[2018-08-11 14:24:11,430] INFO Deleting index /shif/data/kafkaData/sf2-2/00000000000000000000.index (kafka.log.OffsetIndex)
[2018-08-11 14:24:11,430] INFO Deleted log for partition [sf2,2] in /shif/data/kafkaData/sf2-2. (kafka.log.LogManager)
[2018-08-11 14:24:11,582] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions [sf2,1] (kafka.server.ReplicaFetcherManager)
[2018-08-11 14:24:11,591] INFO Deleting index /shif/data/kafkaData/sf2-1/00000000000000000000.index (kafka.log.OffsetIndex)
[2018-08-11 14:24:11,591] INFO Deleted log for partition [sf2,1] in /shif/data/kafkaData/sf2-1. (kafka.log.LogManager)
[2018-08-11 14:24:11,600] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions [sf2,0] (kafka.server.ReplicaFetcherManager)
[2018-08-11 14:24:11,604] INFO Deleting index /shif/data/kafkaData/sf2-0/00000000000000000000.index (kafka.log.OffsetIndex)
[2018-08-11 14:24:11,605] INFO Deleted log for partition [sf2,0] in /shif/data/kafkaData/sf2-0. (kafka.log.LogManager)
其中sf1,sf2為我創建的topic