官網(wǎng)
安裝
-
is recommended 是推薦版本
安裝圖
配置文件
- 修改conf目錄下的server.properties
vim server.properties
進(jìn)入文件目錄
- 修改主機(jī)名稱(chēng)慨蛙、端口號(hào)你弦、zookeeper
host.name=hzh
port=9092
zookeeper.connect=hzh:2181
服務(wù)器名豆混、端口號(hào)
-
配置zookeeper。因?yàn)槭菃喂?jié)點(diǎn)鹰服,所以只需要配置一個(gè)就行了
Zookeeper
啟動(dòng)
- 先啟動(dòng)zookeeper
bin/zkServer.sh start
- 啟動(dòng)kafka
bin/kafka-server-start.sh -daemon ./config/server.properties
啟動(dòng)Kafka
測(cè)試
- 測(cè)試纲辽,創(chuàng)建一個(gè)topic祈纯。
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test1
創(chuàng)建
- 查看
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test1
查看
- 啟動(dòng)console生產(chǎn)者
bin/kafka-console-producer.sh --broker-list hzh:9092 --topic test1
生產(chǎn)者
- 啟動(dòng)console消費(fèi)者
bin/kafka-console-consumer.sh --bootstrap-server hzh:9092 --topic test1
消費(fèi)者
可能錯(cuò)誤糠爬,在部分教程中會(huì)用到 --zookeeper
Exception in thread "main" joptsimple.UnrecognizedOptionException: zookeeper is not a recognized option
錯(cuò)誤截圖
解決原文
這是因?yàn)榘惭b的kafka版本過(guò)高轧邪,2.8+的kafka刽脖,已經(jīng)不需要依賴(lài)zookeeper來(lái)創(chuàng)建topic,新版本使用 --bootstrap-server 參數(shù)忌愚。
#創(chuàng)建主題
bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic my-topic --partitions 1
#查看主題
bin/kafka-topics.sh --list --bootstrap-server localhost:9092