1. 程式人生 > >kafka常用命令總結

kafka常用命令總結

整理kafka相關的常用命令

建立主題(4個分割槽,2個副本)
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 4 --topic test
查詢叢集描述
bin/kafka-topics.sh --describe --zookeeper 
生產者
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
消費者
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test
新生產者(支援0.9版本+)
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test --producer.config config/producer.properties
新消費者(支援0.9版本+)
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --new-consumer --from-beginning --consumer.config config/consumer.properties
新消費者列表查詢(支援0.9版本+)
bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092 --list
顯示某個消費組的消費詳情(僅支援offset儲存在zookeeper上的)
bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zkconnect localhost:2181 --group test
顯示某個消費組的消費詳情(支援0.9版本+)
bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092 --describe --group test-consumer-group
平衡leader
bin/kafka-preferred-replica-election.sh --zookeeper zk_host:port/chroot
kafka自帶壓測命令
bin/kafka-producer-perf-test.sh --topic test --num-records 100 --record-size 1 --throughput 100  --producer-props bootstrap.servers=localhost:9092