【备忘录】kafka常用命令维护

kafka指令备忘录

单个Topic扩容
sh bin/kafka-topics.sh --bootstrap-server broker_host:port --alter --topic test_create_topic1 --partitions 4

批量扩容

将所有正则表达式匹配到的Topic分区扩容到4个
sh bin/kafka-topics.sh --topic “.*?” --bootstrap-server 172.23.248.85:9092 --alter --partitions 4

查询单个Topic
sh bin/kafka-topics.sh --topic test --bootstrap-server xxxx:9092 --describe --exclude-internal

批量查询Topic
sh bin/kafka-topics.sh --topic “.*?” --bootstrap-server xxxx:9092 --describe --exclude-internal

查询所有Topic列表
sh bin/kafka-topics.sh --bootstrap-server xxxxxx:9092 --list --exclude-internal

查询匹配Topic列表(正则表达式)

查询test_create_开头的所有Topic列表
sh bin/kafka-topics.sh --bootstrap-server xxxxxx:9092 --list --exclude-internal --topic “test_create_.*”

查询单个Topic配置(只列举动态配置)
sh bin/kafka-configs.sh --describe --bootstrap-server xxxxx:9092 --topic test_create_topic 或者 sh bin/kafka-configs.sh --describe --bootstrap-server 172.23.248.85:9092 --entity-type topics --entity-name test_create_topic

查询所有Topic配置(包括内部Topic)(只列举动态配置)
sh bin/kafka-configs.sh --describe --bootstrap-server 172.23.248.85:9092 --entity-type topics

查询kafka版本信息
sh bin/kafka-configs.sh --describe --bootstrap-server xxxx:9092 --version

opic添加/修改动态配置
–add-config
sh bin/kafka-configs.sh --bootstrap-server xxxxx:9092 --alter --entity-type topics --entity-name test_create_topic1 --add-config file.delete.delay.ms=222222,retention.ms=999999

–delete-config
sh bin/kafka-configs.sh --bootstrap-server xxxxx:9092 --alter --entity-type topics --entity-name test_create_topic1 --delete-config file.delete.delay.ms,retention.ms

添加/删除配置同时执行
sh bin/kafka-configs.sh --bootstrap-server xxxxx:9092 --alter --entity-type brokers --entity-default --add-config log.segment.bytes=788888888 --delete-config log.retention.ms

配置默认
–entity-default
sh bin/kafka-configs.sh --bootstrap-server xxxxx:9090 --alter --entity-type brokers --entity-default --add-config log.segment.bytes=88888888

生产无key消息
bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test --producer.config config/producer.properties

生产有key消息加上属性
–property parse.key=true
bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test --producer.config config/producer.properties --property parse.key=true

新客户端从头消费
–from-beginning
sh bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

正则表达式匹配topic进行消费
–whitelist
消费所有的topic
sh bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --whitelist ‘.*’

消费所有的topic
sh bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --whitelist ‘.*’ --from-beginning

消费指定topic并显示key
–property print.key=true
sh bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --property print.key=true

指定分区消费
–partition
指定起始偏移量消费–offset
sh bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --partition 0 --offset 100

给客户端命名
–group
sh bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --group test-group

添加客户端属性
–consumer.config
跟–consumer-property 一样的性质,都是添加客户端的属性,–consumer-property 的优先级大于 --consumer.config
sh bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --consumer.config config/consumer.properties

相关推荐

  1. 备忘录kafka命令维护

    2024-03-15 09:52:04       37 阅读
  2. kafka 命令

    2024-03-15 09:52:04       24 阅读
  3. kafka(二)——命令

    2024-03-15 09:52:04       60 阅读
  4. kafka 命令【学习笔记】

    2024-03-15 09:52:04       56 阅读
  5. kafka客户端命令

    2024-03-15 09:52:04       35 阅读
  6. 大数据命令-Kafka

    2024-03-15 09:52:04       32 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-15 09:52:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-15 09:52:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-15 09:52:04       82 阅读
  4. Python语言-面向对象

    2024-03-15 09:52:04       91 阅读

热门阅读

  1. postman学习

    2024-03-15 09:52:04       33 阅读
  2. html5&css&js代码 011 个人简历二

    2024-03-15 09:52:04       37 阅读
  3. c 语言stdlib.h介绍

    2024-03-15 09:52:04       35 阅读
  4. Spring Boot 事务管理(事务失效常见场景)

    2024-03-15 09:52:04       42 阅读
  5. Python中的区块链技术与应用

    2024-03-15 09:52:04       40 阅读
  6. 每日OJ题_简单多问题dp①_力扣LCR 089. 打家劫舍

    2024-03-15 09:52:04       36 阅读
  7. ChatGPT创造力与创新探究

    2024-03-15 09:52:04       40 阅读
  8. Hive连接函数 concat 和 concat_ws 使用示例

    2024-03-15 09:52:04       36 阅读
  9. 如果保障服务器的安全

    2024-03-15 09:52:04       43 阅读
  10. ubuntu服务器使用netplan管理工具添加静态地址

    2024-03-15 09:52:04       34 阅读