1 启动
kafka-server-start.sh -daemon /opt/kafka_2.11-2.3.0/config/server.properties
要手动启动集群中的所有机器
2 查看topics列表
kafka-topics.sh --list --zookeeper hdp-01:2181,hdp-02:2181,hdp-03:2181
topics 的信息是保存在zookeeper里面的,所以重新安装kafka,之前的那些topics信息也会在
3 查看某个topic的信息
kafka-topics.sh --describe --zookeeper hdp-01:2181,hdp-02:2181,hdp-03:2181 --topic testTopic
topic信息是保存在zookeeper里面
4 创建topic
kafka-topics.sh --create --zookeeper hdp-01:2181,hdp-02:2181,hdp-03:2181 --replication-factor 3 --partitions 3 --topic testTopic
副本数量 <= broker数量,同个机器保存多分没意义
分区可以超过broker数量
5 topic写入
kafka-console-producer.sh --broker-list hdp-01:9092,hdp-02:9092,hdp-03:9092 --topic testTopic
命令行的生产者
生产者往Kafka里面写数据,只需要知道broker在哪里,不需要知道zookeeper在哪里
6 读取数据
kafka-console-consumer.sh --bootstrap-server hdp-01:9092,hdp-02:9092,hdp-03:9092 --topic testTopic --from-beginning
和旧版本不一样,旧版需要zookeeper,新版本需要brokerList