kafka常用基本命令
-
启动kafka命令
bin/kafka-server-start.sh config/server.properties & -
停止命令:
./bin/kafka-server-stop.sh,或者 ps -ef |grep kafka|grep -v grep|awk ‘{print $2}’ |xargs kill -9 -
创建topic
./bin/kafka-topic.sh --create --bootstrap-server IP:9092 [–relication-factor 3] [–partition 3] --topic test
可选: [–relication-factor 3] 副本数量,数量应该少于等于节点数
[–partition 3] 分区数量,分区相当于工作区域。不通的分区不同的工作内容。 -
删除topic
./bin/kafka-topic.sh --bootstrap-server IP:9092 --delete --topic test
删除topic 慎用,删除后这个分区的消费队列也没了。 -
查询topic
查看服务器上topic列表 ./bin/kafka-topic.sh --bootstrap-server IP:9092 --list
查询topic是test的详细信息
./bin/kafka-topic.sh --bootstrap-server IP:9092 --describe --topic test -
查看消费者组
./bin/kafka-consumer-groups.shh --bootstrap-server IP地址:9092 --list -
查看指定消费者组的 消费偏移量
./bin/kafka-consumer-groups.sh --bootstrap-server IP地址:9092 --describe --group test
current-offset:目前已经消费的位置
log-end-offset: 消费组 当前所有的消息
-
查看指定消费偏移量的消息内容
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --partition 0 --offset 100
–partition 分区数量,指定查看偏移量一定要有分区
–offset 偏移量的指定
这个命令是从 偏移量开始在界面展示,想要看那一条,执行完看到界面有回显就要ctrl +c 终止命令。 -
查看历史消费信息
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
从kafka 重启只有开始的消费内容 -
kafka界面化工具 kafka-map
可以安装kafkamap这个工具进行监控kafka的消息队列