目錄
一:準備
二:kafka的基本操作(命令列操作)
一:準備
1.安裝kafka
操作:kafka單機和集群(全分布)的安裝部署程序_一個人的牛牛的博客-CSDN博客
2.安裝zookeeper
操作:zookeeper單機和集群(全分布)的安裝程序_一個人的牛牛的博客-CSDN博客
3.啟動zookeeper
在zookeeper目錄下執行:
bin/zkServer.sh start
如果是集群每一臺都需要執行啟動命令!!
驗證: jps看到QuorumPeerMain行程就已經啟動成功!!!
4.啟動kafka(在kafka目錄下)(需要先啟動zookeeper)
bin/kafka-server-start.sh -daemon config/server.properties
如果是集群每一臺都需要執行啟動命令!!
驗證:jps查看行程都有kafka行程就啟動成功了1.!!!
二:kafka的基本操作(命令列操作)
1.查看當前服務器中的所有topic(在kafka目錄下)
kafka-topics.sh --zookeeper hadoop001:2181 --list
2.創建主題topic(在kafka目錄下)
如:test
bin/kafka-topics.sh --create --zookeeper hadoop001:2181 --replication-factor 1 --partitions 1 --topic test
如:second
bin/kafka-topics.sh --zookeeper hadoop001:2181 --create --replication-factor 1 --partitions 3 --topic second
3.洗掉topic(在kafka目錄下)
如:test
bin/kafka-topics.sh --zookeeper hadoop001:2181 --delete --topic test
需要server.properties中設定delete.topic.enable=true否則只是標記洗掉,
4.啟動控制臺生產者(在kafka目錄下)
如:test
bin/kafka-console-producer.sh --broker-list hadoop001:9092 --topic test
5.啟動控制臺消費者(在kafka目錄下)(需要另外打開一個終端)
如:test
bin/kafka-console-consumer.sh --bootstrap-server hadoop001:9092 --topic test --from-beginning
我們一般先運行消費者,再去運行生產者
topic為second發送訊息

topic為second消費訊息
6.查看某個topic的詳情(在kafka目錄下)
如:test
bin/kafka-topics.sh --zookeeper hadoop001:2181 --describe --topic test
7.修改磁區數(在kafka目錄下)
如:test
bin/kafka-topics.sh --zookeeper hadoop001:2181 --alter --topic test --partitions 6
8.說明:
hadoop001 我的主機名
2181 埠
--topic 定義topic名
--replication-factor 定義副本數
--partitions 定義磁區數
--from-beginning:會把主題中以往所有的資料都讀取出來
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/376996.html
標籤:其他
