涓€鏂囧交搴曟悶鎳?zookeeper 鏍稿績鐭ヨ瘑鐐?
Posted 绋嬪簭鍛橀潰璇曞惂
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了涓€鏂囧交搴曟悶鎳?zookeeper 鏍稿績鐭ヨ瘑鐐?相关的知识,希望对你有一定的参考价值。
鐐瑰嚮鈥?/span>绋嬪簭鍛橀潰璇曞惂鈥濓紝閫夋嫨鈥滄槦鏍囸煍濃€?/span>
鍥炲鍏抽敭璇嶁€滈潰璇曗€濇湁鎯婂枩~
1. ZooKeeper 鏄粈涔堬紵
ZooKeeper 鏄竴涓紑婧愮殑鍒嗗竷寮忓崗璋冩湇鍔°€傚畠鏄竴涓负鍒嗗竷寮忓簲鐢ㄦ彁渚涗竴鑷存€ф湇鍔$殑杞欢锛屽垎甯冨紡搴旂敤绋嬪簭鍙互鍩轰簬 Zookeeper 瀹炵幇璇稿鏁版嵁鍙戝竷/璁㈤槄銆佽礋杞藉潎琛°€佸懡鍚嶆湇鍔°€佸垎甯冨紡鍗忚皟/閫氱煡銆侀泦缇ょ鐞嗐€丮aster 閫変妇銆佸垎甯冨紡閿佸拰鍒嗗竷寮忛槦鍒楃瓑鍔熻兘銆?/span>
ZooKeeper 鐨勭洰鏍囧氨鏄皝瑁呭ソ澶嶆潅鏄撳嚭閿欑殑鍏抽敭鏈嶅姟锛屽皢绠€鍗曟槗鐢ㄧ殑鎺ュ彛鍜屾€ц兘楂樻晥銆佸姛鑳界ǔ瀹氱殑绯荤粺鎻愪緵缁欑敤鎴枫€?/span>
Zookeeper 淇濊瘉浜嗗涓嬪垎甯冨紡涓€鑷存€х壒鎬э細
锛?锛夐『搴忎竴鑷存€?/span>
锛?锛夊師瀛愭€?/span>
锛?锛夊崟涓€瑙嗗浘
锛?锛夊彲闈犳€?/span>
锛?锛夊疄鏃舵€э紙鏈€缁堜竴鑷存€э級
瀹㈡埛绔殑璇昏姹傚彲浠ヨ闆嗙兢涓殑浠绘剰涓€鍙版満鍣ㄥ鐞嗭紝濡傛灉璇昏姹傚湪鑺傜偣涓婃敞鍐屼簡鐩戝惉鍣紝杩欎釜鐩戝惉鍣ㄤ篃鏄敱鎵€杩炴帴鐨?zookeeper 鏈哄櫒鏉ュ鐞嗐€傚浜庡啓璇锋眰锛岃繖浜涜姹備細鍚屾椂鍙戠粰鍏朵粬 zookeeper 鏈哄櫒骞朵笖杈炬垚涓€鑷村悗锛岃姹傛墠浼氳繑鍥炴垚鍔熴€傚洜姝わ紝闅忕潃 zookeeper 鐨勯泦缇ゆ満鍣ㄥ澶氾紝璇昏姹傜殑鍚炲悙浼氭彁楂樹絾鏄啓璇锋眰鐨勫悶鍚愪細涓嬮檷銆?/span>
鏈夊簭鎬ф槸 zookeeper 涓潪甯搁噸瑕佺殑涓€涓壒鎬э紝鎵€鏈夌殑鏇存柊閮芥槸鍏ㄥ眬鏈夊簭鐨勶紝姣忎釜鏇存柊閮芥湁涓€涓敮涓€鐨勬椂闂存埑锛岃繖涓椂闂存埑绉颁负 zxid锛圸ookeeper Transaction Id锛夈€傝€岃璇锋眰鍙細鐩稿浜庢洿鏂版湁搴忥紝涔熷氨鏄璇锋眰鐨勮繑鍥炵粨鏋滀腑浼氬甫鏈夎繖涓獄ookeeper 鏈€鏂扮殑 zxid銆?/span>
2. ZooKeeper 鎻愪緵浜嗕粈涔堬紵
鏂囦欢绯荤粺
閫氱煡鏈哄埗
3. Zookeeper 鏂囦欢绯荤粺
Zookeeper 鎻愪緵涓€涓灞傜骇鐨勮妭鐐瑰懡鍚嶇┖闂达紙鑺傜偣绉颁负 znode锛夈€備笌鏂囦欢绯荤粺涓嶅悓鐨勬槸锛岃繖浜涜妭鐐归兘鍙互璁剧疆鍏宠仈鐨勬暟鎹紝鑰屾枃浠剁郴缁熶腑鍙湁鏂囦欢鑺傜偣鍙互瀛樻斁鏁版嵁鑰岀洰褰曡妭鐐逛笉琛屻€?/span>
Zookeeper 涓轰簡淇濊瘉楂樺悶鍚愬拰浣庡欢杩燂紝鍦ㄥ唴瀛樹腑缁存姢浜嗚繖涓爲鐘剁殑鐩綍缁撴瀯锛岃繖绉嶇壒鎬т娇寰?Zookeeper 涓嶈兘鐢ㄤ簬瀛樻斁澶ч噺鐨勬暟鎹紝姣忎釜鑺傜偣鐨勫瓨鏀炬暟鎹笂闄愪负1M銆?/span>
4. Zookeeper 鎬庝箞淇濊瘉涓讳粠鑺傜偣鐨勭姸鎬佸悓姝ワ紵
Zookeeper 鐨勬牳蹇冩槸鍘熷瓙骞挎挱鏈哄埗锛岃繖涓満鍒朵繚璇佷簡鍚勪釜 server 涔嬮棿鐨勫悓姝ャ€傚疄鐜拌繖涓満鍒剁殑鍗忚鍙仛 Zab 鍗忚銆俍ab 鍗忚鏈変袱绉嶆ā寮忥紝瀹冧滑鍒嗗埆鏄仮澶嶆ā寮忓拰骞挎挱妯″紡銆?/span>
鎭㈠妯″紡
褰撴湇鍔″惎鍔ㄦ垨鑰呭湪棰嗗鑰呭穿婧冨悗锛孼ab灏辫繘鍏ヤ簡鎭㈠妯″紡锛屽綋棰嗗鑰呰閫変妇鍑烘潵锛屼笖澶у鏁?server 瀹屾垚浜嗗拰 leader 鐨勭姸鎬佸悓姝ヤ互鍚庯紝鎭㈠妯″紡灏辩粨鏉熶簡銆傜姸鎬佸悓姝ヤ繚璇佷簡 leader 鍜?server 鍏锋湁鐩稿悓鐨勭郴缁熺姸鎬併€?/span>
骞挎挱妯″紡
涓€鏃?leader 宸茬粡鍜屽鏁扮殑 follower 杩涜浜嗙姸鎬佸悓姝ュ悗锛屽畠灏卞彲浠ュ紑濮嬪箍鎾秷鎭簡锛屽嵆杩涘叆骞挎挱鐘舵€併€傝繖鏃跺€欏綋涓€涓?server 鍔犲叆 ZooKeeper 鏈嶅姟涓紝瀹冧細鍦ㄦ仮澶嶆ā寮忎笅鍚姩锛屽彂鐜?leader锛屽苟鍜?leader 杩涜鐘舵€佸悓姝ャ€傚緟鍒板悓姝ョ粨鏉燂紝瀹冧篃鍙備笌娑堟伅骞挎挱銆俍ooKeeper 鏈嶅姟涓€鐩寸淮鎸佸湪 Broadcast 鐘舵€侊紝鐩村埌 leader 宕╂簝浜嗘垨鑰?leader 澶卞幓浜嗗ぇ閮ㄥ垎鐨?followers 鏀寔銆?/span>
5. 鍥涚绫诲瀷鐨勬暟鎹妭鐐?Znode
锛?锛塒ERSISTENT-鎸佷箙鑺傜偣
闄ら潪鎵嬪姩鍒犻櫎锛屽惁鍒欒妭鐐逛竴鐩村瓨鍦ㄤ簬 Zookeeper 涓?/span>
锛?锛塃PHEMERAL-涓存椂鑺傜偣
涓存椂鑺傜偣鐨勭敓鍛藉懆鏈熶笌瀹㈡埛绔細璇濈粦瀹氾紝涓€鏃﹀鎴风浼氳瘽澶辨晥锛堝鎴风涓巣ookeeper 杩炴帴鏂紑涓嶄竴瀹氫細璇濆け鏁堬級锛岄偅涔堣繖涓鎴风鍒涘缓鐨勬墍鏈変复鏃惰妭鐐归兘浼氳绉婚櫎銆?/span>
锛?锛塒ERSISTENT_SEQUENTIAL-鎸佷箙椤哄簭鑺傜偣
鍩烘湰鐗规€у悓鎸佷箙鑺傜偣锛屽彧鏄鍔犱簡椤哄簭灞炴€э紝鑺傜偣鍚嶅悗杈逛細杩藉姞涓€涓敱鐖惰妭鐐圭淮鎶ょ殑鑷鏁村瀷鏁板瓧銆?/span>
锛?锛塃PHEMERAL_SEQUENTIAL-涓存椂椤哄簭鑺傜偣
鍩烘湰鐗规€у悓涓存椂鑺傜偣锛屽鍔犱簡椤哄簭灞炴€э紝鑺傜偣鍚嶅悗杈逛細杩藉姞涓€涓敱鐖惰妭鐐圭淮鎶ょ殑鑷鏁村瀷鏁板瓧銆?/span>
6. Zookeeper Watcher 鏈哄埗 鈥?鏁版嵁鍙樻洿閫氱煡
Zookeeper 鍏佽瀹㈡埛绔悜鏈嶅姟绔殑鏌愪釜 Znode 娉ㄥ唽涓€涓?Watcher 鐩戝惉锛屽綋鏈嶅姟绔殑涓€浜涙寚瀹氫簨浠惰Е鍙戜簡杩欎釜 Watcher锛屾湇鍔$浼氬悜鎸囧畾瀹㈡埛绔彂閫佷竴涓簨浠堕€氱煡鏉ュ疄鐜板垎甯冨紡鐨勯€氱煡鍔熻兘锛岀劧鍚庡鎴风鏍规嵁 Watcher 閫氱煡鐘舵€佸拰浜嬩欢绫诲瀷鍋氬嚭涓氬姟涓婄殑鏀瑰彉銆?/span>
宸ヤ綔鏈哄埗锛?/span>
锛?锛夊鎴风娉ㄥ唽 watcher
锛?锛夋湇鍔$澶勭悊 watcher
锛?锛夊鎴风鍥炶皟 watcher
Watcher 鐗规€ф€荤粨锛?/span>
锛?锛変竴娆℃€?/span>
鏃犺鏄湇鍔$杩樻槸瀹㈡埛绔紝涓€鏃︿竴涓?Watcher 琚?瑙?鍙?锛孼ookeeper 閮戒細灏嗗叾浠庣浉搴旂殑瀛樺偍涓Щ闄ゃ€傝繖鏍风殑璁捐鏈夋晥鐨勫噺杞讳簡鏈嶅姟绔殑鍘嬪姏锛屼笉鐒跺浜庢洿鏂伴潪甯搁绻佺殑鑺傜偣锛屾湇鍔$浼氫笉鏂殑鍚戝鎴风鍙戦€佷簨浠堕€氱煡锛屾棤璁哄浜庣綉缁滆繕鏄湇鍔$鐨勫帇鍔涢兘闈炲父澶с€?/span>
锛?锛夊鎴风涓茶鎵ц
瀹㈡埛绔?Watcher 鍥炶皟鐨勮繃绋嬫槸涓€涓覆琛屽悓姝ョ殑杩囩▼銆?/span>
锛?锛夎交閲?/span>
3.1銆乄atcher 閫氱煡闈炲父绠€鍗曪紝鍙細鍛婅瘔瀹㈡埛绔彂鐢熶簡浜嬩欢锛岃€屼笉浼氳鏄庝簨浠剁殑鍏蜂綋鍐呭銆?/span>
3.2銆佸鎴风鍚戞湇鍔$娉ㄥ唽 Watcher 鐨勬椂鍊欙紝骞朵笉浼氭妸瀹㈡埛绔湡瀹炵殑 Watcher 瀵硅薄瀹炰綋浼犻€掑埌鏈嶅姟绔紝浠呬粎鏄湪瀹㈡埛绔姹備腑浣跨敤 boolean 绫诲瀷灞炴€ц繘琛屼簡鏍囪銆?/span>
锛?锛墂atcher event 寮傛鍙戦€?watcher 鐨勯€氱煡浜嬩欢浠?server 鍙戦€佸埌 client 鏄紓姝ョ殑锛岃繖灏卞瓨鍦ㄤ竴涓棶棰橈紝涓嶅悓鐨勫鎴风鍜屾湇鍔″櫒涔嬮棿閫氳繃 socket 杩涜閫氫俊锛岀敱浜庣綉缁滃欢杩熸垨鍏朵粬鍥犵礌瀵艰嚧瀹㈡埛绔湪涓嶉€氱殑鏃跺埢鐩戝惉鍒颁簨浠讹紝鐢变簬 Zookeeper 鏈韩鎻愪緵浜?ordering guarantee锛屽嵆瀹㈡埛绔洃鍚簨浠跺悗锛屾墠浼氭劅鐭ュ畠鎵€鐩戣 znode鍙戠敓浜嗗彉鍖栥€傛墍浠ユ垜浠娇鐢?Zookeeper 涓嶈兘鏈熸湜鑳藉鐩戞帶鍒拌妭鐐规瘡娆$殑鍙樺寲銆俍ookeeper 鍙兘淇濊瘉鏈€缁堢殑涓€鑷存€э紝鑰屾棤娉曚繚璇佸己涓€鑷存€с€?/span>
锛?锛夋敞鍐?watcher getData銆乪xists銆乬etChildren
锛?锛夎Е鍙?watcher create銆乨elete銆乻etData
锛?锛夊綋涓€涓鎴风杩炴帴鍒颁竴涓柊鐨勬湇鍔″櫒涓婃椂锛寃atch 灏嗕細琚互浠绘剰浼氳瘽浜嬩欢瑙﹀彂銆傚綋涓庝竴涓湇鍔″櫒澶卞幓杩炴帴鐨勬椂鍊欙紝鏄棤娉曟帴鏀跺埌 watch 鐨勩€傝€屽綋 client 閲嶆柊杩炴帴鏃讹紝濡傛灉闇€瑕佺殑璇濓紝鎵€鏈夊厛鍓嶆敞鍐岃繃鐨?watch锛岄兘浼氳閲嶆柊娉ㄥ唽銆傞€氬父杩欐槸瀹屽叏閫忔槑鐨勩€傚彧鏈夊湪涓€涓壒娈婃儏鍐典笅锛寃atch 鍙兘浼氫涪澶憋細瀵逛簬涓€涓湭鍒涘缓鐨?znode鐨?exist watch锛屽鏋滃湪瀹㈡埛绔柇寮€杩炴帴鏈熼棿琚垱寤轰簡锛屽苟涓旈殢鍚庡湪瀹㈡埛绔繛鎺ヤ笂涔嬪墠鍙堝垹闄や簡锛岃繖绉嶆儏鍐典笅锛岃繖涓?watch 浜嬩欢鍙兘浼氳涓㈠け銆?/span>
7. 瀹㈡埛绔敞鍐?Watcher 瀹炵幇
锛?锛夎皟鐢?getData()/getChildren()/exist()涓変釜 API锛屼紶鍏?Watcher 瀵硅薄
锛?锛夋爣璁拌姹?request锛屽皝瑁?Watcher 鍒?WatchRegistration
锛?锛夊皝瑁呮垚 Packet 瀵硅薄锛屽彂鏈嶅姟绔彂閫?request
锛?锛夋敹鍒版湇鍔$鍝嶅簲鍚庯紝灏?Watcher 娉ㄥ唽鍒?ZKWatcherManager 涓繘琛岀鐞?/span>
锛?锛夎姹傝繑鍥烇紝瀹屾垚娉ㄥ唽銆?/span>
8. 鏈嶅姟绔鐞?Watcher 瀹炵幇
锛?锛夋湇鍔$鎺ユ敹 Watcher 骞跺瓨鍌?/span>
鎺ユ敹鍒板鎴风璇锋眰锛屽鐞嗚姹傚垽鏂槸鍚﹂渶瑕佹敞鍐?Watcher锛岄渶瑕佺殑璇濆皢鏁版嵁鑺傜偣鐨勮妭鐐硅矾寰勫拰 ServerCnxn锛圫erverCnxn 浠h〃涓€涓鎴风鍜屾湇鍔$鐨勮繛鎺ワ紝瀹炵幇浜?Watcher 鐨?process 鎺ュ彛锛屾鏃跺彲浠ョ湅鎴愪竴涓?Watcher 瀵硅薄锛夊瓨鍌ㄥ湪WatcherManager 鐨?WatchTable 鍜?watch2Paths 涓幓銆?/span>
锛?锛塛atcher 瑙﹀彂
浠ユ湇鍔$鎺ユ敹鍒?setData() 浜嬪姟璇锋眰瑙﹀彂 NodeDataChanged 浜嬩欢涓轰緥锛?/span>
2.1 灏佽 WatchedEvent
灏嗛€氱煡鐘舵€侊紙SyncConnected锛夈€佷簨浠剁被鍨嬶紙NodeDataChanged锛変互鍙婅妭鐐硅矾寰勫皝瑁呮垚涓€涓?WatchedEvent 瀵硅薄
2.2 鏌ヨ Watcher
浠?WatchTable 涓牴鎹妭鐐硅矾寰勬煡鎵?Watcher
2.3 娌℃壘鍒帮紱璇存槑娌℃湁瀹㈡埛绔湪璇ユ暟鎹妭鐐逛笂娉ㄥ唽杩?Watcher
2.4 鎵惧埌锛涙彁鍙栧苟浠?WatchTable 鍜?Watch2Paths 涓垹闄ゅ搴?Watcher锛堜粠杩欓噷鍙互鐪嬪嚭 Watcher 鍦ㄦ湇鍔$鏄竴娆℃€х殑锛岃Е鍙戜竴娆″氨澶辨晥浜嗭級
锛?锛夎皟鐢?process 鏂规硶鏉ヨЕ鍙?Watcher
杩欓噷 process 涓昏灏辨槸閫氳繃 ServerCnxn 瀵瑰簲鐨?TCP 杩炴帴鍙戦€?Watcher 浜嬩欢閫氱煡銆?/span>
9. 瀹㈡埛绔洖璋?Watcher
瀹㈡埛绔?SendThread 绾跨▼鎺ユ敹浜嬩欢閫氱煡锛屼氦鐢?EventThread 绾跨▼鍥炶皟 Watcher銆?/span>
瀹㈡埛绔殑 Watcher 鏈哄埗鍚屾牱鏄竴娆℃€х殑锛屼竴鏃﹁瑙﹀彂鍚庯紝璇?Watcher 灏卞け鏁堜簡銆?/span>
10. ACL 鏉冮檺鎺у埗鏈哄埗
UGO锛圲ser/Group/Others锛?/span>
鐩墠鍦?Linux/Unix 鏂囦欢绯荤粺涓娇鐢紝涔熸槸浣跨敤鏈€骞挎硾鐨勬潈闄愭帶鍒舵柟寮忋€傛槸涓€绉嶇矖绮掑害鐨勬枃浠剁郴缁熸潈闄愭帶鍒舵ā寮忋€?/span>
ACL锛圓ccess Control List锛夎闂帶鍒跺垪琛?/span>
鍖呮嫭涓変釜鏂归潰锛?/span>
鏉冮檺妯″紡锛圫cheme锛?/span>
锛?锛塂igest锛氭渶甯哥敤锛岀敤绫讳技浜?username:password 鐨勬潈闄愭爣璇嗘潵杩涜鏉冮檺閰嶇疆锛屼究浜庡尯鍒嗕笉鍚屽簲鐢ㄦ潵杩涜鏉冮檺鎺у埗
锛?锛塛orld锛氭渶寮€鏀剧殑鏉冮檺鎺у埗鏂瑰紡锛屾槸涓€绉嶇壒娈婄殑 digest 妯″紡锛屽彧鏈変竴涓潈闄愭爣璇嗏€渨orld:anyone鈥?/span>
锛?锛塖uper锛氳秴绾х敤鎴?/span>
鎺堟潈瀵硅薄
鏉冮檺 Permission
锛?锛塁REATE锛氭暟鎹妭鐐瑰垱寤烘潈闄愶紝鍏佽鎺堟潈瀵硅薄鍦ㄨ Znode 涓嬪垱寤哄瓙鑺傜偣
锛?锛塂ELETE锛氬瓙鑺傜偣鍒犻櫎鏉冮檺锛屽厑璁告巿鏉冨璞″垹闄よ鏁版嵁鑺傜偣鐨勫瓙鑺傜偣
锛?锛塕EAD锛氭暟鎹妭鐐圭殑璇诲彇鏉冮檺锛屽厑璁告巿鏉冨璞¤闂鏁版嵁鑺傜偣骞惰鍙栧叾鏁版嵁鍐呭鎴栧瓙鑺傜偣鍒楄〃绛?/span>
锛?锛塛RITE锛氭暟鎹妭鐐规洿鏂版潈闄愶紝鍏佽鎺堟潈瀵硅薄瀵硅鏁版嵁鑺傜偣杩涜鏇存柊鎿嶄綔
锛?锛堿DMIN锛氭暟鎹妭鐐圭鐞嗘潈闄愶紝鍏佽鎺堟潈瀵硅薄瀵硅鏁版嵁鑺傜偣杩涜 ACL 鐩稿叧璁剧疆鎿嶄綔
11. Chroot 鐗规€?/p>
3.2.0 鐗堟湰鍚庯紝娣诲姞浜?Chroot 鐗规€э紝璇ョ壒鎬у厑璁告瘡涓鎴风涓鸿嚜宸辫缃竴涓懡鍚嶇┖闂淬€傚鏋滀竴涓鎴风璁剧疆浜?Chroot锛岄偅涔堣瀹㈡埛绔鏈嶅姟鍣ㄧ殑浠讳綍鎿嶄綔锛岄兘灏嗕細琚檺鍒跺湪鍏惰嚜宸辩殑鍛藉悕绌洪棿涓嬨€?/span>
閫氳繃璁剧疆 Chroot锛岃兘澶熷皢涓€涓鎴风搴旂敤浜?Zookeeper 鏈嶅姟绔殑涓€棰楀瓙鏍戠浉瀵瑰簲锛屽湪閭d簺澶氫釜搴旂敤鍏敤涓€涓?Zookeeper 杩涚兢鐨勫満鏅笅锛屽瀹炵幇涓嶅悓搴旂敤闂寸殑鐩镐簰闅旂闈炲父鏈夊府鍔┿€?/span>
12. 浼氳瘽绠$悊
鍒嗘《绛栫暐锛氬皢绫讳技鐨勪細璇濇斁鍦ㄥ悓涓€鍖哄潡涓繘琛岀鐞嗭紝浠ヤ究浜?Zookeeper 瀵逛細璇濊繘琛屼笉鍚屽尯鍧楃殑闅旂澶勭悊浠ュ強鍚屼竴鍖哄潡鐨勭粺涓€澶勭悊銆?/span>
鍒嗛厤鍘熷垯锛氭瘡涓細璇濈殑鈥滀笅娆¤秴鏃舵椂闂寸偣鈥濓紙ExpirationTime锛?/span>
璁$畻鍏紡锛?/span>
ExpirationTime_ = currentTime + sessionTimeout
ExpirationTime = (ExpirationTime_ / ExpirationInrerval + 1) *
ExpirationInterval , ExpirationInterval 鏄寚 Zookeeper 浼氳瘽瓒呮椂妫€鏌ユ椂闂撮棿闅旓紝榛樿 tickTime
13. 鏈嶅姟鍣ㄨ鑹?/p>
Leader
锛?锛変簨鍔¤姹傜殑鍞竴璋冨害鍜屽鐞嗚€咃紝淇濊瘉闆嗙兢浜嬪姟澶勭悊鐨勯『搴忔€?/span>
锛?锛夐泦缇ゅ唴閮ㄥ悇鏈嶅姟鐨勮皟搴﹁€?/span>
Follower
锛?锛夊鐞嗗鎴风鐨勯潪浜嬪姟璇锋眰锛岃浆鍙戜簨鍔¤姹傜粰 Leader 鏈嶅姟鍣?/span>
锛?锛夊弬涓庝簨鍔¤姹?Proposal 鐨勬姇绁?/span>
锛?锛夊弬涓?Leader 閫変妇鎶曠エ
Observer
锛?锛?.0 鐗堟湰浠ュ悗寮曞叆鐨勪竴涓湇鍔″櫒瑙掕壊锛屽湪涓嶅奖鍝嶉泦缇や簨鍔″鐞嗚兘鍔涚殑鍩虹涓婃彁鍗囬泦缇ょ殑闈炰簨鍔″鐞嗚兘鍔?/span>
锛?锛夊鐞嗗鎴风鐨勯潪浜嬪姟璇锋眰锛岃浆鍙戜簨鍔¤姹傜粰 Leader 鏈嶅姟鍣?/span>
锛?锛変笉鍙備笌浠讳綍褰㈠紡鐨勬姇绁?/span>
14. Zookeeper 涓?Server 宸ヤ綔鐘舵€?/p>
鏈嶅姟鍣ㄥ叿鏈夊洓绉嶇姸鎬侊紝鍒嗗埆鏄?LOOKING銆丗OLLOWING銆丩EADING銆丱BSERVING銆?/span>
锛?锛塋OOKING锛氬 鎵?Leader 鐘舵€併€傚綋鏈嶅姟鍣ㄥ浜庤鐘舵€佹椂锛屽畠浼氳涓哄綋鍓嶉泦缇や腑娌℃湁 Leader锛屽洜姝ら渶瑕佽繘鍏?Leader 閫変妇鐘舵€併€?/span>
锛?锛塅OLLOWING锛氳窡闅忚€呯姸鎬併€傝〃鏄庡綋鍓嶆湇鍔″櫒瑙掕壊鏄?Follower銆?/span>
锛?锛塋EADING锛氶瀵艰€呯姸鎬併€傝〃鏄庡綋鍓嶆湇鍔″櫒瑙掕壊鏄?Leader銆?/span>
锛?锛塐BSERVING锛氳瀵熻€呯姸鎬併€傝〃鏄庡綋鍓嶆湇鍔″櫒瑙掕壊鏄?Observer銆?/span>
15. 鏁版嵁鍚屾
鏁翠釜闆嗙兢瀹屾垚 Leader 閫変妇涔嬪悗锛孡earner锛團ollower 鍜?Observer 鐨勭粺绉帮級鍥炲悜Leader 鏈嶅姟鍣ㄨ繘琛屾敞鍐屻€傚綋 Learner 鏈嶅姟鍣ㄦ兂 Leader 鏈嶅姟鍣ㄥ畬鎴愭敞鍐屽悗锛岃繘鍏ユ暟鎹悓姝ョ幆鑺傘€?/span>
鏁版嵁鍚屾娴佺▼锛氾紙鍧囦互娑堟伅浼犻€掔殑鏂瑰紡杩涜锛?/span>
Learner 鍚?Learder 娉ㄥ唽
鏁版嵁鍚屾
鍚屾纭
Zookeeper 鐨勬暟鎹悓姝ラ€氬父鍒嗕负鍥涚被锛?/span>
锛?锛夌洿鎺ュ樊寮傚寲鍚屾锛圖IFF 鍚屾锛?/span>
锛?锛夊厛鍥炴粴鍐嶅樊寮傚寲鍚屾锛圱RUNC+DIFF 鍚屾锛?/span>
锛?锛変粎鍥炴粴鍚屾锛圱RUNC 鍚屾锛?/span>
锛?锛夊叏閲忓悓姝ワ紙SNAP 鍚屾锛?/span>
鍦ㄨ繘琛屾暟鎹悓姝ュ墠锛孡eader 鏈嶅姟鍣ㄤ細瀹屾垚鏁版嵁鍚屾鍒濆鍖栵細
peerLastZxid锛?/span>
路 浠?learner 鏈嶅姟鍣ㄦ敞鍐屾椂鍙戦€佺殑 ACKEPOCH 娑堟伅涓彁鍙?lastZxid锛堣Learner 鏈嶅姟鍣ㄦ渶鍚庡鐞嗙殑 ZXID锛?/span>
minCommittedLog锛?/span>
路 Leader 鏈嶅姟鍣?Proposal 缂撳瓨闃熷垪 committedLog 涓渶灏?ZXIDmaxCommittedLog锛?/span>
路 Leader 鏈嶅姟鍣?Proposal 缂撳瓨闃熷垪 committedLog 涓渶澶?ZXID鐩存帴宸紓鍖栧悓姝ワ紙DIFF 鍚屾锛?/span>
路 鍦烘櫙锛歱eerLastZxid 浠嬩簬 minCommittedLog 鍜?maxCommittedLog涔嬮棿鍏堝洖婊氬啀宸紓鍖栧悓姝ワ紙TRUNC+DIFF 鍚屾锛?/span>
路 鍦烘櫙锛氬綋鏂扮殑 Leader 鏈嶅姟鍣ㄥ彂鐜版煇涓?Learner 鏈嶅姟鍣ㄥ寘鍚簡涓€鏉¤嚜宸辨病鏈夌殑浜嬪姟璁板綍锛岄偅涔堝氨闇€瑕佽璇?Learner 鏈嶅姟鍣ㄨ繘琛屼簨鍔″洖婊氣€撳洖婊氬埌 Leader鏈嶅姟鍣ㄤ笂瀛樺湪鐨勶紝鍚屾椂涔熸槸鏈€鎺ヨ繎浜?peerLastZxid 鐨?ZXID浠呭洖婊氬悓姝ワ紙TRUNC 鍚屾锛?/span>
路 鍦烘櫙锛歱eerLastZxid 澶т簬 maxCommittedLog
鍏ㄩ噺鍚屾锛圫NAP 鍚屾锛?/span>
路 鍦烘櫙涓€锛歱eerLastZxid 灏忎簬 minCommittedLog
路 鍦烘櫙浜?/span>锛歀eader 鏈嶅姟鍣ㄤ笂娌℃湁 Proposal 缂撳瓨闃熷垪涓?peerLastZxid 涓嶇瓑浜?lastProcessZxid
16. zookeeper 鏄浣曚繚璇佷簨鍔$殑椤哄簭涓€鑷存€х殑锛?/p>
zookeeper 閲囩敤浜嗗叏灞€閫掑鐨勪簨鍔?Id 鏉ユ爣璇嗭紝鎵€鏈夌殑 proposal锛堟彁璁級閮藉湪琚彁鍑虹殑鏃跺€欏姞涓婁簡 zxid锛寊xid 瀹為檯涓婃槸涓€涓?64 浣嶇殑鏁板瓧锛岄珮 32 浣嶆槸 epoch锛?鏃舵湡; 绾厓; 涓? 鏂版椂浠o級鐢ㄦ潵鏍囪瘑 leader 鍛ㄦ湡锛屽鏋滄湁鏂扮殑 leader 浜х敓鍑烘潵锛宔poch浼氳嚜澧烇紝浣?32 浣嶇敤鏉ラ€掑璁℃暟銆傚綋鏂颁骇鐢?proposal 鐨勬椂鍊欙紝浼氫緷鎹暟鎹簱鐨勪袱闃舵杩囩▼锛岄鍏堜細鍚戝叾浠栫殑 server 鍙戝嚭浜嬪姟鎵ц璇锋眰锛屽鏋滆秴杩囧崐鏁扮殑鏈哄櫒閮借兘鎵ц骞朵笖鑳藉鎴愬姛锛岄偅涔堝氨浼氬紑濮嬫墽琛屻€?/span>
17. 鍒嗗竷寮忛泦缇や腑涓轰粈涔堜細鏈?Master涓昏妭鐐癸紵
鍦ㄥ垎甯冨紡鐜涓紝鏈変簺涓氬姟閫昏緫鍙渶瑕侀泦缇や腑鐨勬煇涓€鍙版満鍣ㄨ繘琛屾墽琛岋紝鍏朵粬鐨勬満鍣ㄥ彲浠ュ叡浜繖涓粨鏋滐紝杩欐牱鍙互澶уぇ鍑忓皯閲嶅璁$畻锛屾彁楂樻€ц兘锛屼簬鏄氨闇€瑕佽繘琛?leader 閫変妇銆?/span>
18. zk 鑺傜偣瀹曟満濡備綍澶勭悊锛?/p>
Zookeeper 鏈韩涔熸槸闆嗙兢锛屾帹鑽愰厤缃笉灏戜簬 3 涓湇鍔″櫒銆俍ookeeper 鑷韩涔熻淇濊瘉褰撲竴涓妭鐐瑰畷鏈烘椂锛屽叾浠栬妭鐐逛細缁х画鎻愪緵鏈嶅姟銆?/span>
濡傛灉鏄竴涓?Follower 瀹曟満锛岃繕鏈?2 鍙版湇鍔″櫒鎻愪緵璁块棶锛屽洜涓?Zookeeper 涓婄殑鏁版嵁鏄湁澶氫釜鍓湰鐨勶紝鏁版嵁骞朵笉浼氫涪澶憋紱
濡傛灉鏄竴涓?Leader 瀹曟満锛孼ookeeper 浼氶€変妇鍑烘柊鐨?Leader銆?/span>
ZK 闆嗙兢鐨勬満鍒舵槸鍙瓒呰繃鍗婃暟鐨勮妭鐐规甯革紝闆嗙兢灏辫兘姝e父鎻愪緵鏈嶅姟銆傚彧鏈夊湪 ZK鑺傜偣鎸傚緱澶锛屽彧鍓╀竴鍗婃垨涓嶅埌涓€鍗婅妭鐐硅兘宸ヤ綔锛岄泦缇ゆ墠澶辨晥銆?/span>
鎵€浠?/span>
3 涓妭鐐圭殑 cluster 鍙互鎸傛帀 1 涓妭鐐?leader 鍙互寰楀埌 2 绁?gt;1.5)
2 涓妭鐐圭殑 cluster 灏变笉鑳芥寕鎺変换浣?1 涓妭鐐逛簡(leader 鍙互寰楀埌 1 绁?lt;=1)
19. zookeeper 璐熻浇鍧囪 鍜?nginx 璐熻浇鍧囪 鍖哄埆
zk 鐨勮礋杞藉潎琛℃槸鍙互璋冩帶锛宯ginx 鍙槸鑳借皟鏉冮噸锛屽叾浠栭渶瑕佸彲鎺х殑閮介渶瑕佽嚜宸卞啓鎻掍欢锛涗絾鏄?nginx 鐨勫悶鍚愰噺姣?zk 澶у緢澶氾紝搴旇璇存寜涓氬姟閫夋嫨鐢ㄥ摢绉嶆柟寮忋€?/span>
20. Zookeeper 鏈夊摢鍑犵鍑犵閮ㄧ讲妯″紡锛?/p>
Zookeeper 鏈変笁绉嶉儴缃叉ā寮忥細
鍗曟満閮ㄧ讲锛氫竴鍙伴泦缇や笂杩愯锛?/span>
闆嗙兢閮ㄧ讲锛氬鍙伴泦缇よ繍琛岋紱
浼泦缇ら儴缃诧細涓€鍙伴泦缇ゅ惎鍔ㄥ涓?Zookeeper 瀹炰緥杩愯銆?/span>
21. 闆嗙兢鏈€灏戣鍑犲彴鏈哄櫒锛岄泦缇よ鍒欐槸鎬庢牱鐨勶紵闆嗙兢涓湁 3 鍙版湇鍔″櫒锛屽叾涓竴涓妭鐐瑰畷鏈猴紝杩欎釜鏃跺€?Zookeeper 杩樺彲浠ヤ娇鐢ㄥ悧锛?/p>
闆嗙兢瑙勫垯涓?2N+1 鍙帮紝N>0锛屽嵆 3 鍙般€傚彲浠ョ户缁娇鐢紝鍗曟暟鏈嶅姟鍣ㄥ彧瑕佹病瓒呰繃涓€鍗婄殑鏈嶅姟鍣ㄥ畷鏈哄氨鍙互缁х画浣跨敤銆?/span>
22. 闆嗙兢鏀寔鍔ㄦ€佹坊鍔犳満鍣ㄥ悧锛?/p>
鍏跺疄灏辨槸姘村钩鎵╁浜嗭紝Zookeeper 鍦ㄨ繖鏂归潰涓嶅お濂姐€備袱绉嶆柟寮忥細
鍏ㄩ儴閲嶅惎锛氬叧闂墍鏈?Zookeeper 鏈嶅姟锛屼慨鏀归厤缃箣鍚庡惎鍔ㄣ€備笉褰卞搷涔嬪墠瀹㈡埛绔殑浼氳瘽銆?/span>
閫愪釜閲嶅惎锛氬湪杩囧崐瀛樻椿鍗冲彲鐢ㄧ殑鍘熷垯涓嬶紝涓€鍙版満鍣ㄩ噸鍚笉褰卞搷鏁翠釜闆嗙兢瀵瑰鎻愪緵鏈嶅姟銆傝繖鏄瘮杈冨父鐢ㄧ殑鏂瑰紡銆?/span>
3.5 鐗堟湰寮€濮嬫敮鎸佸姩鎬佹墿瀹广€?/span>
23. Zookeeper 瀵硅妭鐐圭殑 watch 鐩戝惉閫氱煡鏄案涔呯殑鍚楋紵涓轰粈涔堜笉鏄案涔呯殑?
涓嶆槸銆傚畼鏂瑰0鏄庯細涓€涓?Watch 浜嬩欢鏄竴涓竴娆℃€х殑瑙﹀彂鍣紝褰撹璁剧疆浜?Watch鐨勬暟鎹彂鐢熶簡鏀瑰彉鐨勬椂鍊欙紝鍒欐湇鍔″櫒灏嗚繖涓敼鍙樺彂閫佺粰璁剧疆浜?Watch 鐨勫鎴风锛屼互渚块€氱煡瀹冧滑銆?/span>
涓轰粈涔堜笉鏄案涔呯殑锛屼妇涓緥瀛愶紝濡傛灉鏈嶅姟绔彉鍔ㄩ绻侊紝鑰岀洃鍚殑瀹㈡埛绔緢澶氭儏鍐典笅锛屾瘡娆″彉鍔ㄩ兘瑕侀€氱煡鍒版墍鏈夌殑瀹㈡埛绔紝缁欑綉缁滃拰鏈嶅姟鍣ㄩ€犳垚寰堝ぇ鍘嬪姏銆?/span>
涓€鑸槸瀹㈡埛绔墽琛?getData(鈥?鑺傜偣 A鈥?true)锛屽鏋滆妭鐐?A 鍙戠敓浜嗗彉鏇存垨鍒犻櫎锛屽鎴风浼氬緱鍒板畠鐨?watch 浜嬩欢锛屼絾鏄湪涔嬪悗鑺傜偣 A 鍙堝彂鐢熶簡鍙樻洿锛岃€屽鎴风鍙堟病鏈夎缃?watch 浜嬩欢锛屽氨涓嶅啀缁欏鎴风鍙戦€併€?/span>
鍦ㄥ疄闄呭簲鐢ㄤ腑锛屽緢澶氭儏鍐典笅锛屾垜浠殑瀹㈡埛绔笉闇€瑕佺煡閬撴湇鍔$鐨勬瘡涓€娆″彉鍔紝鎴戝彧瑕佹渶鏂扮殑鏁版嵁鍗冲彲銆?/span>
24. Zookeeper 鐨?java 瀹㈡埛绔兘鏈夊摢浜涳紵
java 瀹㈡埛绔細zk 鑷甫鐨?zkclient 鍙?Apache 寮€婧愮殑 Curator銆?/span>
25. chubby 鏄粈涔堬紝鍜?zookeeper 姣斾綘鎬庝箞鐪嬶紵
chubby 鏄?google 鐨勶紝瀹屽叏瀹炵幇 paxos 绠楁硶锛屼笉寮€婧愩€倆ookeeper 鏄?chubby鐨勫紑婧愬疄鐜帮紝浣跨敤 zab 鍗忚锛宲axos 绠楁硶鐨勫彉绉嶃€?/span>
26. 璇村嚑涓?zookeeper 甯哥敤鐨勫懡浠ゃ€?/p>
甯哥敤鍛戒护锛歭s get set create delete 绛夈€?/span>
27. ZAB 鍜?Paxos 绠楁硶鐨勮仈绯讳笌鍖哄埆锛?/p>
鐩稿悓鐐癸細
锛?锛変袱鑰呴兘瀛樺湪涓€涓被浼间簬 Leader 杩涚▼鐨勮鑹诧紝鐢卞叾璐熻矗鍗忚皟澶氫釜 Follower 杩涚▼鐨勮繍琛?/span>
锛?锛塋eader 杩涚▼閮戒細绛夊緟瓒呰繃鍗婃暟鐨?Follower 鍋氬嚭姝g‘鐨勫弽棣堝悗锛屾墠浼氬皢涓€涓彁妗堣繘琛屾彁浜?/span>
锛?锛塟AB 鍗忚涓紝姣忎釜 Proposal 涓兘鍖呭惈涓€涓?epoch 鍊兼潵浠h〃褰撳墠鐨?Leader鍛ㄦ湡锛孭axos 涓悕瀛椾负 Ballot
涓嶅悓鐐癸細
ZAB 鐢ㄦ潵鏋勫缓楂樺彲鐢ㄧ殑鍒嗗竷寮忔暟鎹富澶囩郴缁燂紙Zookeeper锛夛紝Paxos 鏄敤鏉ユ瀯寤哄垎甯冨紡涓€鑷存€х姸鎬佹満绯荤粺銆?/span>
28. Zookeeper 鐨勫吀鍨嬪簲鐢ㄥ満鏅?/p>
Zookeeper 鏄竴涓吀鍨嬬殑鍙戝竷/璁㈤槄妯″紡鐨勫垎甯冨紡鏁版嵁绠$悊涓庡崗璋冩鏋讹紝寮€鍙戜汉鍛樺彲浠ヤ娇鐢ㄥ畠鏉ヨ繘琛屽垎甯冨紡鏁版嵁鐨勫彂甯冨拰璁㈤槄銆?/span>
閫氳繃瀵?Zookeeper 涓赴瀵岀殑鏁版嵁鑺傜偣杩涜浜ゅ弶浣跨敤锛岄厤鍚?Watcher 浜嬩欢閫氱煡鏈哄埗锛屽彲浠ラ潪甯告柟渚跨殑鏋勫缓涓€绯诲垪鍒嗗竷寮忓簲鐢ㄤ腑骞撮兘浼氭秹鍙婄殑鏍稿績鍔熻兘锛屽锛?/span>
锛?锛夋暟鎹彂甯?璁㈤槄
锛?锛夎礋杞藉潎琛?/span>
锛?锛夊懡鍚嶆湇鍔?/span>
锛?锛夊垎甯冨紡鍗忚皟/閫氱煡
锛?锛夐泦缇ょ鐞?/span>
锛?锛塎aster 閫変妇
锛?锛夊垎甯冨紡閿?/span>
锛?锛夊垎甯冨紡闃熷垪
鏁版嵁鍙戝竷/璁㈤槄
浠嬬粛
鏁版嵁鍙戝竷/璁㈤槄绯荤粺锛屽嵆鎵€璋撶殑閰嶇疆涓績锛岄【鍚嶆€濅箟灏辨槸鍙戝竷鑰呭彂甯冩暟鎹緵璁㈤槄鑰呰繘琛屾暟鎹闃呫€?/span>
鐩殑
鍔ㄦ€佽幏鍙栨暟鎹紙閰嶇疆淇℃伅锛?/span>
瀹炵幇鏁版嵁锛堥厤缃俊鎭級鐨勯泦涓紡绠$悊鍜屾暟鎹殑鍔ㄦ€佹洿鏂?/span>
璁捐妯″紡
Push 妯″紡
Pull 妯″紡
鏁版嵁锛堥厤缃俊鎭級鐗规€?/span>
锛?锛夋暟鎹噺閫氬父姣旇緝灏?/span>
锛?锛夋暟鎹唴瀹瑰湪杩愯鏃朵細鍙戠敓鍔ㄦ€佹洿鏂?/span>
锛?锛夐泦缇や腑鍚勬満鍣ㄥ叡浜紝閰嶇疆涓€鑷?/span>
濡傦細鏈哄櫒鍒楄〃淇℃伅銆佽繍琛屾椂寮€鍏抽厤缃€佹暟鎹簱閰嶇疆淇℃伅绛?/span>
鍩轰簬 Zookeeper 鐨勫疄鐜版柟寮?/span>
路 鏁版嵁瀛樺偍锛氬皢鏁版嵁锛堥厤缃俊鎭級瀛樺偍鍒?Zookeeper 涓婄殑涓€涓暟鎹妭鐐?/span>
路 鏁版嵁鑾峰彇锛氬簲鐢ㄥ湪鍚姩鍒濆鍖栬妭鐐逛粠 Zookeeper 鏁版嵁鑺傜偣璇诲彇鏁版嵁锛屽苟鍦ㄨ鑺傜偣涓婃敞鍐屼竴涓暟鎹彉鏇?Watcher
路 鏁版嵁鍙樻洿锛氬綋鍙樻洿鏁版嵁鏃讹紝鏇存柊 Zookeeper 瀵瑰簲鑺傜偣鏁版嵁锛孼ookeeper浼氬皢鏁版嵁鍙樻洿閫氱煡鍙戝埌鍚勫鎴风锛屽鎴风鎺ュ埌閫氱煡鍚庨噸鏂拌鍙栧彉鏇村悗鐨勬暟鎹嵆鍙€?/span>
璐熻浇鍧囪
zk 鐨勫懡鍚嶆湇鍔?/span>
鍒嗗竷寮忛€氱煡鍜屽崗璋?/span>
瀵逛簬绯荤粺璋冨害鏉ヨ锛氭搷浣滀汉鍛樺彂閫侀€氱煡瀹為檯鏄€氳繃鎺у埗鍙版敼鍙樻煇涓妭鐐圭殑鐘舵€侊紝鐒跺悗 zk 灏嗚繖浜涘彉鍖栧彂閫佺粰娉ㄥ唽浜嗚繖涓妭鐐圭殑 watcher 鐨勬墍鏈夊鎴风銆?/span>
瀵逛簬鎵ц鎯呭喌姹囨姤锛氭瘡涓伐浣滆繘绋嬮兘鍦ㄦ煇涓洰褰曚笅鍒涘缓涓€涓复鏃惰妭鐐广€傚苟鎼哄甫宸ヤ綔鐨勮繘搴︽暟鎹紝杩欐牱姹囨€荤殑杩涚▼鍙互鐩戞帶鐩綍瀛愯妭鐐圭殑鍙樺寲鑾峰緱宸ヤ綔杩涘害鐨勫疄鏃剁殑鍏ㄥ眬鎯呭喌銆?/span>
zk 鐨勫懡鍚嶆湇鍔★紙鏂囦欢绯荤粺锛?/span>
zk 鐨勯厤缃鐞嗭紙鏂囦欢绯荤粺銆侀€氱煡鏈哄埗锛?/span>
绋嬪簭鍒嗗竷寮忕殑閮ㄧ讲鍦ㄤ笉鍚岀殑鏈哄櫒涓婏紝灏嗙▼搴忕殑閰嶇疆淇℃伅鏀惧湪 zk 鐨?znode 涓嬶紝褰撴湁閰嶇疆鍙戠敓鏀瑰彉鏃讹紝涔熷氨鏄?znode 鍙戠敓鍙樺寲鏃讹紝鍙互閫氳繃鏀瑰彉 zk 涓煇涓洰褰曡妭鐐圭殑鍐呭锛屽埄鐢?watcher 閫氱煡缁欏悇涓鎴风锛屼粠鑰屾洿鏀归厤缃€?/span>
Zookeeper 闆嗙兢绠$悊锛堟枃浠剁郴缁熴€侀€氱煡鏈哄埗锛?/span>
鎵€璋撻泦缇ょ鐞嗘棤鍦ㄤ箮涓ょ偣锛氭槸鍚︽湁鏈哄櫒閫€鍑哄拰鍔犲叆銆侀€変妇 master銆?/span>
瀵逛簬绗竴鐐癸紝鎵€鏈夋満鍣ㄧ害瀹氬湪鐖剁洰褰曚笅鍒涘缓涓存椂鐩綍鑺傜偣锛岀劧鍚庣洃鍚埗鐩綍鑺傜偣
鐨勫瓙鑺傜偣鍙樺寲娑堟伅銆備竴鏃︽湁鏈哄櫒鎸傛帀锛岃鏈哄櫒涓?zookeeper 鐨勮繛鎺ユ柇寮€锛屽叾鎵€鍒涘缓鐨勪复鏃剁洰褰曡妭鐐硅鍒犻櫎锛屾墍鏈夊叾浠栨満鍣ㄩ兘鏀跺埌閫氱煡锛氭煇涓厔寮熺洰褰曡鍒犻櫎锛屼簬鏄紝鎵€鏈変汉閮界煡閬擄細瀹冧笂鑸逛簡銆?/span>
鏂版満鍣ㄥ姞鍏ヤ篃鏄被浼硷紝鎵€鏈夋満鍣ㄦ敹鍒伴€氱煡锛氭柊鍏勫紵鐩綍鍔犲叆锛宧ighcount 鍙堟湁浜嗭紝瀵逛簬绗簩鐐癸紝鎴戜滑绋嶅井鏀瑰彉涓€涓嬶紝鎵€鏈夋満鍣ㄥ垱寤轰复鏃堕『搴忕紪鍙风洰褰曡妭鐐癸紝姣忔閫夊彇缂栧彿鏈€灏忕殑鏈哄櫒浣滀负 master 灏卞ソ銆?/span>
Zookeeper 鍒嗗竷寮忛攣锛堟枃浠剁郴缁熴€侀€氱煡鏈哄埗锛?/span>
鏈変簡 zookeeper 鐨勪竴鑷存€ф枃浠剁郴缁燂紝閿佺殑闂鍙樺緱瀹规槗銆傞攣鏈嶅姟鍙互鍒嗕负涓ょ被锛屼竴涓槸淇濇寔鐙崰锛屽彟涓€涓槸鎺у埗鏃跺簭銆?/span>
瀵逛簬绗竴绫伙紝鎴戜滑灏?zookeeper 涓婄殑涓€涓?znode 鐪嬩綔鏄竴鎶婇攣锛岄€氳繃 createznode鐨勬柟寮忔潵瀹炵幇銆傛墍鏈夊鎴风閮藉幓鍒涘缓 /distribute_lock 鑺傜偣锛屾渶缁堟垚鍔熷垱寤虹殑閭d釜瀹㈡埛绔篃鍗虫嫢鏈変簡杩欐妸閿併€傜敤瀹屽垹闄ゆ帀鑷繁鍒涘缓鐨?distribute_lock 鑺傜偣灏遍噴鏀惧嚭閿併€?/span>
瀵逛簬绗簩绫伙紝 /distribute_lock 宸茬粡棰勫厛瀛樺湪锛屾墍鏈夊鎴风鍦ㄥ畠涓嬮潰鍒涘缓涓存椂椤哄簭缂栧彿鐩綍鑺傜偣锛屽拰閫?master 涓€鏍凤紝缂栧彿鏈€灏忕殑鑾峰緱閿侊紝鐢ㄥ畬鍒犻櫎锛屼緷娆℃柟渚裤€?/span>
Zookeeper 闃熷垪绠$悊锛堟枃浠剁郴缁熴€侀€氱煡鏈哄埗锛?/span>
涓ょ绫诲瀷鐨勯槦鍒楋細
锛?锛夊悓姝ラ槦鍒楋紝褰撲竴涓槦鍒楃殑鎴愬憳閮借仛榻愭椂锛岃繖涓槦鍒楁墠鍙敤锛屽惁鍒欎竴鐩寸瓑寰呮墍鏈夋垚鍛樺埌杈俱€?/span>
锛?锛夐槦鍒楁寜鐓?FIFO 鏂瑰紡杩涜鍏ラ槦鍜屽嚭闃熸搷浣溿€?/span>
绗竴绫伙紝鍦ㄧ害瀹氱洰褰曚笅鍒涘缓涓存椂鐩綍鑺傜偣锛岀洃鍚妭鐐规暟鐩槸鍚︽槸鎴戜滑瑕佹眰鐨勬暟鐩€?/span>
绗簩绫伙紝鍜屽垎甯冨紡閿佹湇鍔′腑鐨勬帶鍒舵椂搴忓満鏅熀鏈師鐞嗕竴鑷达紝鍏ュ垪鏈夌紪鍙凤紝鍑哄垪鎸夌紪鍙枫€傚湪鐗瑰畾鐨勭洰褰曚笅鍒涘缓 PERSISTENT_SEQUENTIAL 鑺傜偣锛屽垱寤烘垚鍔熸椂Watcher 閫氱煡绛夊緟鐨勯槦鍒楋紝闃熷垪鍒犻櫎搴忓垪鍙锋渶灏忕殑鑺傜偣鐢ㄤ互娑堣垂銆傛鍦烘櫙涓媄ookeeper 鐨?znode 鐢ㄤ簬娑堟伅瀛樺偍锛寊node 瀛樺偍鐨勬暟鎹氨鏄秷鎭槦鍒椾腑鐨勬秷鎭唴瀹癸紝SEQUENTIAL 搴忓垪鍙峰氨鏄秷鎭殑缂栧彿锛屾寜搴忓彇鍑哄嵆鍙€傜敱浜庡垱寤虹殑鑺傜偣鏄寔涔呭寲鐨勶紝鎵€浠ヤ笉蹇呮媴蹇冮槦鍒楁秷鎭殑涓㈠け闂銆?/span>
29. Zookeeper 閮芥湁鍝簺鍔熻兘锛?/p>
闆嗙兢绠$悊锛氱洃鎺ц妭鐐瑰瓨娲荤姸鎬併€佽繍琛岃姹傜瓑锛?/span>
涓昏妭鐐归€変妇锛氫富鑺傜偣鎸傛帀浜嗕箣鍚庡彲浠ヤ粠澶囩敤鐨勮妭鐐瑰紑濮嬫柊涓€杞€変富锛屼富鑺傜偣閫変妇璇寸殑灏辨槸杩欎釜閫変妇鐨勮繃绋嬶紝浣跨敤 Zookeeper 鍙互鍗忓姪瀹屾垚杩欎釜杩囩▼锛?/span>
鍒嗗竷寮忛攣锛歓ookeeper 鎻愪緵涓ょ閿侊細鐙崰閿併€佸叡浜攣銆傜嫭鍗犻攣鍗充竴娆″彧鑳芥湁涓€涓嚎绋嬩娇鐢ㄨ祫婧愶紝鍏变韩閿佹槸璇婚攣鍏变韩锛岃鍐欎簰鏂ワ紝鍗冲彲浠ユ湁澶氱嚎绾跨▼鍚屾椂璇诲悓涓€涓祫婧愶紝濡傛灉瑕佷娇鐢ㄥ啓閿佷篃鍙兘鏈変竴涓嚎绋嬩娇鐢ㄣ€俍ookeeper 鍙互瀵瑰垎甯冨紡閿佽繘琛屾帶鍒躲€?/span>
30. 璇翠竴涓?Zookeeper 鐨勯€氱煡鏈哄埗锛?/p>
client 绔細瀵规煇涓?znode 寤虹珛涓€涓?watcher 浜嬩欢锛屽綋璇?znode 鍙戠敓鍙樺寲鏃讹紝杩欎簺 client 浼氭敹鍒?zk 鐨勯€氱煡锛岀劧鍚?client 鍙互鏍规嵁 znode 鍙樺寲鏉ュ仛鍑轰笟鍔′笂鐨勬敼鍙樼瓑銆?/span>
31. Zookeeper 鍜?Dubbo 鐨勫叧绯伙紵
Zookeeper鐨勪綔鐢細
dubbo锛?/span>
鏄鐞嗕腑闂村眰鐨勫伐鍏凤紝鍦ㄤ笟鍔″眰鍒版暟鎹粨搴撻棿鏈夐潪甯稿鏈嶅姟鐨勬帴鍏ュ拰鏈嶅姟鎻愪緵鑰呴渶瑕佽皟搴︼紝dubbo鎻愪緵涓€涓鏋惰В鍐宠繖涓棶棰樸€?br class="mq-750">娉ㄦ剰杩欓噷鐨刣ubbo鍙槸涓€涓鏋讹紝鑷充簬浣犳灦瀛愪笂鏀句粈涔堟槸瀹屽叏鍙栧喅浜庝綘鐨勶紝灏卞儚涓€涓苯杞﹂鏋讹紝浣犻渶瑕侀厤浣犵殑杞瓙寮曟搸銆傝繖涓鏋朵腑瑕佸畬鎴愯皟搴﹀繀椤昏鏈変竴涓垎甯冨紡鐨勬敞鍐屼腑蹇冿紝鍌ㄥ瓨鎵€鏈夋湇鍔$殑鍏冩暟鎹紝浣犲彲浠ョ敤zk锛屼篃鍙互鐢ㄥ埆鐨勶紝鍙槸澶у閮界敤zk銆?/span>
zookeeper鍜宒ubbo鐨勫叧绯伙細
Dubbo 鐨勫皢娉ㄥ唽涓績杩涜鎶借薄锛屽畠鍙互澶栨帴涓嶅悓鐨勫瓨鍌ㄥ獟浠嬬粰娉ㄥ唽涓績鎻愪緵鏈嶅姟锛屾湁 ZooKeeper锛孧emcached锛孯edis 绛夈€?/span>
鍑哄锛歨ttps://blog.csdn.net/ThinkWon/article/details/104397719
以上是关于涓€鏂囧交搴曟悶鎳?zookeeper 鏍稿績鐭ヨ瘑鐐?的主要内容,如果未能解决你的问题,请参考以下文章
馃幆銆愭繁鍏ヨВ鏋愩€戣法绔鏋剁殑鏍稿績鎶€鏈埌搴曟槸浠€涔堬紵