kafka 安裝與配置


下載

地址:https://kafka.apache.org/downloads

這里下載的是kafka_2.11-0.11.0.1.tgz

解壓

tar -xzf kafka_2.11-0.11.0.1.tgz
cd kafka_2.11-0.11.0.1

啟動zookeeper

$ bin/zookeeper-server-start.sh config/zookeeper.properties

默認使用的2181端口,可在配置文件修改。

啟動kafka server

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

(非本地生產者和消費者訪問Kafka,記得修改 config/server.properties中的listeners, 例如
listeners=PLAINTEXT://192.168.33.152:9092)

create a topic

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

查看topic

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

好像沒有輸出

啟動生產者

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

輸入

This is a message
This is another message

啟動消費者

$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
This is a message
This is another message

如果無法啟動,根據提示,可能需要加zookeeper:

$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --zookeeper localhost:2181 --topic test --from-beginning

參考

kafka官網
https://kafka.apache.org/
https://kafka.apache.org/quickstart


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM