进入到kafka的bin目录下
1、实时消费消息内容
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic_name --from-beginning
2、控制台向topic发送消息
./kafka-console-producer.sh --broker-list localhost:9092 --topic topic_name
3、 查看主题列表
./kafka-topics.sh --zookeeper localhost:2181 --list
更多详细内容看下
创建topic
./kafka-topics.sh --create --topic test1 --replication-factor 2 --partitions 3 --zookeeper hbp001:2181
增加partition
./kafka-topics.sh --zookeeper node01:2181 --alter --topic t_cdr --partitions 10
查看指定topic信息
./kafka-topics.sh --zookeeper hbp201:2181 --describe --topic t_cdr
查看topic某分区偏移量最大(小)值
./kafka-run-class.sh kafka.tools.GetOffsetShell --topic hive-mdatabase-hostsltable --time -1 --broker-list node86:9092 --partitions 0
注: time为-1时表示最大值,time为-2时表示最小值
增加topic分区数
为topic t_cdr 增加到10个分区
./kafka-topics.sh --zookeeper hbp201:2181 --alter --topic t_cdr --partitions 10
删除topic
慎用,只会删除zookeeper中的元数据,消息文件须手动删除
./kafka-run-class.sh kafka.admin.DeleteTopicCommand --zookeeper hbp201:2181 --topic t_cdr
查看consumer组内消费的offset
./kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper localhost:2181 --group test --topic testKJ1
./kafka-consumer-offset-checker.sh --zookeeper 192.168.0.201:2181 --group group1 --topic group1
查看kafka某分区日志具体内容
./kafka-run-class.sh kafka.tools.DumpLogSegments -files /tmp/kafka-logs/test3-0/00000000000000000000.log -print-data-log
.获取正在消费的topic的group的offset
./kafka-consumer-groups.sh --new-consumer --describe --group test6 --bootstrap-server hbp201:9092
显示消费者
./kafka-consumer-groups.sh --bootstrap-server hdh56:9092,hdh57:9092,hdh58:9092 --list --new-consume
kafka自带压测命令
./kafka-producer-perf-test.sh --topic test5 --num-records 100000 --record-size 1 --throughput 100 --producer-props bootstrap.servers=hbp001:9092
平衡leader
./kafka-preferred-replica-election.sh --zookeeper zk_host:port/chroot
本文已参与「新人创作礼」活动,一起开启掘金创作之路