zl程序教程

您现在的位置是:首页 >  大数据

当前栏目

【kafka】常用命令汇总

Kafka 汇总 常用命令
2023-09-11 14:17:08 时间

查询

1.查看所有或者指定Topic的信息

查看Topic的分区情况 副本情况和 配置情况

## 所有
bin/kafka-topics.sh --describe --zookeeper xxxx 

##指定
bin/kafka-topics.sh --describe --zookeeper xxxx --topic TOPIC名称

输出

[root@ kafka]# bin/kafka-topics.sh --describe --zookeeper xxx.xx.xx.xx --topic SHI_TOPIC3
Topic:SHI_TOPIC3	PartitionCount:3	ReplicationFactor:1	Configs:cleanup.policy=compact
	Topic: SHI_TOPIC3	Partition: 0	Leader: 0	Replicas: 0	Isr: 0
	Topic: SHI_TOPIC3	Partition: 1	Leader: 2	Replicas: 2	Isr: 2
	Topic: SHI_TOPIC3	Partition: 2	Leader: 1	Replicas: 1	Isr: 1

2.列出所有Topic

## topic列表查询
bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --list

## topic列表查询(支持0.9版本+)
bin/kafka-topics.sh --list --bootstrap-server localhost:9092

3.新消费者列表查询

## 新消费者列表查询(支持0.9版本+)
bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092 --list

## 新消费者列表查询(支持0.10版本+)
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list

输出

[root@]# bin/kafka-consumer-groups.sh --bootstrap-server xxx.xxx.xxx --list
Note: This will not show information about old Zookeeper-based consumers.
consumer-id
consumer-id1
BASE-DEMO

4.显示某个消费组的消费详情(0.10.1.0版本+)

查看某个消费者有多少消费者,消费哪些Topic; 消费者分别消费哪个分区等等信息;并且消费到的位置offset

bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-group

输出

[root@dev5_172_16_10_62 kafka]# bin/kafka-consumer-groups.sh --bootstrap-server  xxxx --describe --group consumer-id7
Note: This will not show information about old Zookeeper-based consumers.


TOPIC                          PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG        CONSUMER-ID                                       HOST                           CLIENT-ID
SHI_TOPIC3                     0          128             128             0          myClientId7-0-c6568666-b249-491a-a1e2-c3bd85f343c6/172.16.14.37                  myClientId7-0
SHI_TOPIC4                     0          0               0               0          myClientId7-0-c6568666-b249-491a-a1e2-c3bd85f343c6/172.16.14.37                  myClientId7-0

TODO