bin/kafka-list-topic.sh --zookeeper 192.168.197.170:2181,192.168.197.171:2181 (列出所有topic的分区情况)
bin/kafka-list-topic.sh --zookeeper 192.168.197.170:2181,192.168.197.171:2181 --topic test (查看test的分区情况)
bin/kafka-create-topic.sh   --replica 2 --partition 8 --topic test  --zookeeper 192.168.197.170:2181,192.168.197.171:2181


bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic eee


这个命令可以分区指定到想要的--broker-list上
bin/kafka-reassign-partitions.sh --topics-to-move-json-file topics-to-move.json --broker-list "171"


##为Topic增加 partition数目kafka-add-partitions.sh
bin/kafka-add-partitions.sh --topic test --partition 2  --zookeeper  192.168.197.170:2181,192.168.197.171:2181 (为topic test增加2个分区)




##控制台接收消息
bin/kafka-console-consumer.sh --zookeeper  192.168.197.170:2181,192.168.197.171:2181  --from-beginning --topic test


##控制台发送消息
bin/kafka-console-producer.sh --broker-list  192.168.197.170:9092,192.168.197.171: 9092    --topic test 


##删除topic,慎用,只会删除zookeeper中的元数据,消息文件须手动删除
bin/kafka-run-class.sh kafka.admin.DeleteTopicCommand --topic test666 --zookeeper 192.168.197.170:2181 ,192.168.197.171:2181




4.    命令


1.  启动Server


Kafka 依赖 ZK 服务


nohup bin/kafka-server-start.sh config/server.properties &


2.  创建Topic


bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 3 --topic page_visits


3.  查看命令


bin/kafka-topics.sh --list --zookeeper localhost:2181


4.  发送消息


bin/kafka-console-producer.sh --broker-list localhost:9092 --topic page_visits


5.  消费消息


bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic page_visits --from-beginning


6.  多 Broker 方式


bin/kafka-server-start.sh config/server-1.properties &


bin/kafka-server-start.sh config/server-2.properties &


bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic visits


bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic visits


bin/kafka-console-producer.sh --broker-list localhost:9092 --topic visits


bin/kafka-console-consumer.sh --zookeeper localhost:2181 --from-beginning --topic visits


7.  停止服务


pkill -9 -f config/server.properties


8.       删除无用的topic


bin/kafka-run-class.sh kafka.admin.DeleteTopicCommand --topic visits --zookeeper sjxt-hd02:2181,sjxt-hd03:2181,sjxt-hd04:2181


 
Logo

Kafka开源项目指南提供详尽教程,助开发者掌握其架构、配置和使用,实现高效数据流管理和实时处理。它高性能、可扩展,适合日志收集和实时数据处理,通过持久化保障数据安全,是企业大数据生态系统的核心。

更多推荐