阿川CH
学海无涯,上栽上栽!
Toggle navigation
阿川CH
主页
归档
标签
Kafka常用排查命令
Kafka
常用操作
2018-03-09 17:43:21
1
0
0
cqc
Kafka
常用操作
# Kafka常用排查命令 Kafka有新旧Consumer Api之分,旧的ConsumerApi提交的组信息及offset是存放在zookeeper中的, 而由于zookeeper并不适合频繁的大批量写入操作,所以在新的ConsumerApi的设计中, 新建了一个`__consumer_offsets`Topic用于存放新ConsumerApi提交的组信息及offset。 所以现在有了新旧Api之分,旧的提交上来的还是存在zookeeper中。 kafka提供的工具脚本中和Consumer相碰的都有个选项`--new-consumer`, 用以区分新旧Api。 ### 查看所有组信息 ```bash # 新版 ./kafka-consumer-groups.sh --list --bootstrap-server xxx:9092 --new-consumer newgrp # 旧版 ./kafka-consumer-groups.sh --list --zookeeper xxx:2181 console-consumer-54503 console-consumer-27065 console-consumer-1686 ``` ### 查看指定组的偏移信息 ```bash # 新版 ./kafka-consumer-groups.sh --describe --bootstrap-server xxx:9092 --new-consumer --group newgrp GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG OWNER newgrp topicname 0 40054927 40054927 0 consumer-1_/10.28.38.222 newgrp topicname 1 43599415 43599415 0 consumer-1_/10.28.38.222 newgrp topicname 2 40092386 40092386 0 consumer-1_/10.28.38.222 newgrp topicname 3 42575063 42575063 0 consumer-1_/10.28.38.222 newgrp topicname 4 40138115 40138115 0 consumer-1_/10.28.38.222 # 旧版 ./kafka-consumer-groups.sh --describe --zookeeper datacenter-test-1:2181 --group console-consumer-1686 ``` ### 查看Topic的分布情况 ``` ./kafka-topics.sh --describe --zookeeper datecenter1:2181 --topic userAction Topic:userAction PartitionCount:12 ReplicationFactor:1 Configs: Topic: userAction Partition: 0 Leader: 0 Replicas: 0 Isr: 0 Topic: userAction Partition: 1 Leader: 1 Replicas: 1 Isr: 1 Topic: userAction Partition: 2 Leader: 2 Replicas: 2 Isr: 2 Topic: userAction Partition: 3 Leader: 3 Replicas: 3 Isr: 3 Topic: userAction Partition: 4 Leader: 0 Replicas: 0 Isr: 0 Topic: userAction Partition: 5 Leader: 1 Replicas: 1 Isr: 1 Topic: userAction Partition: 6 Leader: 2 Replicas: 2 Isr: 2 Topic: userAction Partition: 7 Leader: 3 Replicas: 3 Isr: 3 Topic: userAction Partition: 8 Leader: 0 Replicas: 0 Isr: 0 Topic: userAction Partition: 9 Leader: 1 Replicas: 1 Isr: 1 Topic: userAction Partition: 10 Leader: 2 Replicas: 2 Isr: 2 Topic: userAction Partition: 11 Leader: 3 Replicas: 3 Isr: 3 ``` ** 旧版类似,后面只讨论新版的用法** ### 删除偏移信息 ```bash # 删除指定组的所有offset信息 ./kafka-consumer-groups.sh --delete --bootstrap-server datacenter-test-1:9092 --new-consumer --group group1 --group group2 # 删除指定topic的所有组的offset信息 ./kafka-consumer-groups.sh --delete --bootstrap-server datacenter-test-1:9092 --new-consumer --topic topicname # 删除指定topic下指定组的offset信息 ./kafka-consumer-groups.sh --delete --bootstrap-server datacenter-test-1:9092 --new-consumer --topic topicname --group group1 ``` ### 查看__consumer_offsets Topic内容 ```bash # 在0.10版本以后的版本,formatter使用kafka.coordinator.group.GroupMetadataManager\$OffsetsMessageFormatter ./kafka-console-consumer.sh --bootstrap-server datecenter6:9092 --new-consumer --topic __consumer_offsets --formatter "kafka.coordinator.GroupMetadataManager\$OffsetsMessageFormatter" ``` ## 参考 [Kafka 如何读取offset topic内容 (__consumer_offsets)](http://www.cnblogs.com/huxi2b/p/6061110.html)
上一篇:
shell变量操作
下一篇:
lsof用法
文档导航