kafka基本使用

啓動服務

bin/zookeeper-server-start.sh -daemon config/zookeeper.propertiesshell

bin/kafka-server-start.sh -daemon config/server.properties日誌

關閉服務

bin/zookeeper-server-stop.shcode

bin/kafka-server-stop.shserver

建立topic

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

刪除topic

bin/kafka-topics.sh --delete --topic test --zookeeper localhost:2181kafka

查看topic列表

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

查看topic信息

bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic testit

說明:io

「Leader」: 是負責給定分區的全部讀取和寫入的節點。 每一個節點將成爲分區隨機選擇部分的領導者。如上面表示節點0爲test的leaderconsole

「Replicas」: 是複製此分區日誌的節點列表,不管它們是不是領導者,或者即便他們當前處於活動狀態。如上面表示當前總共只有一個節點0

「Isr」: 是一組「同步」副本。這是複製品列表的子集,當前活着並被引導到領導者。

生產消息

指明當前數據要流向哪一個broker,以及哪一個topic

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

消費消息

--from-beginning表示從頭開始讀取全部數據

bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning`

查看zk當前有幾個broker

bin/zookeeper-shell.sh localhost:2181

ls /brokers/ids

相關文章
相關標籤/搜索