您好,登錄后才能下訂單哦!
zookeeper中怎么存儲(chǔ)Kafka,相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。
/brokers/topics/[topic] :
存儲(chǔ)某個(gè)topic的partitions所有分配信息
[zk: localhost:2181(CONNECTED) 1] get /brokers/topics/topic2
Schema: { "version": "版本編號(hào)目前固定為數(shù)字1", "partitions": { "partitionId編號(hào)": [ 同步副本組brokerId列表 ], "partitionId編號(hào)": [ 同步副本組brokerId列表 ], ....... } } Example: { "version": 1, "partitions": { "2": [1, 2, 3], "1": [0, 1, 2], "0": [3, 0, 1], } }
Schema: { "controller_epoch": 表示kafka集群中的中央控制器選舉次數(shù), "leader": 表示該partition選舉leader的brokerId, "version": 版本編號(hào)默認(rèn)為1, "leader_epoch": 該partition leader選舉次數(shù), "isr": [同步副本組brokerId列表] } Example: { "controller_epoch": 1, "leader": 3, "version": 1, "leader_epoch": 0, "isr": [3, 0, 1] }
Schema: { "jmx_port": jmx端口號(hào), "timestamp": kafka broker初始啟動(dòng)時(shí)的時(shí)間戳, "host": 主機(jī)名或ip地址, "version": 版本編號(hào)默認(rèn)為1, "port": kafka broker的服務(wù)端端口號(hào),由server.properties中參數(shù)port確定 } Example: { "jmx_port": -1, "timestamp":"1525741823119" "version": 1, "host": "hadoop1", "port": 9092 }
/controller -> int (broker id of the controller) 存儲(chǔ)center controller中央控制器所在kafka broker的信息
Schema: { "version": 版本編號(hào)默認(rèn)為1, "brokerid": kafka集群中broker唯一編號(hào), "timestamp": kafka broker中央控制器變更時(shí)的時(shí)間戳 } Example: { "version": 1, "brokerid": 0, "timestamp": "1525741822769" }
a.每個(gè)consumer客戶端被創(chuàng)建時(shí),會(huì)向zookeeper注冊(cè)自己的信息;
b.此作用主要是為了"負(fù)載均衡".
c.同一個(gè)Consumer Group中的Consumers,Kafka將相應(yīng)Topic中的每個(gè)消息只發(fā)送給其中一個(gè)Consumer。
d.Consumer Group中的每個(gè)Consumer讀取Topic的一個(gè)或多個(gè)Partitions,并且是唯一的Consumer;
e.一個(gè)Consumer group的多個(gè)consumer的所有線程依次有序地消費(fèi)一個(gè)topic的所有partitions,如果Consumer group中所有consumer總線程大于partitions數(shù)量,則會(huì)出現(xiàn)空閑情況;
舉例說明:
kafka集群中創(chuàng)建一個(gè)topic為report-log 4 partitions 索引編號(hào)為0,1,2,3
假如有目前有三個(gè)消費(fèi)者node:注意-->一個(gè)consumer中一個(gè)消費(fèi)線程可以消費(fèi)一個(gè)或多個(gè)partition.
如果每個(gè)consumer創(chuàng)建一個(gè)consumer thread線程,各個(gè)node消費(fèi)情況如下,node1消費(fèi)索引編號(hào)為0,1分區(qū),node2費(fèi)索引編號(hào)為2,node3費(fèi)索引編號(hào)為3
如果每個(gè)consumer創(chuàng)建2個(gè)consumer thread線程,各個(gè)node消費(fèi)情況如下(是從consumer node先后啟動(dòng)狀態(tài)來確定的),node1消費(fèi)索引編號(hào)為0,1分區(qū);node2費(fèi)索引編號(hào)為2,3;node3為空閑狀態(tài)
總結(jié):
從以上可知,Consumer Group中各個(gè)consumer是根據(jù)先后啟動(dòng)的順序有序消費(fèi)一個(gè)topic的所有partitions的。
如果Consumer Group中所有consumer的總線程數(shù)大于partitions數(shù)量,則可能consumer thread或consumer會(huì)出現(xiàn)空閑狀態(tài)。
當(dāng)一個(gè)group中,有consumer加入或者離開時(shí),會(huì)觸發(fā)partitions均衡.均衡的最終目的,是提升topic的并發(fā)消費(fèi)能力.
1) 假如topic1,具有如下partitions: P0,P1,P2,P3
2) 加入group中,有如下consumer: C0,C1
3) 首先根據(jù)partition索引號(hào)對(duì)partitions排序: P0,P1,P2,P3
4) 根據(jù)(consumer.id + '-'+ thread序號(hào))排序: C0,C1
5) 計(jì)算倍數(shù): M = [P0,P1,P2,P3].size / [C0,C1].size,本例值M=2(向上取整)
6) 然后依次分配partitions: C0 = [P0,P1],C1=[P2,P3],即Ci = [P(i * M),P((i + 1) * M -1)]
每個(gè)consumer都有一個(gè)唯一的ID(consumerId可以通過配置文件指定,也可以由系統(tǒng)生成),此id用來標(biāo)記消費(fèi)者信息.
/consumers/[groupId]/ids/[consumerIdString]
是一個(gè)臨時(shí)的znode,此節(jié)點(diǎn)的值為請(qǐng)看consumerIdString產(chǎn)生規(guī)則,即表示此consumer目前所消費(fèi)的topic + partitions列表.
consumerId產(chǎn)生規(guī)則:
StringconsumerUuid = null;
if(config.consumerId!=null && config.consumerId)
consumerUuid = consumerId;
else {
String uuid = UUID.randomUUID()
consumerUuid = "%s-%d-%s".format(
InetAddress.getLocalHost.getHostName, System.currentTimeMillis,
uuid.getMostSignificantBits().toHexString.substring(0,8));}
String consumerIdString = config.groupId + "_" + consumerUuid;
[zk: localhost:2181(CONNECTED) 11] get /consumers/console-consumer-2304/ids/console-consumer-2304_hadoop2-1525747915241-6b48ff32
Schema: { "version": 版本編號(hào)默認(rèn)為1, "subscription": { //訂閱topic列表 "topic名稱": consumer中topic消費(fèi)者線程數(shù) }, "pattern": "static", "timestamp": "consumer啟動(dòng)時(shí)的時(shí)間戳" } Example: { "version": 1, "subscription": { "topic2": 1 }, "pattern": "white_list", "timestamp": "1525747915336" }
/consumers/[groupId]/offsets/[topic]/[partitionId] -> long (offset)
用來跟蹤每個(gè)consumer目前所消費(fèi)的partition中最大的offset
此znode為持久節(jié)點(diǎn),可以看出offset跟group_id有關(guān),以表明當(dāng)消費(fèi)者組(consumer group)中一個(gè)消費(fèi)者失效,
重新觸發(fā)balance,其他consumer可以繼續(xù)消費(fèi).
/admin/reassign_partitions
{ "fields":[ { "name":"version", "type":"int", "doc":"version id" }, { "name":"partitions", "type":{ "type":"array", "items":{ "fields":[ { "name":"topic", "type":"string", "doc":"topic of the partition to be reassigned" }, { "name":"partition", "type":"int", "doc":"the partition to be reassigned" }, { "name":"replicas", "type":"array", "items":"int", "doc":"a list of replica ids" } ], } "doc":"an array of partitions to be reassigned to new replicas" } } ] } Example: { "version": 1, "partitions": [ { "topic": "Foo", "partition": 1, "replicas": [0, 1, 3] } ] }
{ "fields":[ { "name":"version", "type":"int", "doc":"version id" }, { "name":"partitions", "type":{ "type":"array", "items":{ "fields":[ { "name":"topic", "type":"string", "doc":"topic of the partition for which preferred replica election should be triggered" }, { "name":"partition", "type":"int", "doc":"the partition for which preferred replica election should be triggered" } ], } "doc":"an array of partitions for which preferred replica election should be triggered" } } ] } 例子: { "version": 1, "partitions": [ { "topic": "Foo", "partition": 1 }, { "topic": "Bar", "partition": 0 } ] }
Schema: { "fields": [ {"name": "version", "type": "int", "doc": "version id"}, {"name": "topics", "type": { "type": "array", "items": "string", "doc": "an array of topics to be deleted"} } ] } 例子: { "version": 1, "topics": ["foo", "bar"] }
/config/topics/[topic_name]
看完上述內(nèi)容,你們掌握zookeeper中怎么存儲(chǔ)Kafka的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。