zookeeper之集羣--轉載

ZooKeeper介紹請見官網。

1.環境說明

在兩臺裝有centos6.4(32位)的服務器上安裝ZooKeeper,官網建議至少3個節點,資源有限,本次實驗就2臺了。

需要提前安裝jdk,選擇的版本是jdk-6u27-Linux-i586.bin,下載地址:http://pan.baidu.com/s/1mgICcFA

 

2.配置主機名和ip映射的關係。

ZooKeeper集羣所有的結點作爲一個整體對分佈式應用提供服務,因此需要各個節點實現互連,就要知道其他節點的主機和ip的映射關係。在每個節點上配置/etc/hosts文件,添加如下:

 

[plain] view plain copy
 
  1. 192.168.1.67 MasterServer  
  2. 192.168.1.241 SlaveServer  

 

 

3.安裝ZooKeeper

1)下載ZooKeeper,建議選擇穩定版,即stable的。

 

[plain] view plain copy
 
  1. wget http://apache.dataguru.cn/zookeeper/stable/zookeeper-3.4.6.tar.gz  

2)解壓

 

 

[plain] view plain copy
 
  1. tar -zxvf zookeeper-3.4.6.tar.gz  

3)修改/etc/profile,添加ZooKeeper路徑

 

 

[plain] view plain copy
 
  1. export ZOOKEEPER_HOME=/home/hadooper/hadoop/zookeeper-3.4.6  
  2.   
  3. export PATH=$ZOOKEEPER_HOME/bin:$ZOOKEEPER_HOME/conf:$PATH  

4)新建zoo.cfg並修改

 

 

[plain] view plain copy
 
  1. cp conf/zoo_sample.cfg conf/zoo.cfg   
[plain] view plain copy
 
  1. # The number of milliseconds of each tick  
  2. tickTime=2000  
  3. # The number of ticks that the initial   
  4. # synchronization phase can take  
  5. initLimit=10  
  6. # The number of ticks that can pass between   
  7. # sending a request and getting an acknowledgement  
  8. syncLimit=5  
  9. # the directory where the snapshot is stored.  
  10. # do not use /tmp for storage, /tmp here is just   
  11. # example sakes.  
  12. dataDir=/home/hadooper/hadoop/zookeeper-3.4.6/data  
  13. # the port at which the clients will connect  
  14. clientPort=2181  
  15. # the maximum number of client connections.  
  16. # increase this if you need to handle more clients  
  17. #maxClientCnxns=60  
  18. #  
  19. # Be sure to read the maintenance section of the   
  20. # administrator guide before turning on autopurge.  
  21. #  
  22. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance  
  23. #  
  24. # The number of snapshots to retain in dataDir  
  25. #autopurge.snapRetainCount=3  
  26. # Purge task interval in hours  
  27. # Set to "0" to disable auto purge feature  
  28. #autopurge.purgeInterval=1  
  29. server.1=MasterServer:2888:3888  
  30. server.2=SlaveServer:2888:3888   

參數說明:

 

①tickTime:心跳時間,毫秒爲單位。

②initLimit:這個配置項是用來配置 Zookeeper 接受客戶端(這裏所說的客戶端不是用戶連接 Zookeeper服務器的客戶端,而是 Zookeeper 服務器集羣中連接到 Leader 的 Follower 服務器)初始化連接時最長能忍受多少個心跳時間間隔數。當已經超過 10 個心跳的時間(也就是 tickTime)長度後 Zookeeper 服務器還沒有收到客戶端的返回信息,那麼表明這個客戶端連接失敗。總的時間長度就是 10*2000=20 秒。

③syncLimit:這個配置項標識 Leader 與 Follower 之間發送消息,請求和應答時間長度,最長不能超過多少個 tickTime 的時間長度,總的時間長度就是 5*2000=10 秒。

④dataDir:存儲內存中數據庫快照的位置。

⑤clientPort:監聽客戶端連接的端口

⑥server.A=B:C:D:其中 A 是一個數字,表示這個是第幾號服務器;B 是這個服務器的 ip 地址;C 表示的是這個服務器與集羣中的 Leader 服務器交換信息的端口;D 表示的是萬一集羣中的 Leader 服務器掛了,需要一個端口來重新進行選舉,選出一個新的 Leader,而這個端口就是用來執行選舉時服務器相互通信的端口。如果是僞集羣的配置方式,由於 B 都是一樣,所以不同的 Zookeeper 實例通信端口號不能一樣,所以要給它們分配不同的端口號。

5)dataDir目錄下創建myid文件,將內容設置爲上⑥中的A值,用來標識不同的服務器。

 

4.遠程複製安裝文件

注:記得修改各節點的myid。

 

[plain] view plain copy
 
  1. scp -r zookeeper-3.3.4/ hadooper@SlaveServer:/home/hadooper/hadoop/    

轉載請註明:http://blog.csdn.net/hwwn2009/article/details/40000881

 

5.測試ZooKeeper

 

1)各節點上啓動

 

[plain] view plain copy
 
  1. [hadooper@MasterServer zookeeper-3.4.6]$ bin/zkServer.sh start  

2)jps查看進程

 

 

[plain] view plain copy
 
  1. 30056 QuorumPeerMain  

QuorumPeerMain是zookeeper進程,說明啓動正常。
3)查看狀態

 

 

[plain] view plain copy
 
  1. [hadooper@MasterServer zookeeper-3.4.6]$ bin/zkServer.sh status  
[plain] view plain copy
 
  1. JMX enabled by default  
  2. Using config: /home/hadooper/hadoop/zookeeper-3.4.6/bin/../conf/zoo.cfg  
  3. Mode: follower  

 

 

[plain] view plain copy
 
  1. [hadooper@SlaveServer zookeeper-3.4.6]$ bin/zkServer.sh status  
  2. JMX enabled by default  
  3. Using config: /home/hadooper/hadoop/zookeeper-3.4.6/bin/../conf/zoo.cfg  
  4. Mode: leader  

 

注:SlaveServer 爲集羣的leader。

4)停止ZooKeeper

 

[plain] view plain copy
 
  1. [hadooper@MasterServer zookeeper-3.4.6]$ bin/zkServer.sh stop  

轉載請註明:http://blog.csdn.net/hwwn2009/article/details/40000881

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章