20-kafka生產(chǎn)環(huán)境搭建之核心參數(shù)詳解
- borker.id
- log.dirs:日志存儲(chǔ)目錄(可以多個(gè)目錄蛾方,使用逗號(hào)分隔啄育,可以多磁盤提高效率)
- zookeeper.connect:
- listeners:默認(rèn)9092罩润,沒必要改
- delete.topic.enable:允許刪除topic默認(rèn)true
- num.network.threads:processor線程數(shù) 默認(rèn)3赫舒,建議調(diào)到6-9
- num.io.threads:handlerrequestPool線程數(shù),默認(rèn)8唐全,建議32
- log.retention.hours:kafka數(shù)據(jù)生命周期埃跷,默認(rèn)7天(可以少點(diǎn)蕊玷,如3天之內(nèi))
- log.flush.interval.ms:os cache 刷新到磁盤的時(shí)間間隔,默認(rèn)1s弥雹,(太頻繁了)
- log.flush.interval.messages:os cache 刷新到磁盤的條數(shù)垃帅,默認(rèn)1萬
- message.max.bytes :broker能接收的最大消息大小,默認(rèn)977k,太小了剪勿,建議改成10M或更大
- min.insync.replicas:默認(rèn)是1贸诚,producer向leader發(fā)送數(shù)據(jù)的時(shí)候,通過
request.required.acks
設(shè)置數(shù)據(jù)可靠性的級別
1(默認(rèn)):producer 在 ISR 中的 leader 成功接收到數(shù)據(jù)并得到確認(rèn)后厕吉,發(fā)送下一條message.
0:producer 不等待任何確認(rèn)消息赦颇,直接發(fā)送下面的message。效率高赴涵,可靠性低
-1:producer 等待 ISR 中的所有 follower 都確認(rèn)接收到數(shù)據(jù)后才發(fā)送下一條《┧希可靠性最高髓窜,但也不能保證不丟數(shù)據(jù)。比如ISR只有l(wèi)eader時(shí)(follower超過10秒沒有向leader同步數(shù)據(jù)欺殿,就會(huì)從ISR中移除)寄纵。
21-kafka生產(chǎn)環(huán)境搭建之集群壓力測試
kafka-producer-perf-test.sh --broker-list kafka:9092 --messages 5000000 --topics test
kafka-consumer-perf-test.sh --broker-list kafka:9092 --fetch-size 2000 --message 5000000 --topics test
22-kafka運(yùn)維之常見運(yùn)維工具介紹
kafkaManager(略了)
23-kafka運(yùn)維之常見運(yùn)維命令介紹
- Topic 數(shù)據(jù)增大,需要增加partiton
kafka-topic.sh --alter --zookeeper zk:2181 --partition 3 --topic test
- 核心 Topic 增加副本因子
先編輯 test.json文件
{"version":1,
"partitions":[
{"topic":"test","partition":0,"replicas":[0,1,2]},
{"topic":"test","partition":1,"replicas":[0,1,2]},
{"topic":"test","partition":2 ,"replicas":[0,1,2]}
]}
執(zhí)行以下命令(記得指定 test.json 文件)
kafka-reassign-partitions.sh --zookeeper zk:2181 --reassignment-json-file test.json --execute
- Topic 負(fù)載不均衡
編輯 topics-to-move.json
{"topic":[
{"topic":"test01"},
{"topic":"test02"}
],
"version":1
}
生成遷移方案命令:要指定topics-to-move.json脖苏。此命令會(huì)生成expand-cluster-reassignment.json 文件
kafka-reassign-partitions.sh --zookeeper zk:2181 --topics-to-move-json-file test.json --broker-list "5,6" --generate
執(zhí)行遷移方案
kafka-reassign-partitions.sh --zookeeper zk:2181 --reassignment-json-file expand-cluster-reassignment.json --execute
檢查遷移是否完成
kafka-reassign-partitions.sh --zookeeper zk:2181 --reassignment-json-file expand-cluster-reassignment.json --verify
注意:遷移需要在低峰期進(jìn)行程拭,因?yàn)闀?huì)占用大量帶寬
- broker leader partition 過多,需要負(fù)載均衡
kafka 與leader負(fù)載均衡相關(guān)的參數(shù)有三個(gè)
- auto.leader.rebalance.enable:是否開啟leader負(fù)載均衡棍潘,默認(rèn)true.
- leader.imbalance.check.interval.seconds:檢查負(fù)載時(shí)間間隔恃鞋,默認(rèn)300s.
- leader.imbalance.per.broker.percentage:每個(gè)broker允許的不平衡比例,默認(rèn)10%
解釋不平衡比例:如有三個(gè)broker亦歉,leader數(shù)分布如下
broker0:4
broker1:3
broker2:1
正常負(fù)載應(yīng)該是
broker0:2
broker1:2
broker2:2
每個(gè)broker平衡比例計(jì)算規(guī)則在 KafkaController.scala
里恤浪,具體的沒細(xì)看呢。