kafka控制台命令总结
1、kafka查看topic有关的信息的命令
1.1查看kafka的topic列表,使用–list参数
bin/kafka-topics.sh --zookeeper [hostname/ip地址]:2181,[hostname/ip地址]:2181 --list
eg : bin/kafka-topics.sh --zookeeper ps-01:2181,ps02:2181 --list
参数说明:
- hostname/ip地址:这里要填zookeeper集群的配置
1.2 查看kafka的特定topic的详情,使用–topic和–describe参数
bin/kafka-topics.sh --zookeeper [hostname/ip地址]:2181,[hostname/ip地址]:2181 --describe --topic online_data
eg: bin/kafka-topics.sh --zookeeper ps-01:2181,ps02:2181 --describe --topic online_data
参数说明:
- PartitionCount:partition 个数
- ReplicationFactor:副本个数
- Partition:partition 编号,从 0 开始递增
- Leader:当前 partition 起作用的 breaker.id
- Replicas: 当前副本数据所在的 breaker.id,是一个列表,排在最前面的其作用
- Isr:当前 kakfa 集群中可用的 breaker.id 列表
2、控制台消费某个topic的消息
2.1 从 latest 位移位置开始消费该主题的所有分区消息,即仅消费正在写入的消息
bin/kafka-console-consumer.sh --bootstrap-server [ hostname/ip:9092, hostname/ip:9092] --topic [topicname]
eg:bin/kafka-console-consumer.sh --bootstrap-server ps-01:9092,ps02:9092 --topic online_data
参数说明:
- hostname/ip :kafka集群的ip或主机名
- topicname :要消费的哪个topic的主题名称
2.2 表示从指定主题中有效的起始位移位置开始消费所有分区的消息
bin/kafka-console-consumer.sh --bootstrap-server [ip01:9092,ip02:9092] --topic [topicName] --from-beginning
eg :bin/kafka-console-consumer.sh --bootstrap-server ps-01:9092,ps02:9092 --topic online_data --from-beginning
参数说明:
- [ip01:9092,ip02:9092] :kafka集群的ip和kafka客户端端口
- [topicName]:需要消费的主题名称
- –from-beginning:表示从头开始消费当前topic里面的消息