ZooKeeper是一個分佈式的,開放源碼的分佈式應用程序協調服務,是Google的Chubby一個開源的實現,是Hadoop和Hbase的重要組件。它是一個爲分佈式應用提供一致性服務的軟件,提供的功能包括:配置維護、域名服務、分佈式同步、組服務等。 Zookeeper是一個分佈式協調服務;就是爲用戶的分佈式應用程序提供協調服務 |序號 |功能 | |--|--| |1 |爲別的分佈式程序服務的| |2 |自己就是一個分佈式程序| |3 |主從協調 服務器節點動態上下線 統一配置管理 分佈式共享鎖 一名稱服務| |4 |管理(存儲,讀取)用戶程序提交的數據 併爲用戶程序提供數據節點監聽服務|html
zookeeper是爲其餘分佈式程序提供服務的,因此自己本身不能隨便就掛了,因此zookeeper自身的集羣機制就很重要。zookeeper的集羣機制採用的是半數存活機制,也就是整個集羣節點中有半數以上的節點存活,那麼整個集羣環境可用。這也就是說們的集羣節點最好是奇數個節點。node
Leader服務器是Zookeeper集羣工做的核心,其主要工做以下linux
事務請求的惟一調度和處理者,保證集羣事務處理的順序性。 集羣內部各服務器的調度者。apache
Follower是Zookeeper集羣的跟隨者,其主要工做以下服務器
處理客戶端非事務性請求(讀取數據),轉發事務請求給Leader服務器。 參與事務請求Proposal的投票。 參與Leader選舉投票。
ip | 主機名 |
---|---|
192.168.119.20 | zek00 |
192.168.119.21 | zek01 |
192.168.119.22 | zek02 |
刪除 HWADDR這行信息
ssh
其餘兩個節點也這樣配置
刪除一個文件
三個節點修改主機名
重啓分佈式
ssh-keygen
四次回車便可 而後四次回車就能夠了,而後就能夠在當前登陸用戶的主目錄下能夠查看到.ssh目錄,公鑰和私鑰就保存在該目錄中 ide
ssh-copy-id zek00 ssh-copy-id zek01 ssh-copy-id zek02
分別發送給各個節點,自身也須要發送。 而後在其餘兩個節點上重複此步驟oop
重啓後生效(永久關閉) 開啓: chkconfig iptables on 關閉: chkconfig iptables offui
即時生效,重啓後失效 開啓: service iptables start 關閉: service iptables sto
下載地址:http://mirror.bit.edu.cn/apache/zookeeper/ linux下載命令
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
解壓縮命令
tar -zxvf zookeeper-3.4.14.tar.gz
修改的地方有兩處:
修改zookeeper存儲數據的位置 添加集羣節點信息
# 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=/root/zookeeper/zkdata dataLogDir=/root/zookeeper/zklog # 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 #zookeeper配置端口 server.1=zek00:2888:3888 server.2=zek01:2888:3888 server.3=zek02:2888:3888
在 zookeeper的數據的存儲目錄中建立 myid文件,本文既是zkData目錄下,這個myid中的內容只有一行信息,即表示咱們集羣節點的標示,範圍在1~255之間。每一個節點中的myid的數字和咱們在zoo.cfg中的server.數字=host…對應, 建立這塊Data目錄:
mkdir zkData echo 3 > zkData/myid
將咱們hadoop-node01上安裝配置的環境分發到hadoop-node02和hadoop-node03兩個節點相同的目錄下: 確認分發成功後分別修改zek00和zek01上的myid的值分別爲1,2
用上面分發文件的方法:(scp 參數 目的地主機名 路徑) 發送給其餘兩個節點,此配置不用在安裝根目錄下啓動
zkServer.sh start
查看狀態,分別在每一個節點上執行
./bin/zkServer.sh status
zek00 zek01
zek02
說明啓動成功