Kafka集群 版本:V3.5.1
名稱 | Node1 | Node2 | Node3 |
---|---|---|---|
IP | 172.29.145.157 | 172.29.145.182 | 172.29.145.183 |
(1)查看Kraft集群中的狀態(tài)以及Leader節(jié)點,投票節(jié)點
使用--status可以查看集群選舉次數(shù)/水位線以及投票節(jié)點等
使用--replication可以查看Ledaer和Follower分布
使用kafka-metadata-quorum.sh
./kafka-metadata-quorum.sh --bootstrap-server 172.29.145.157:9092,172.29.145.182:9092,172.29.145.183:9092 describe --replication
./kafka-metadata-quorum.sh --bootstrap-server 172.29.145.157:9092,172.29.145.182:9092,172.29.145.183:9092 describe --status
(2)查看Kraft集群中的Topic
使用--list可以查看所有的topic
使用--describe --topic topicname可以查看指定topic的分區(qū)狀態(tài)和副本同步狀態(tài)
使用kafka-topics.sh
./kafka-topics.sh --list --bootstrap-server 172.29.145.157:9092,172.29.145.182:9092,172.29.145.183:9092
./kafka-topics.sh --describe --bootstrap-server 172.29.145.157:9092,172.29.145.182:9092,172.29.145.183:9092 --topic test-topic1
(3)啟動與關閉Kraft集群
啟動集群時一定需要添加--daemon參數(shù)以后臺守護進程運行
使用kafka-server-start.sh
使用kafka-server-stop.sh
./kafka-server-start.sh -daemon ../config/kraft/server.properties
啟動后可以使用jps來查看kafka集群是否啟動成功
關閉集群也需要加上參數(shù)server.properties./kafka-server-stop.sh ../config/kraft/server.properties
(4)測試集群性能
使用kafka-producer-perf-test.sh生產(chǎn)數(shù)據(jù)
使用kafka-consumer-perf-test.sh消費數(shù)據(jù)
./kafka-producer-perf-test.sh --producer-props bootstrap.servers=172.29.145.157:9092,172.29.145.182:9092,172.29.145.183:9092 --topic test-topic1 --num-records 1000000 --record-size 4096 --throughput 50000
--topic指定topic
--num-records指定生產(chǎn)者產(chǎn)生的消息數(shù)量
--record-size指定一條消息的大小KB為單位
--throughput指定生產(chǎn)者每秒寫入的消息數(shù)量限制(吞吐量),-1則為不限制
反饋的指標是生產(chǎn)者發(fā)送了一百萬條消息,每秒生產(chǎn)消息15377條(生產(chǎn)速率60MB/s),平均時延394毫秒,后續(xù)就是各種時延的分布范圍
./kafka-consumer-perf-test.sh --topic test-topic1 --messages 1000000 --fetch-size 40000 --broker-list 172.29.145.157:9092,172.29.145.182:9092,172.29.145.183:9092
使用--topic指定topic
使用--messages指定需要消費的消息數(shù)量
使用--fetch-size指定一次獲取的消息總大小
使用broker-list來指定消費的broker
反饋的指標是 Kafka集群消費100萬條消息用時23秒,消息總大小3906MB,平均每秒消費速率168MB,消息總數(shù)量1000015條,每秒消費消息數(shù)量43185條
(5)命令行驗證生產(chǎn)實時消費
使用kafka-console-producer.sh實時生產(chǎn)消息
使用kafka-console-consumer.sh實時消費消息
./kafka-console-producer.sh --bootstrap-server 172.29.145.157:9092,172.29.145.182:9092,172.29.145.183:9092 --topic test-topic2
./kafka-console-consumer.sh --bootstrap-server 172.29.145.157:9092,172.29.145.182:9092,172.29.145.183:9092 --topic test-topic2
同時在Kafka管控平臺上也能夠實時查詢到test-topic2上的消息
同時我們也可以指定offset來使消費者從指定offset開始消費,對于生產(chǎn)環(huán)境有利于故障恢復./kafka-console-consumer.sh --bootstrap-server 172.29.145.157:9092,172.29.145.182:9092,172.29.145.183:9092 --topic test-topic2 --partition 1 --offset 2
可以看到由于輸入的消息key相同所以消息都分到了partition1上,所以在消費消息時需要指定分區(qū)partition1,然后指定offset消息位移量2,就可以讀取到offset=2對應的消息3以及之后的所有消息了
(6)查詢消費者組信息
使用kafka-consumer-groups.sh
./kafka-consumer-groups.sh --bootstrap-server 172.29.145.157:9092,172.29.145.182:9092,172.29.145.183:9092 --list
./kafka-consumer-groups.sh --bootstrap-server 172.29.145.157:9092,172.29.145.182:9092,172.29.145.183:9092 --group perf-consumer-91301 --describe
通過--list查詢到消費者組列表再通過--describe查詢具體信息
可以看到在test-topic1主題上的partition5和partition0的Lag為18,代表著兩個分區(qū)還有18條消息沒有消費,通過kafka-console-consumer.sh嘗試消費partition5的剩余18條消息./kafka-console-consumer.sh --bootstrap-server 172.29.145.157:9092,172.29.145.182:9092,172.29.145.183:9092 --topic test-topic1 --group perf-consumer-91301
ps:很多很多消息,因為輸入的時候一條消息的大小由--record-size決定,設置為4096KB...
此時再通過describe查看消費者組情況看在partition5和partition0上是否還有消息Lag文章來源:http://www.zghlxwxcb.cn/news/detail-710838.html
可以看到消息都消費完了,Lag也已為0,再執(zhí)行相同的命令只會等待而不會繼續(xù)輸出消息文章來源地址http://www.zghlxwxcb.cn/news/detail-710838.html
到了這里,關于Kraft模式下Kafka腳本的使用的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!