启动集群
依次在master、server01、server02节点上启动kafka
[www@master kafka]$ bin/kafka-server-start.sh config/server.properties &
[www@server01 kafka]$ bin/kafka-server-start.sh config/server.properties &
[www@server02 kafka]$ bin/kafka-server-start.sh config/server.properties &
关闭集群
[www@master kafka]$ bin/kafka-server-stop.sh stop
[www@server01 kafka]$ bin/kafka-server-stop.sh stop
[www@server02 kafka]$ bin/kafka-server-stop.sh stop
查看当前服务器中的所有topic
[www@master kafka]$ bin/kafka-topics.sh --zookeeper master:2181 --list
创建topic
[www@master kafka]$ bin/kafka-topics.sh --zookeeper master:2181 --create --replication-factor 1 --partitions 1 --topic second
选项说明:
–topic 定义topic名
–replication-factor 定义副本数
–partitions 定义分区数
删除topic
[www@master kafka]$ bin/kafka-topics.sh --zookeeper master:2181 --delete --topic first
发送消息
[www@master kafka]$ bin/kafka-console-producer.sh
–broker-list master:9092 --topic first
消费者
[www@server01 kafka]$ bin/kafka-console-consumer.sh
–zookeeper master:2181 --from-beginning --topic second
bin/kafka-console-consumer.sh --zookeeper master:2181 --from-beginning --topic first
查看某个Topic的详情
[www@master kafka]$ bin/kafka-topics.sh --zookeeper master:2181 --describe --topic first