一:概念
二:部署
使用kafka自带的zookeeper集群启动
(1)下载好kafka的包,并解压到/opt/kafka/目录下
tar zxvf kafka_2.11-2.2.1.tgz -C /opt/kafka
(2)启动自带的zookeeper(2181端口)
cd /opt/kafka/kafka_2.11-2.2.1/
bin/zookeeper-server-start.sh config/zookeeper.properties
(3)启动kafka(9092端口)
bin/kafka-server-start.sh -daemon config/server.properties
lsof -i :9092 (列出9092端口是否在使用)
(4)创建topic
bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic test1 --partitions 3 --replication-factor 1
其中:--partitions 3 //创建1个分区
--replications-factor 1 //复制一份
--topic //主题为test1
bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic test1 (查看topic的描述命令)
(5)创建生产者
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test1
(6) 创建消费者
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test1 --from-beginning
注:旧版本是 bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test1
原文:https://www.cnblogs.com/shuaifing/p/11023337.html