• kafka主题脚本常用指令


    1、创建主题

    ./bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic zmtest --partitions 4 --replication-factor 2
    
    • 1

    2、查看主题分区情况

    ./bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic topic-create-same
    
    • 1

    3、指定分区副本创建主题命令

    ./bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic topic-create-same --replica-assignment 2:0,0:1,1:2,2:1
    
    • 1

    4、config覆盖默认配置

    ./bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic zmtest --partitions 4 --replication-factor 2 --config cleanup.policy=compact --config max.message.bytes=1000
    
    • 1

    5、创建主题时名称冲突–if-not-exists指令

    ./bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic zmtest --partitions 4 --replication-factor 2 --if-not-exists
    
    • 1

    6、查看主题列表命令

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

    7、查看主题,无–topic显示所有主题

    ./bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topics-with-overrides
    //列出覆盖配置的主题

    ./bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic zmtest --under-replicated-partitions
    
    • 1

    //找出失效副本分区

    ./bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic zmtest --unavailable-partitions  
    
    • 1

    //找出没有leader副本的分区

    8、修改主题信息
    ./bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic zmtest --partitions 1
    //修改分区数量,只增不减
    注:–if-exists参数如果存在时才执行命令;–delete-config xxxxxx//删除之前的覆盖属性
    9、主题配置管理
    //增加配置

    ./bin/kafka-configs.sh --zookeeper localhost:2181 --alter --entity-type topics --entity-name zmtest --add-config cleanup.policy=compact,max.message.bytes=1000 
    
    • 1

    //查看配置,无–entity-name则查看所有的信息

    ./bin/kafka-configs.sh --zookeeper localhost:2181 --describe --entity-type topics --entity-name zmtest
    
    • 1

    //删除配置

    ./bin/kafka-configs.sh --zookeeper localhost:2181 --alter --entity-type topics --entity-name zmtest --delete-config cleanup.policy,max.message.bytes 
    
    • 1

    10、删除主题

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

    //主题不存在会忽略

    ./bin/kafka-topics.sh --zookeeper 10.1.26.25:2181 --delete --topic topic-delete --if-exists 
    
    • 1
  • 相关阅读:
    ORA-01005 vs ORA-28040
    Bootstrap主页面搭建(十四)
    spring aop 初探
    品牌数字化转型|借势营销节点,3 招解锁品牌营销力
    python 根据url下载文件使用Python实现
    如何看待现在的面试变成了八股文
    C#单例模式懒汉式与饿汉式
    【C/C++】宏定义中的#和##
    uni-app开发微信小程序的报错[渲染层错误]排查及解决
    Kotlin委托
  • 原文地址:https://blog.csdn.net/weixin_41463944/article/details/127950194