ZooKeeper-瀹夎

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ZooKeeper-瀹夎相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/apach' title='apach'>apach   htm   ini   rpo   tac   ror   pid   add   

涓嬭浇

涓嬭浇鍦板潃 zookeeper锛屽缓璁笅杞?bin 缁撳熬鐨則ar鍖呫€?/p>

鍦?readme.md 涓彲浠ョ湅鍒?/p>

apache-zookeeper-[version].tar.gz

        Contains all the source files which can be built by running:
        mvn clean install

        To generate an aggregated apidocs for zookeeper-server and zookeeper-jute:
        mvn javadoc:aggregate
        (generated files will be at target/site/apidocs)

apache-zookeeper-[version]-bin.tar.gz

        Contains all the jar files required to run ZooKeeper
        Full documentation can also be found in the docs folder

涓嶄互 bin 缁撳熬鐨勯渶瑕?nbsp;mvn clean install锛屾垜璇曡繃杩欎釜 tar 鍖咃紝楹荤儲...

 

鍗曟満瀹夎

瑙e帇 tar 鍖?/p>

杩涘叆 zookeeper 鐩綍锛屽缓绔?data 鏂囦欢澶?/p>

鎶€鏈浘鐗? src=

杩涘叆conf锛屼慨鏀?span style="background-color: #00ffff;">閰嶇疆鏂囦欢

鍒濆鐨勯厤缃枃浠舵槸 zoo_sample.cfg锛寊ookeeper 榛樿浣跨敤 zoo.cfg锛屽彲浠ユ柊寤轰竴涓?zoo.cfg锛屼篃鍙互鎶?nbsp;zoo_sample cp 鎴?zoo

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/kafka/apache-zookeeper-3.5.5-bin/data
clientPort=2181

tickTime锛歾k 鏈嶅姟鍣ㄤ箣闂存垨鑰呭鎴风涓庢湇鍔″櫒涔嬮棿蹇冭烦鐨勬椂闂撮棿闅旓紝姣

initLimit锛?/p>

dataDir锛歾k 鏁版嵁瀛樺偍璺緞

clientPort锛歾k 鏈嶅姟鍣ㄧ洃鍚殑绔彛

 

閰嶇疆瀹屾垚锛屽氨鍙互鍚姩鏈嶅姟鍣?/span>浜嗭紝姝e父鎯呭喌涓嬭緭鍑哄涓?/p>

[root@localhost apache-zookeeper-3.5.5-bin]# bin/zkServer.sh start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/kafka/apache-zookeeper-3.5.5-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

浣嗘槸涓婇潰骞朵笉鑳借鏄庢湇鍔″櫒宸茬粡鍚姩锛屽彲浠?span style="background-color: #00ffff;">鏌ョ湅鏈嶅姟鍣ㄧ姸鎬?/span>

[root@localhost apache-zookeeper-3.5.5-bin]# bin/zkServer.sh status
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/kafka/apache-zookeeper-3.5.5-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Error contacting service. It is probably not running.

鎴戜滑鍙戠幇骞舵湭鎴愬姛鍚姩銆?/p>

 

姝ゆ椂锛岄渶瑕佹煡鐪嬫棩蹇?/p>

鎶€鏈浘鐗? src=

鎵撳紑鏃ュ織锛屽彲浠ョ湅鍒?Error锛屾彁绀?杩炰笉涓?8080 绔彛锛屾垜鎯冲埌鏄笉鏄?8080 琚崰鐢ㄤ簡锛屾煡浜嗕竴涓嬫灉鐒?/p>

netstat -anp | grep 8080

缁撴潫璇ヨ繘绋嬶紝閲嶆柊鍚姩鏈嶅姟鍣紝OK浜?/p>

[root@localhost apache-zookeeper-3.5.5-bin]# bin/zkServer.sh start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/kafka/apache-zookeeper-3.5.5-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

[root@localhost apache
-zookeeper-3.5.5-bin]# bin/zkServer.sh status /usr/bin/java ZooKeeper JMX enabled by default Using config: /usr/local/kafka/apache-zookeeper-3.5.5-bin/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Mode: standalone

杈撳嚭濡備笂浠h〃鍚姩鎴愬姛銆?/p>

 

鍋滄鏈嶅姟鍣?/span>

[root@localhost apache-zookeeper-3.5.5-bin]# bin/zkServer.sh stop
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/kafka/apache-zookeeper-3.5.5-bin/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED

 

鎬濊€?/span> zookeeper 鍦ㄥ摢閲岀敤鍒?8080 绔彛浜嗗憿锛熷湪 AdminServe 涓壘鍒颁簡杩欎釜閰嶇疆

鎶€鏈浘鐗? src=

<ul>
  <li><p><em>admin.enableServer</em> : (Java system property: <strong>zookeeper.admin.enableServer</strong>) Set to "false" to disable the AdminServer. By default the AdminServer is enabled.</p></li>
  <li><p><em>admin.serverAddress</em> : (Java system property: <strong>zookeeper.admin.serverAddress</strong>) The address the embedded Jetty server listens on. Defaults to 0.0.0.0.</p></li>
  <li><p><em>admin.serverPort</em> : (Java system property: <strong>zookeeper.admin.serverPort</strong>) The port the embedded Jetty server listens on. Defaults to 8080.</p></li>
  <li><p><em>admin.idleTimeout</em> : (Java system property: <strong>zookeeper.admin.idleTimeout</strong>) Set the maximum idle time in milliseconds that a connection can wait before sending or receiving data. Defaults to 30000 ms.</p></li>
  <li><p><em>admin.commandURL</em> : (Java system property: <strong>zookeeper.admin.commandURL</strong>) The URL for listing and issuing commands relative to the root URL. Defaults to "/commands".</p></li>
</ul>

瑙e喅杩欎釜闂鐨勬柟娉曟湁涓夌锛?/p>

1. 淇敼绔彛

涓ょ鏂瑰紡锛氬惎鍔ㄦ椂澧炲姞閰嶇疆椤?nbsp; -Dzookeeper.admin.serverPort=浣犵殑绔彛鍙凤紱鍦?zoo.cfg 涓鍔犻厤缃?nbsp;admin.serverPort=娌℃湁琚崰鐢ㄧ殑绔彛鍙?/span>

2. 鍒犻櫎 jetty

3. 鍋滅敤杩欎釜鏈嶅姟锛屽湪鍚姩鏃跺鍔犻厤缃」 -Dzookeeper.admin.enableServer=false

 

鏈嶅姟鍣ㄥ惎鍔ㄥ悗锛屽氨鍙互鍚姩瀹㈡埛绔?/span>杩涚▼娴嬭瘯浜?/p>

[root@localhost apache-zookeeper-3.5.5-bin]# bin/zkCli.sh

鍑虹幇濡備笅鐣岄潰

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] 

 

杈撳叆 help 鏌ョ湅鍛戒护

[zk: localhost:2181(CONNECTED) 0] help
ZooKeeper -server host:port cmd args
    addauth scheme auth
    close 
    config [-c] [-w] [-s]
    connect host:port
    create [-s] [-e] [-c] [-t ttl] path [data] [acl]
    delete [-v version] path
    deleteall path
    delquota [-n|-b] path
    get [-s] [-w] path
    getAcl [-s] path
    history 
    listquota path
    ls [-s] [-w] [-R] path
    ls2 path [watch]
    printwatches on|off
    quit 
    reconfig [-s] [-v version] [[-file path] | [-members serverID=host:port1:port2;port3[,...]*]] | [-add serverId=host:port1:port2;port3[,...]]* [-remove serverId[,...]*]
    redo cmdno
    removewatches path [-c|-d|-a] [-l]
    rmr path
    set [-s] [-v version] path data
    setAcl [-s] [-v version] [-R] path acl
    setquota -n|-b val path
    stat [-w] path
    sync path

 

鍒涘缓鑺傜偣锛岃祴鍊硷紝鍙栧€硷紝鍒犻櫎锛屾煡鐪嬫牴鑺傜偣

[zk: localhost:2181(CONNECTED) 17] ls /
[zookeeper]
[zk: localhost:2181(CONNECTED) 18] create /mykey1
Created /mykey1
[zk: localhost:2181(CONNECTED) 19] create /mykey2
Created /mykey2
[zk: localhost:2181(CONNECTED) 20] set /mykey1 3
[zk: localhost:2181(CONNECTED) 21] get /mykey1
3
[zk: localhost:2181(CONNECTED) 22] ls /
[mykey1, mykey2, zookeeper]
[zk: localhost:2181(CONNECTED) 23] delete /mykey1
[zk: localhost:2181(CONNECTED) 24] ls /
[mykey2, zookeeper]

 

闆嗙兢瀹夎

鐢变簬鍙湁涓€鍙版湇鍔″櫒锛屾湰娆″畨瑁呬吉鍒嗗竷寮忛泦缇わ紝涓庡垎甯冨紡瀹夎杩囩▼闆峰悓銆?/p>

浼泦缇?/span>鏄寚鐢ㄤ竴鍙版湇鍔″櫒鐨勫涓鍙fā鎷熷鍙版湇鍔″櫒锛岀敤澶氫釜閰嶇疆鏂囦欢鍚姩澶氫釜 zookeeper 瀹炰緥銆?/p>

涓庨泦缇ゅ畨瑁?span style="background-color: #00ffff;">涓嶅悓鐐?/span>锛?/p>

1. 鐢变簬鍦ㄤ竴鍙版湇鍔″櫒涓婏紝zookeeper 鏈嶅姟鍣ㄧ洃鍚殑绔彛涓嶈兘鐩稿悓锛屽嵆 clientPort 涓嶇浉鍚岋紝鑰岄泦缇ゅ彲浠ョ浉鍚?/p>

2. 鏁版嵁瀛樺偍璺緞涓嶅悓锛屽嵆 dataDir 涓嶇浉鍚岋紱涔熸湁蹇呰鎶?dataLogDir 鍚姩鏃ュ織鍒嗗紑瀛樺偍锛屽綋鐒?log 璺緞鐩稿悓涔熷彲浠?/p>

3. server.x 涓?myid 锛歴erver.x 涓殑 x 绛変簬 myid 鏂囦欢閲岀殑鏁板瓧銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆愯繖涓や釜鍦ㄥ崟涓湇鍔″櫒瀹夎涓槸娌℃湁鐨勩€?/p>

銆€銆€// myid 鏂囦欢涓彧鍐欎簡涓€涓暟瀛楋紝浠h〃璇ヨ妭鐐瑰湪闆嗙兢涓殑瑙掕壊 id锛宮yid 鏂囦欢闇€瑕佹墜鍔ㄥ垱寤恒€€

銆€銆€// server.x 瀵瑰簲鏈嶅姟鍣?IP 鍜岀鍙o紝鍚屼竴鍙版湇鍔″櫒涓婇渶瑕佽繛涓や釜绔彛锛屼笖涓嶅悓 server 绔彛涓嶈兘鐩稿悓

 

瀹夎杩囩▼

绗竴姝ワ紝鏂板缓3涓厤缃枃浠?zoo1.cfg锛?zoo2.cfg锛?zoo3.cfg

鎶€鏈浘鐗? src=

zoo1.cfg 閰嶇疆濡備笅

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper/zk1/data
clientPort=2182
dataLogDir=/usr/local/zookeeper/zk1/logs

server.1=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389

鍏朵腑3涓厤缃枃浠剁殑 dataDir 涓嶈兘鐩稿悓锛宒ataLogDir 涔熶笉瑕佺浉鍚岋紱

鍚庨潰鐨?server.x 蹇呴』鍐欙紝3涓厤缃枃浠朵竴鏍凤紱

 

绗簩姝ワ紝寤虹珛 dataDir 鍜?nbsp;dataLogDir 瀵瑰簲鐨勮矾寰?/p>

绗笁姝?/span>锛屽湪姣忎釜 dataDir 涓嬪垱寤?myid 鏂囦欢锛屽苟鍐欏叆涓€涓暟瀛楋紝瀵瑰簲 server.x 涓殑 x銆€銆€銆€銆€銆愭敞鎰忓繀椤绘妸姣忎釜鏈嶅姟鐨?myid 閮藉厛鍐欏ソ锛屼笉鑳藉啓涓€涓惎鍔ㄤ竴涓€?/p>

绗洓姝ワ紝鍚姩 zookeeper 鏈嶅姟锛屾瘡涓湇鍔℃寚瀹氫笉鍚岀殑閰嶇疆鏂囦欢

[root@localhost apache-zookeeper-3.5.5-bin]# bin/zkServer.sh start conf/zoo1.cfg 
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: conf/zoo1.cfg
Starting zookeeper ... STARTED
[root@localhost apache
-zookeeper-3.5.5-bin]# bin/zkServer.sh status conf/zoo1.cfg /usr/bin/java ZooKeeper JMX enabled by default Using config: conf/zoo1.cfg Client port found: 2191. Client address: localhost. Error contacting service. It is probably not running.

鍚姩绗竴涓?zookeeper 鏈嶅姟鏃讹紝鍙戠敓閿欒浜嗭紝杩欏叾瀹炴槸姝e父鐜拌薄

鍥犱负 zookeeper 鏈嶅姟鐨勬瘡涓疄渚嬮兘鎷ユ湁鍏ㄥ眬閰嶇疆淇℃伅锛屼粬浠湪鍚姩鏃朵細闅忔椂闅忓湴閫変妇 leader锛屼篃灏辨槸 瑕佷笌鍏朵粬 zookeeper 瀹炰緥杩涜閫氫俊锛岃€屾鏃跺叾浠栫殑 zookeeper 鏈嶅姟杩樻病鍚姩锛岃嚜鐒舵棤娉曢€氫俊锛屾晠鎶ラ敊

姝ゆ椂鎴戜滑蹇界暐姝ら敊璇紝鐩存帴鎶?3 涓湇鍔″叏閮ㄥ惎鍔?/p>

鐒跺悗妫€鏌ョ姸鎬侊紝鍙戠幇涓€鍒囨甯镐簡銆?/p>

[root@localhost apache-zookeeper-3.5.5-bin]# bin/zkServer.sh status conf/zoo1.cfg 
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: conf/zoo1.cfg
Client port found: 2191. Client address: localhost.
Mode: follower
[root@localhost apache
-zookeeper-3.5.5-bin]# bin/zkServer.sh status conf/zoo2.cfg /usr/bin/java ZooKeeper JMX enabled by default Using config: conf/zoo2.cfg Client port found: 2192. Client address: localhost. Mode: leader

骞朵笖鏄剧ず浜?涓讳粠鍏崇郴銆?/p>

 

 

 

鍙傝€冭祫鏂欙細

https://blog.csdn.net/qq_27868061/article/details/91383759銆€銆€zookeeper3.5.5瀹夎

https://www.jianshu.com/p/f6c96b2d4b6a銆€銆€centos7 zookeeper3.5.5 瀹夎

https://www.cnblogs.com/crazylqy/p/7119030.html銆€銆€瀹夎zookeeper锛堝崟鏈猴紝浼泦缇わ級

https://www.cnblogs.com/songfayuan/articles/7290175.html銆€銆€ZooKeeper鍚姩鍗犵敤8080绔彛

以上是关于ZooKeeper-瀹夎的主要内容,如果未能解决你的问题,请参考以下文章

Zookeeper -- 初识ZookeeperZookeeper的安装和配置Zookeeper命令操作(Zookeeper数据模型 Zookeeper服务端 / 客户端常用命令)

ZooKeeper集群

ZooKeeper集群

Zookeeper集群部署

zookeeper概述和部署

zookeeper概述和部署