kafka 安裝部署,使用教程

王聰聰發表於2018-03-22

kafka 安裝部署,使用教程

第1步:準備環境

1.centos 7 
2.jdk
3.zookeeper
複製程式碼

第2步:下載解壓kafka 安裝包:

Scala 2.11 點選下載

tar -xzf kafka_2.11-1.0.1.tgz

cd kafka_2.11-1.0.1
複製程式碼

第3步:啟動伺服器

⑴ .Kafka使用ZooKeeper,因此如果您還沒有ZooKeeper伺服器,您需要首先啟動ZooKeeper伺服器。您可以使用與kafka打包在一起的便捷指令碼來獲得快速且簡單的單節點ZooKeeper例項。
> bin/zookeeper-server-start.sh config/zookeeper.properties
[2013-04-22 15:01:37,495] INFO Reading configuration from: config/zookeeper.properties (org.apache.zookeeper.server.quorum.QuorumPeerConfig)
...

複製程式碼
⑵. 現在啟動Kafka伺服器:
> bin/kafka-server-start.sh config/server.properties
[2013-04-22 15:01:47,028] INFO Verifying properties (kafka.utils.VerifiableProperties)
[2013-04-22 15:01:47,051] INFO Property socket.send.buffer.bytes is overridden to 1048576 (kafka.utils.VerifiableProperties)
...
複製程式碼

第4步:建立一個主題

⑴ .我們用一個分割槽和一個副本建立一個名為“test”的主題:
> bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
複製程式碼
⑵. 如果我們執行list topic命令,我們現在可以看到該主題:
> bin/kafka-topics.sh --list --zookeeper localhost:2181
test 
或者,您也可以將代理配置為在釋出不存在的主題時自動建立主題,而不是手動建立主題。
複製程式碼

第5步:傳送一些訊息

⑴ .Kafka附帶一個命令列客戶端,它將從檔案或標準輸入中獲取輸入,並將其作為訊息傳送到Kafka叢集。預設情況下,每行將作為單獨的訊息傳送。
執行生產者,然後在控制檯中輸入幾條訊息傳送到伺服器。
> bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
This is a message
This is another message
複製程式碼

第6步:啟動消費者

卡夫卡也有一個命令列消費者,將訊息轉儲到標準輸出。
> bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
This is a message
This is another message
複製程式碼

遠端連線出現問題時修改下方配置檔案:confing/server.properties

kafka 安裝部署,使用教程

相關文章