【备忘录】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

相关推荐
想回家的一天3 分钟前
Go1.25的源码分析-src/runtime/runtime1.go(GMP)
数据库·redis·缓存
阿里云大数据AI技术1 小时前
鹰角网络基于阿里云EMR Serverless StarRocks的实时分析工程实践
数据库·数据分析
久笙&1 小时前
对象存储解决方案:MinIO 的架构与代码实战
数据库·python·架构
码luffyliu2 小时前
MySQL:MVCC机制及其在Java秋招中的高频考点
java·数据库·mysql·事务·并发·mvcc
水涵幽树2 小时前
MySQL 时间筛选避坑指南:为什么格式化字符串比较会出错?
数据库·后端·sql·mysql·database
PythonicCC2 小时前
Django中的MVC和MVT模式
数据库·django·mvc
AI 嗯啦5 小时前
SQL详细语法教程(七)核心优化
数据库·人工智能·sql
ClouGence5 小时前
三步搞定!GaussDB 实时数据入仓
数据库·后端
纪莫6 小时前
Kafka如何保证「消息不丢失」,「顺序传输」,「不重复消费」,以及为什么会发生重平衡(reblanace)
java·分布式·后端·中间件·kafka·队列
鼠鼠我捏,要死了捏7 小时前
生产环境MongoDB分片策略优化与故障排查实战经验分享
数据库·mongodb·分片