启动zk集群
nohup bin/zookeeper-server-start.sh config/zookeeper.properties &
启动kafka集群
bin/kafka-server-start.sh config/server.properties &
创建topic
bin/kafka-topics.sh --create --zookeeper 192.1.x.x:2181,192.1.x.1:2181,192.1.x.3:2181 --replication-factor 3 --partitions 1 --topic my-replicated-topic
查看topic信息
bin/kafka-topics.sh --describe --zookeeper 192.1.x.x:2181,192.1.x.1:2181,192.1.x.3:2181 --topic my-replicated-topic
生产者生产消息
bin/kafka-console-producer.sh --broker-list 192.1.x.x:9092,192.1.x.1:9093,192.1.x.3:9092 --topic my-replicated-topic
从头开始消费消息
bin/kafka-console-consumer.sh --bootstrap-server 192.168.x.a:9092 --zookeeper 192.1.x.x:2181,192.1.x.1:2181,192.1.x.3:2181 --from-beginning --topic my-replicated-topic
重启kafka
sh kafka-server-start.sh ../config/server.properties &
sh kafka-server-stop.sh ../config/server.properties &
列出所有topic
./kafka-topics.sh --list --zookeeper 172.16.b.a:2181
查看指定topic的数据数量
./kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list 192.168.10.x:9092 --topic topic_name --time -1
zk删除topic
rmr /brokers/topics/topic_name
删除指定topic
./kafka-topics.sh --zookeeper 192.168.10.z:2181 --delete --topic topic_name
导出指定topic数据
./bin/kafka-console-consumer.sh --bootstrap-server 172.16.11.a:9092 --topic topic_name --from-beginning > topic_name.json
创建topic
./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 3 --topic topic_name
启动生产者
./kafka-console-producer.sh --broker-list localhost:9092 --topic test0919
启动消费
./kafka-console-consumer.sh --zookeeper 192.168.10.zx:2181 --topic topic_name --from-beginning
查看消费者ID
./kafka-consumer-groups.sh --zookeeper 192.168.10.a:2181 --list
查看指定消费者组情况
./kafka-consumer-groups.sh --bootstrap-server 192.168.100.a:9092,192.168.100.b:9092,192.168.100.c:9092 --group groupId_name --describe --new-consumer