一、Kafka下載
下載地址:https://kafka.apache.org/downloads
二、Kafka安裝
因?yàn)檫x擇下載的是 .zip 文件,直接跳過(guò)安裝,一步到位。
選擇在任一磁盤(pán)創(chuàng)建空文件夾(不要使用中文路徑),解壓之后把文件夾內(nèi)容剪切進(jìn)去(本人選擇 D:\env-java\路徑下,即完成安裝)。
linux解壓命令tar -zxvf kafka_2.13-3.5.1.tgz
,linux環(huán)境下指令是在\kafka_2.13-3.5.1\bin
目錄。
windows直接解壓即可,windows環(huán)境下指令是在kafka_2.13-3.5.1\bin\windows
目錄。
注意:不同系統(tǒng)指令所在的目錄不同。
執(zhí)行命令當(dāng)前目錄D:\env-java\kafka_2.13-3.5.1
修改 kafka-server 和zookeeper配置
進(jìn)入到目錄:kafka_2.13-3.5.1/config/server.properties
以及kafka_2.13-3.5.1/config/zookeeper.properties
- linux系統(tǒng):
broker.id=1
log.dir=/Users/imagetask/kafka-logs
- windows系統(tǒng):
broker.id=1
log.dirs=/env-java/kafka_2.13-3.5.1/kafka-logs
/:表示當(dāng)前的根路徑,即D盤(pán)。沒(méi)有就會(huì)創(chuàng)建對(duì)應(yīng)的文件夾。
三、啟動(dòng)Kafka服務(wù)
1、啟動(dòng)ZooKeeper
- linux系統(tǒng):
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
- windows系統(tǒng):
bin\windows\zookeeper-server-start.bat config\zookeeper.properties
2、啟動(dòng)kafka
- linux系統(tǒng):
bin/kafka-server-start.sh config/server.properties
- windows系統(tǒng):
bin\windows\kafka-server-start.bat config\server.properties
四、Kafka的使用
1、創(chuàng)建主題
- linux系統(tǒng):
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
- windows系統(tǒng):
bin\windows\kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
2、刪除主題
- linux系統(tǒng):
bin/kafka-topics.sh --delete --bootstrap-server localhost:9092 --topic test
- windows系統(tǒng):
bin\windows\kafka-topics.bat --delete --bootstrap-server localhost:9092 --topic test
3、查看Topic 列表
- linux系統(tǒng):
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
- windows系統(tǒng):
bin\windows\kafka-topics.bat --list --bootstrap-server localhost:9092
4、啟動(dòng) Producer
- linux系統(tǒng):
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
- windows系統(tǒng):
bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic test
5、啟動(dòng) Consumer
- linux系統(tǒng):
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
- windows系統(tǒng):
bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning
6、查看Topic 相關(guān)信息(test)
- linux系統(tǒng):
bin/kafka-topics.sh --describe --bootstrap-server localhost:9092 --topic test
- windows系統(tǒng):
bin\windows\kafka-topics.bat --describe --bootstrap-server localhost:9092 --topic test
詳細(xì)了解可參考以下視頻:
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-647262.html
實(shí)用開(kāi)發(fā)篇-130-Kafka安裝文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-647262.html
到了這里,關(guān)于Kafka的下載安裝以及使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!