• 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
  • 相关阅读:
    ArcGIS 气象风场等示例 数据制作、服务发布及前端加载
    车载网络安全指南 概述(一)
    WPF使用Dispatcher
    Java虚拟机:Java模块化系统
    Redis(主从复制、哨兵模式、集群)概述及部署
    使用结构体指针作为参数赋值传递时的注意点
    关于在3dsmax中制作的模型导入UE后尺寸大小不对的问题
    多线程---线程安全问题及解决
    win11 卸载SQL Server
    【Linux操作系统】-- 多线程(三)-- 线程池+单例模式
  • 原文地址:https://blog.csdn.net/weixin_41463944/article/details/127950194