切换到kafka目录
cd ~/kafka
启动和停止Kafka服务
bin/kafka-server-start.sh config/server.properties
bin/kafka-server-stop.sh
nohup bin/kafka-server-start.sh config/server.properties >/dev/null 2>&1 &
主题管理
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic my-topic
bin/kafka-topics.sh --list --zookeeper localhost:2181
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-topic
生产者和消费者
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic my-topic
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic my-topic --from-beginning
消费者组管理
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-group
消息生产和消费
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic my-topic
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic my-topic --from-latest
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic my-topic --from-beginning
消息查看和删除
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic my-topic --partition 0 --offset 0 --max-messages 10
bin/kafka-delete-records.sh --bootstrap-server localhost:9092 --topic my-topic --offset-json-file delete.json
分区和副本管理
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-topic
bin/kafka-topics.sh --alter --zookeeper localhost:2181 --topic my-topic --partitions 3
bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --topics-to-move-json-file topics-to-move.json --broker-list "1,2,3" --generate