kafka常用命令
1.启动Zookeeper
./bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
2.启动kafka
./bin/kafka-server-start.sh -daemon config/server.properties
3.创建主题
(1)单机
./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
(2)集群
./bin/kafka-topics.sh --create --zookeeper 192.168.108.240:2181,192.168.108.241:2181,192.168.108.242:2181 --replication-factor 3 --partitions 3 --topic emqtest
3.查看主题
./bin/kafka-topics.sh --list --zookeeper localhost:2181
./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test
4.生产者
./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
./bin/kafka-console-producer.sh --broker-list 192.168.108.240:9092,192.168.108.241:9092,192.168.108.242:9092 --topic emqtest
5.消费者
./bin/kafka-console-consumer.sh --zookeeper 192.168.108.240:2181 --topic emqtest --from-beginning
./bin/kafka-console-consumer.sh --bootstrap-server localhost:2181 --topic emqtest --from-beginning
6.结束(先关kafka)
./bin/kafka-server-stop.sh
./bin/zookeeper-server-stop.sh
7.根据group查看kafka消费情况
./bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server 192.168.108.240:9092 --describe --group sit_mon
8.修改topic信息(分区)
./bin/kafka-topics.sh --alter --zookeeper 192.168.108.240:2181 --topic sit_mon --partitions 24
er 192.168.108.240:2181 --topic sit_mon --partitions 24