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文件,添加如下:
- 192.168.1.67 MasterServer
- 192.168.1.241 SlaveServer
3.安裝ZooKeeper
1)下載ZooKeeper,建議選擇穩定版,即stable的。
- wget http://apache.dataguru.cn/zookeeper/stable/zookeeper-3.4.6.tar.gz
2)解壓
- tar -zxvf zookeeper-3.4.6.tar.gz
3)修改/etc/profile,添加ZooKeeper路徑
- export ZOOKEEPER_HOME=/home/hadooper/hadoop/zookeeper-3.4.6
- export PATH=$ZOOKEEPER_HOME/bin:$ZOOKEEPER_HOME/conf:$PATH
4)新建zoo.cfg並修改
- cp conf/zoo_sample.cfg conf/zoo.cfg
- # The number of milliseconds of each tick
- tickTime=2000
- # The number of ticks that the initial
- # synchronization phase can take
- initLimit=10
- # The number of ticks that can pass between
- # sending a request and getting an acknowledgement
- syncLimit=5
- # the directory where the snapshot is stored.
- # do not use /tmp for storage, /tmp here is just
- # example sakes.
- dataDir=/home/hadooper/hadoop/zookeeper-3.4.6/data
- # the port at which the clients will connect
- clientPort=2181
- # the maximum number of client connections.
- # increase this if you need to handle more clients
- #maxClientCnxns=60
- #
- # Be sure to read the maintenance section of the
- # administrator guide before turning on autopurge.
- #
- # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
- #
- # The number of snapshots to retain in dataDir
- #autopurge.snapRetainCount=3
- # Purge task interval in hours
- # Set to "0" to disable auto purge feature
- #autopurge.purgeInterval=1
- server.1=MasterServer:2888:3888
- 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。
- scp -r zookeeper-3.3.4/ hadooper@SlaveServer:/home/hadooper/hadoop/
轉載請註明:http://blog.csdn.net/hwwn2009/article/details/40000881
5.測試ZooKeeper
1)各節點上啓動
- [hadooper@MasterServer zookeeper-3.4.6]$ bin/zkServer.sh start
2)jps查看進程
- 30056 QuorumPeerMain
QuorumPeerMain是zookeeper進程,說明啓動正常。
3)查看狀態
- [hadooper@MasterServer zookeeper-3.4.6]$ bin/zkServer.sh status
- JMX enabled by default
- Using config: /home/hadooper/hadoop/zookeeper-3.4.6/bin/../conf/zoo.cfg
- Mode: follower
- [hadooper@SlaveServer zookeeper-3.4.6]$ bin/zkServer.sh status
- JMX enabled by default
- Using config: /home/hadooper/hadoop/zookeeper-3.4.6/bin/../conf/zoo.cfg
- Mode: leader
注:SlaveServer 爲集羣的leader。
4)停止ZooKeeper
- [hadooper@MasterServer zookeeper-3.4.6]$ bin/zkServer.sh stop
轉載請註明:http://blog.csdn.net/hwwn2009/article/details/40000881