zoukankan      html  css  js  c++  java
  • 【帖子】怎么彻底删除kafka的topic,然后重建?

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

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

    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**新增加了这个参数
    kafka_delete.png

     
    删除过程:
    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如下:
    delete_topic.png
     

    chris - 喜欢自由散漫的我

    版本不一样,删除方法不一样,最好是升级到新版较稳定的比较好。
  • 相关阅读:
    给按钮添加事件的方法
    kindedtor的基本使用
    angularJs增加行的操作
    js获取复选框内容
    Python3学习之路~5.13 re模块 正则表达式
    Python3学习之路~5.12 hashlib & hmac & md5 & sha & base64模块
    Python3学习之路~5.11 configparser模块
    Python3学习之路~5.10 PyYAML模块
    Python3学习之路~5.9 xml处理模块
    Python3学习之路~5.8 shelve模块
  • 原文地址:https://www.cnblogs.com/the-tops/p/5909781.html
Copyright © 2011-2022 走看看