这是我参与8月更文挑战的第12天,活动详情查看:8月更文挑战java
@[TOC]git
平常运维 、问题排查 怎么可以少了滴滴开源的 滴滴开源LogiKM一站式Kafka监控与管控平台github
--list
sh bin/kafka-consumer-groups.sh --bootstrap-server xxxx:9090 --list
面试
先调用MetadataRequest
拿到全部在线Broker列表 再给每一个Broker发送ListGroupsRequest
请求获取 消费者组数据apache
--describe
DescribeGroupsRequest
bootstrap
查看消费组详情--group
或 --all-groups
markdown
查看指定消费组详情
--group
sh bin/kafka-consumer-groups.sh --bootstrap-server xxxxx:9090 --describe --group test2_consumer_group
app
查看全部消费组详情
--all-groups
sh bin/kafka-consumer-groups.sh --bootstrap-server xxxxx:9090 --describe --all-groups
查看该消费组 消费的全部Topic、及所在分区、最新消费offset、Log最新数据offset、Lag还未消费数量、消费者ID等等信息运维
查询消费者成员信息--members
oop
全部消费组成员信息
sh bin/kafka-consumer-groups.sh --describe --all-groups --members --bootstrap-server xxx:9090
指定消费组成员信息sh bin/kafka-consumer-groups.sh --describe --members --group test2_consumer_group --bootstrap-server xxxx:9090
查询消费者状态信息--state
全部消费组状态信息
sh bin/kafka-consumer-groups.sh --describe --all-groups --state --bootstrap-server xxxx:9090
指定消费组状态信息sh bin/kafka-consumer-groups.sh --describe --state --group test2_consumer_group --bootstrap-server xxxxx:9090
--delete
DeleteGroupsRequest
删除消费组--delete
删除指定消费组
--group
sh bin/kafka-consumer-groups.sh --delete --group test2_consumer_group --bootstrap-server xxxx:9090
删除全部消费组--all-groups
sh bin/kafka-consumer-groups.sh --delete --all-groups --bootstrap-server xxxx:9090
PS: 想要删除消费组前提是这个消费组的全部客户端都中止消费/不在线才可以成功删除;不然会报下面异常
Error: Deletion of some consumer groups failed:
* Group 'test2_consumer_group' could not be deleted due to: java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.GroupNotEmptyException: The group is not empty.
复制代码
--reset-offsets
可以执行成功的一个前提是 消费组这会是不可用状态;
下面的示例使用的参数是: --dry-run
;这个参数表示预执行,会打印出来将要处理的结果; 等你想真正执行的时候请换成参数--excute
;
下面示例 重置模式都是 --to-earliest
重置到最先的;
请根据须要参考下面 相关重置Offset的模式 换成其余模式;
重置指定消费组的偏移量 --group
重置指定消费组的全部Topic的偏移量
--all-topic
sh bin/kafka-consumer-groups.sh --reset-offsets --to-earliest --group test2_consumer_group --bootstrap-server xxxx:9090 --dry-run --all-topic
重置指定消费组的指定Topic的偏移量--topic
sh bin/kafka-consumer-groups.sh --reset-offsets --to-earliest --group test2_consumer_group --bootstrap-server xxxx:9090 --dry-run --topic test2
重置全部消费组的偏移量 --all-group
重置全部消费组的全部Topic的偏移量
--all-topic
sh bin/kafka-consumer-groups.sh --reset-offsets --to-earliest --all-group --bootstrap-server xxxx:9090 --dry-run --all-topic
重置全部消费组中指定Topic的偏移量--topic
sh bin/kafka-consumer-groups.sh --reset-offsets --to-earliest --all-group --bootstrap-server xxxx:9090 --dry-run --topic test2
--reset-offsets
后面须要接重置的模式
相关重置Offset的模式
参数 | 描述 | 例子 |
---|---|---|
--to-earliest : |
重置offset到最开始的那条offset(找到还未被删除最先的那个offset) | |
--to-current : |
直接重置offset到当前的offset,也就是LOE | |
--to-latest : |
重置到最后一个offset | |
--to-datetime : |
重置到指定时间的offset;格式为:YYYY-MM-DDTHH:mm:SS.sss ; |
--to-datetime "2021-6-26T00:00:00.000" |
--to-offset |
重置到指定的offset,可是一般状况下,匹配到多个分区,这里是将匹配到的全部分区都重置到这一个值; 若是 1.目标最大offset<--to-offset , 这个时候重置为目标最大offset;2.目标最小offset>--to-offset ,则重置为最小; 3.不然的话才会重置为--to-offset 的目标值; 通常不用这个 |
--to-offset 3465 ![]() |
--shift-by |
按照偏移量增长或者减小多少个offset;正的为往前增长;负的日后退;固然这里也是匹配全部的; | --shift-by 100 、--shift-by -100 |
--from-file |
根据CVS文档来重置; 这里下面单独讲解 |
--from-file
着重讲解一下
上面其余的一些模式重置的都是匹配到的全部分区; 不可以每一个分区重置到不一样的offset;不过**
--from-file
**可让咱们更灵活一点;
格式为: Topic:分区号: 重置目标偏移量 cvs test2,0,100 test2,1,200 test2,2,300
2. 执行命令 >sh bin/kafka-consumer-groups.sh --reset-offsets --group test2_consumer_group --bootstrap-server xxxx:9090 --dry-run --from-file config/reset-offset.csv
delete-offsets
可以执行成功的一个前提是 消费组这会是不可用状态;
偏移量被删除了以后,Consumer Group下次启动的时候,会从头消费;
sh bin/kafka-consumer-groups.sh --delete-offsets --group test2_consumer_group2 --bootstrap-server XXXX:9090 --topic test2
相关可选参数
参数 | 描述 | 例子 |
---|---|---|
--bootstrap-server |
指定链接到的kafka服务; | --bootstrap-server localhost:9092 |
--list |
列出全部消费组名称 | --list |
--describe |
查询消费者描述信息 | --describe |
--group |
指定消费组 | |
--all-groups |
指定全部消费组 | |
--members |
查询消费组的成员信息 | |
--state |
查询消费者的状态信息 | |
--offsets |
在查询消费组描述信息的时候,这个参数会列出消息的偏移量信息; 默认就会有这个参数的; | |
dry-run |
重置偏移量的时候,使用这个参数可让你预先看到重置状况,这个时候尚未真正的执行,真正执行换成--excute ;默认为dry-run |
|
--excute |
真正的执行重置偏移量的操做; | |
--to-earliest |
将offset重置到最先 | |
to-latest |
将offset重置到最近 |
Kafka专栏持续更新中...(源码、原理、实战、运维、视频、面试视频)
【kafka运维】Kafka全网最全最详细运维命令合集(精品强烈建议收藏!!!)_石臻臻的杂货铺-CSDN博客
【kafka实战】分区重分配可能出现的问题和排查问题思路(生产环境实战,干货!!!很是干!!!建议收藏)
【kafka异常】kafka 常见异常处理方案(持续更新! 建议收藏)
【kafka运维】分区从分配、数据迁移、副本扩缩容 (附教学视频)
【kafka源码】ReassignPartitionsCommand源码分析(副本扩缩、数据迁移、副本重分配、副本跨路径迁移