方便日常使用:
1.kafka启动: ./kafka-server-start.sh -daemon ../config/server.properties
2.创建topic: ./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic tes
3.查看kafka的topic:./kafka-topics.sh --zookeeper master:2181 --list
4.查看kafka某个topic下partition信息: ./kafka-topics.sh --describe --zookeeper master:2181 --topic test-topic
5.查看kafka的指定topic: ./kafka-topics.sh --zookeeper master:2181 --describe --topic yq20171220
6.控制台向kafka生产数据: ./kafka-console-producer.sh --broker-list hadoop001:9092 --topic jason_20180519
7.控制台消费kafka的数据: ./kafka-console-consumer.sh --bootstrap-server hadoop001:9092 --topic jason_20180519 --from-beginning
8.查看topic下某分区偏移量的最小值: ./kafka-run-class.sh kafka.tools.GetOffsetShell --topic test-topic --time -1 --broker-list master:9092 --partitions 0
9.增加topic的partition:/kafka-topics.sh --alter --topic jason_20180519 --zookeeper 10.200.10.24:2181,10.200.10.26:2181,10.200.10.29:2181 --partitions 5
10.删除topic,慎用,只会删除zookeeper中的元数据,消息文件须手动删除: ./kafka-run-class.sh kafka.admin.DeleteTopicCommand --zookeeper master:2181 --topic yq20171220
11.彻底删除topic: rmr /brokers/topics/【topic name】即可
其中:
创建topic时,partitions 分区数量,会均匀的分布在broker上 ,replication-factor 副本数量,不能超过broker的数量
参考:https://www.cnblogs.com/lgjlife/p/10569187.html
Zookeeper命令:
ZooKeeper服务命令:
1. 启动ZK服务: sh bin/zkServer.sh start
2. 查看ZK服务状态: sh bin/zkServer.sh status
3. 停止ZK服务: sh bin/zkServer.sh stop
4. 重启ZK服务: sh bin/zkServer.sh restart