最近為了解決HDFS的單點故障的問題,采用了HA的方式是實現,並通過zookeeper來實現自動切換,既然需自動切換的話,那么必須要安裝zookeeper,我選用的版本是3.4.6。下面詳細介紹一下其安裝過程。
再講具體的步驟之前,需要說明的是,我安裝zookeeper的集群是用到了五個節點:分別是hadoop1,hadoop2,hadoop3,hadoop4,hadoop5。也就是說要在這五個節點上部署zookeeper。這里需要注意一點:zookeeper集群的節點數必須是奇數,並且至少為3個。這里涉及到zookeeper的選舉算法。
1、首先肯定是從官網下載相應的tar包,並解壓
網址:http://zookeeper.apache.org/releases.html#download 截至到我發表該文章的時候,應盡出現了3.5.0的版本了。
解壓:tar -zxvf zookeeper-3.4.6.tar.gz
2、添加環境變量
export ZOOKEEPER_HOME=/home/grid/zookeeper-3.4.6
export PATH=$PATH:$ZOOKEEPER_HOME/bin
3、修改配置文件
cd zookeeper-3.4.6/conf ,將zoo_sample.cfg復制為zoo.cfg,並修改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/grid/zookeeper-3.4.6/zkdata dataLogDir=/home/grid/zookeeper-3.4.6/zkdatalog # 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=hadoop1:2888:3888 server.2=hadoop2:2888:3888 server.3=hadoop3:2888:3888 server.4=hadoop4:2888:3888 server.5=hadoop5:2888:3888
在這里需要注意zoo.cfg的配置文件中的dataDir和dataLogDir的路徑當中的文件夾必須要已存在,否則后面啟動zkServer服務的時候會失敗。
4、在dataDir對應的路徑文件夾下(我這里是zkdata文件夾),創建一個myid的文件,並在該文件中輸入對應集群各節點的id,我這里對應的是hadoop1對應的就是1,這個是與
server.1=hadoop1:2888:3888對應的。各個節點分別輸入對應的id值即可。
5、啟動zkServer
在各節點上執行:zkServer.sh start 並通過jps可以看到:啟動了QuorumpeerMain進程。

6、此時可以通過zkServer.sh status 命令來查看節點的啟動狀態。
這里需要注意點,只有當至少啟動了三個節點之后,該命令才會產生結果。否則會顯示:zookeeper Error contacting service. It is probably not running錯誤
當你啟動了至少三個節點之后,執行該命令可以看到:

至此,zookeeper的安裝工作結束。
7、關閉zookeeper服務
zkServer.sh stop 關閉
zkServer.sh restart 重啟
