您好,登錄后才能下訂單哦!
本篇內容介紹了“Kafka安裝部署方法及簡單命令”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
本例使用單機集群方式,在本地啟用三份程序組成集群, 使用一個Zookeeper集群。
需要
1.安裝JDK8 Deepin 安裝jdk1.8
2.配置Zookeeper集群,參見 Zookeeper單機為偽集群
地址: http://kafka.apache.org/downloads.html
tar -zxvf kafka_2.12-2.7.0.tgz -C /usr/local/kafka/
/usr/local/kafka/kafka01
broker.id=0 #broker的id 每個節點一個不能重復,本例中三個節點分別為0,1,2 delete.topic.enable=true #開啟刪除topic功能## host.name=127.0.0.1 #本機名或者ip port=9091 #默認為9092 每個id內Kakfa服務器監聽的端口 log.dirs=/usr/local/kafka/kafka01/logs #日志存放路徑 zookeeper.connect=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183 #zookeeper連接端口
kafka02/config/server.properties
broker.id=1 #broker的id 每個節點一個不能重復,本例中三個節點分別為0,1,2 delete.topic.enable=true #開啟刪除topic功能## host.name=127.0.0.1 #本機名或者ip port=9092 #默認為9092 每個id內Kakfa服務器監聽的端口 log.dirs=/usr/local/kafka/kafka02/logs #日志存放路徑 zookeeper.connect=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183 #zookeeper連接端口
kafka03/config/server.properties
broker.id=2 #broker的id 每個節點一個不能重復,本例中三個節點分別為0,1,2 delete.topic.enable=true #開啟刪除topic功能## host.name=127.0.0.1 #本機名或者ip port=9093 #默認為9092 每個id內Kakfa服務器監聽的端口 log.dirs=/usr/local/kafka/kafka03/logs #日志存放路徑 zookeeper.connect=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183 #zookeeper連接端口
先啟動zookeeper集群
/usr/local/zookeeper/zookeeper01/bin/zkServer.sh start /usr/local/zookeeper/zookeeper02/bin/zkServer.sh start /usr/local/zookeeper/zookeeper03/bin/zkServer.sh start
再啟動kafka集群
root@bluejay-PC:/# /usr/local/kafka/kafka01/bin/kafka-server-start.sh -daemon /usr/local/kafka/kafka01/config/server.properties root@bluejay-PC:/# /usr/local/kafka/kafka02/bin/kafka-server-start.sh -daemon /usr/local/kafka/kafka02/config/server.properties root@bluejay-PC:/# /usr/local/kafka/kafka03/bin/kafka-server-start.sh -daemon /usr/local/kafka/kafka03/config/server.properties
root@bluejay-PC:/# /usr/local/kafka/kafka01/bin/kafka-server-stop.sh root@bluejay-PC:/# /usr/local/kafka/kafka02/bin/kafka-server-stop.sh root@bluejay-PC:/# /usr/local/kafka/kafka03/bin/kafka-server-stop.sh
1. 創建topic
root@bluejay-PC:/# /usr/local/kafka/kafka03/bin/kafka-topics.sh --create --zookeeper 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183 --replication-factor 1 --partitions 1 --topic first Created topic first.
2. 查看當前服務器中的所有 topic
root@bluejay-PC:/# /usr/local/kafka/kafka03/bin/kafka-topics.sh --list --zookeeper 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183 first
3. 消費消息-開啟監聽
root@bluejay-PC:/# /usr/local/kafka/kafka01/bin/kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9091 --topic first
4. 發送消息
root@bluejay-PC:/# /usr/local/kafka/kafka03/bin/kafka-console-producer.sh --broker-list 127.0.0.1:9091 --topic first >hello world >atguigu atguigu >zhanghl^H^H^H >end > >^C
5. 查看某個Topic的詳情
root@bluejay-PC:/# /usr/local/kafka/kafka01/bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --describe --topic first Topic: first PartitionCount: 1 ReplicationFactor: 1 Configs: Topic: first Partition: 0 Leader: 2 Replicas: 2 Isr: 2
6. 修改分區數
root@bluejay-PC:/# /usr/local/kafka/kafka01/bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --alter --topic first --partitions 6 WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected Adding partitions succeeded!
7. 刪除topic
root@bluejay-PC:/# /usr/local/kafka/kafka01/bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --delete --topic first
“Kafka安裝部署方法及簡單命令”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。