zookeeper 3.4.5 安裝包 windows、linux下安裝是一樣的,ZooKeeper是Hadoop的正式子項目,它是一個針對大型分布式係統的可靠協調係統,提供的功能包括:配置維護、名字服務、分布式同步、組服務等。ZooKeeper的目標就是封裝好複雜易出錯的關鍵服務,將簡單易用的接口和性能高效、功能穩定的係統提供給用戶。它也是Google的Chubby一個開源的實現,是高有效和可靠的協同工作係統,Zookeeper能夠用來leader選舉,配置信息維護等,在一個分布式的環境中,需要一個Master實例或存儲一些配置信息,確保文件寫入的一致性等。
1,下載zookeeper-3.4.5安裝包
2,解壓:tar -zxvf zookeeper-3.4.5.tar.gz
3,配置環境變量:
#java環境變量
vim /etc/profile.d/java.sh
#set java environment
JAVA_HOME=/opt/modules/jdk
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
#zookeeper環境變量
vim /etc/profile.d/zookeeper.sh
export ZOOKEEPERER_HOME=/opt/modules/zookeeper-3.4.5
export PATH=$ZOOKEEPER_HOME/bin:$PATH
4,主機名稱到ip地址映射配置(這個步驟再安裝hadoop的時候已經配置好了)
ZooKeeper集群中具有兩個關鍵的角色:Leader和Follower。集群中所有的結點作為一個整體對分布式應用提供服務,集群中每個結點之間都互相連接,所以,在配置的ZooKeeper集群的時候,每一個結點的host到IP地址的映射都要配置上集群中其它結點的映射信息。
例如,我的ZooKeeper集群中每個結點的配置,以master為例,/etc/hosts內容如下所示:
192.168.209.134 master
192.168.209.135 slaver1
192.168.209.136 slaver2
ZooKeeper采用一種稱為Leader election的選舉算法。在整個集群運行過程中,隻有一個Leader,其他的都是Follower,如果ZooKeeper集群在運行過程中 Leader出了問題,係統會采用該算法重新選出一個Leader。因此,各個結點之間要能夠保證互相連接,必須配置上述映射。
5,修改/opt/modules/zookeeper-3.4.5/conf/zoo.cfg(mv zoo_sample.cfg zoo.cfg)
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/home/hadoop/storage/zookeeper
clientPort=2181
server.1=master:2888:3888
server.2=slaver1:2888:3888
server.3=slaver2:2888:3888
6,傳輸到slaver
為了提高傳輸速度,我這裏先將master上配置好的zookeeper進行壓縮。
tar -zcvf zookeeper.tar zookeeper-3.4.5
[hadoop@master modules]$ scp zookeeper.tar hadoop@slaver1:/opt/modules/
zookeeper.tar 100% 16MB 15.7MB/s 00:00
[hadoop@master modules]$ scp zookeeper.tar hadoop@slaver2:/opt/modules/
zookeeper.tar 100% 16MB 15.7MB/s 00:00
[hadoop@master modules]$
7,登陸slaver解壓zookeeper.tar
ssh slaver1
tar -xvf /opt/modules/zookeeper.tar
ctrl+d
ssh slaver2
tar -xvf /opt/modules/zookeeper.tar
8,設置myid
在我們配置的dataDir指定的目錄下麵,創建一個myid文件,裏麵內容為一個數字,用來標識當前主機,conf/zoo.cfg文件中配置的server.X中X為什麼數字,則myid文件中就輸入這個數字,例如:
[root@master ~]# su - hadoop
[hadoop@master ~]$ cd /opt/modules/zookeeper-3.4.5/conf/
[hadoop@master conf]$ vim zoo.cfg
[hadoop@master conf]$ echo "1" > /home/hadoop/storage/zookeeper/myid
-bash: /home/hadoop/storage/zookeeper/myid: No such file or directory
[hadoop@master conf]$ mkdir -p /home/hadoop/storage/zookeeper/
[hadoop@master conf]$ echo "1" > /home/hadoop/storage/zookeeper/myid
[hadoop@master conf]$ ssh slaver1
Last login: Sun Mar 23 23:18:50 2014 from master
[hadoop@slaver1 ~]$ mkdir -p /home/hadoop/storage/zookeeper/
[hadoop@slaver1 ~]$ echo "2" > /home/hadoop/storage/zookeeper/myid
[hadoop@slaver1 ~]$ logout
[hadoop@master conf]$ ssh slaver2
Last login: Sun Mar 23 23:19:25 2014 from master
[hadoop@slaver2 ~]$ mkdir -p /home/hadoop/storage/zookeeper/
[hadoop@slaver2 ~]$ echo "3" > /home/hadoop/storage/zookeeper/myid
9,啟動zookeeper集群
在每個節點上執行啟動任務的腳本:
[hadoop@master zookeeper-3.4.5]$ bin/zkServer.sh start
[hadoop@slaver1 zookeeper-3.4.5]$ bin/zkServer.sh start
[hadoop@slaver2 zookeeper-3.4.5]$ bin/zkServer.sh start
10,驗證安裝
[hadoop@master zookeeper-3.4.5]$ bin/zkServer.sh status
JMX enabled by default
Using config: /opt/modules/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: follower
[hadoop@slaver1 zookeeper-3.4.5]$ bin/zkServer.sh status
JMX enabled by default
Using config: /opt/modules/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: leader
[hadoop@slaver2 zookeeper-3.4.5]$ bin/zkServer.sh status
JMX enabled by default
Using config: /opt/modules/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: follower
在master輸入jps,顯示如下:
4096 SecondaryNameNode
4181 JobTracker
4607 Jps
3919 NameNode
4381 QuorumPeerMain
在slaver1,slaver2輸入jps,顯示如下:
3539 Jps
3021 DataNode
3224 QuorumPeerMain
3127 TaskTracker
另外,可以通過客戶端腳本,連接到ZooKeeper集群上。對於客戶端來說,ZooKeeper是一個整體(ensemble),連接到ZooKeeper集群實際上感覺在獨享整個集群的服務,所以,你可以在任何一個結點上建立到服務集群的連接,例如:
[hadoop@slaver1 zookeeper-3.4.5]$ bin/zkCli.sh -server master:2181
Connecting to master:2181
2014-03-24 00:24:22,321 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.5-1392090, built on 09/30/2012 17:52 GMT
2014-03-24 00:24:22,325 [myid:] - INFO [main:Environment@100] - Client environment:host.name=slaver1
2014-03-24 00:24:22,326 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.6.0_45
2014-03-24 00:24:22,327 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Sun Microsystems Inc.
2014-03-24 00:24:22,327 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/opt/modules/jdk/jre
2014-03-24 00:24:22,328 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/opt/modules/zookeeper-3.4.5/bin/../build/classes:/opt/modules/zookeeper-3.4.5/bin/../build/lib/*.jar:/opt/modules/zookeeper-3.4.5/bin/../lib/slf4j-log4j12-1.6.1.jar:/opt/modules/zookeeper-3.4.5/bin/../lib/slf4j-api-1.6.1.jar:/opt/modules/zookeeper-3.4.5/bin/../lib/netty-3.2.2.Final.jar:/opt/modules/zookeeper-3.4.5/bin/../lib/log4j-1.2.15.jar:/opt/modules/zookeeper-3.4.5/bin/../lib/jline-0.9.94.jar:/opt/modules/zookeeper-3.4.5/bin/../zookeeper-3.4.5.jar:/opt/modules/zookeeper-3.4.5/bin/../src/java/lib/*.jar:/opt/modules/zookeeper-3.4.5/bin/../conf:.:/opt/modules/jdk/lib.tools.jar
2014-03-24 00:24:22,328 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/opt/modules/jdk/jre/lib/amd64/server:/opt/modules/jdk/jre/lib/amd64:/opt/modules/jdk/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2014-03-24 00:24:22,335 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2014-03-24 00:24:22,335 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
2014-03-24 00:24:22,336 [myid:] - INFO [main:Environment@100] - Client environment: os.name=Linux
2014-03-24 00:24:22,336 [myid:] - INFO [main:Environment@100] - Client environment: os.arch=amd64
2014-03-24 00:24:22,337 [myid:] - INFO [main:Environment@100] - Client environment: os.version=2.6.32-358.el6.x86_64
2014-03-24 00:24:22,337 [myid:] - INFO [main:Environment@100] - Client environment:user.name=hadoop
2014-03-24 00:24:22,338 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/home/hadoop
2014-03-24 00:24:22,338 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/opt/modules/zookeeper-3.4.5
2014-03-24 00:24:22,343 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=master:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@24a37368
Welcome to ZooKeeper!
2014-03-24 00:24:22,404 [myid:] - INFO [main-SendThread(master:2181):ClientCnxn$SendThread@966] - Opening socket connection to server master/192.168.209.134:2181. Will not attempt to authenticate using SASL (Unable to locate a login configuration)
2014-03-24 00:24:22,418 [myid:] - INFO [main-SendThread(master:2181):ClientCnxn$SendThread@849] - Socket connection established to master/192.168.209.134:2181, initiating session
JLine support is enabled
2014-03-24 00:24:22,545 [myid:] - INFO [main-SendThread(master:2181):ClientCnxn$SendThread@1207] - Session establishment complete on server master/192.168.209.134:2181, sessionid = 0x144f2dc538b0000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: master:2181(CONNECTED) 0]
到此,分布式的zookeeper集群就算安裝好了。稍後開始安裝hbase。
76.4M / 03-25
立即下載55M / 06-05
立即下載237.9M / 04-13
立即下載140.5M / 03-06
立即下載900.9M / 03-02
立即下載96.2M / 07-06
立即下載311.2M / 07-06
立即下載335M / 07-06
立即下載200M / 07-06
立即下載413.8M / 07-06
立即下載353.9M / 06-05
立即下載131.8M / 04-13
立即下載230.8M / 03-03
立即下載195.6M / 03-03
立即下載165.4M / 03-03
立即下載45.6M / 09-08
立即下載665.2M / 07-06
立即下載2.84G / 07-06
立即下載93M / 07-06
立即下載338.3M / 07-06
立即下載1.38G / 07-26
立即下載488.3M / 07-16
立即下載109.8M / 06-03
立即下載142M / 01-08
立即下載1.2M / 11-23
立即下載548.8M / 04-13
立即下載1.6M / 04-13
立即下載1.48G / 03-18
立即下載646.6M / 03-03
立即下載133.7M / 03-03
立即下載325.8M / 06-07
立即下載60M / 04-29
立即下載254M / 04-25
立即下載659M / 04-23
立即下載1M / 12-26
立即下載253.4M / 12-08
立即下載253M / 12-08
立即下載1.19G / 11-16
立即下載110.5M / 04-23
立即下載26.7M / 03-16
立即下載488.3M / 07-16
立即下載248.9M / 12-08
立即下載248.9M / 12-08
立即下載201.2M / 04-13
立即下載100.6M / 03-06
立即下載148.9M / 03-06
立即下載1.12G / 07-06
立即下載1.25G / 07-06
立即下載9.48G / 07-06
立即下載50KB / 07-06
立即下載116.2M / 04-10
立即下載1.92G / 04-17
立即下載201.5M / 04-13
立即下載7.31G / 07-01
立即下載94.3M / 07-06
立即下載2.48G / 07-06
立即下載7.63G / 07-06
立即下載1M / 07-06
立即下載778.1M / 07-06
立即下載509.7M / 07-06
立即下載561.8M / 07-11
立即下載1.32G / 01-19
立即下載72M / 07-06
立即下載548.7M / 07-06
立即下載1.00G / 07-06
立即下載9.13G / 07-06
立即下載126.2M / 07-06
立即下載72M / 07-06
立即下載105.1M / 07-06
立即下載132M / 07-06
立即下載