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。
140.5M / 09-05
立即下载76.4M / 03-25
立即下载55M / 06-05
立即下载237.9M / 04-13
立即下载900.9M / 03-02
立即下载96.2M / 07-06
立即下载311.2M / 07-06
立即下载335M / 07-06
立即下载200M / 07-06
立即下载413.8M / 07-06
立即下载484.7M / 09-27
立即下载165.4M / 09-05
立即下载353.9M / 06-05
立即下载131.8M / 04-13
立即下载195.6M / 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
立即下载110.5M / 09-05
立即下载33.4M / 09-05
立即下载325.8M / 08-12
立即下载60M / 04-29
立即下载254M / 04-25
立即下载659M / 04-23
立即下载1M / 12-26
立即下载253.4M / 12-08
立即下载253M / 12-08
立即下载1.19G / 11-16
立即下载369M / 09-22
立即下载181.5M / 09-22
立即下载201.2M / 09-05
立即下载488.3M / 07-16
立即下载248.9M / 12-08
立即下载248.9M / 12-08
立即下载100.6M / 03-06
立即下载148.9M / 03-06
立即下载1.12G / 07-06
立即下载1.25G / 07-06
立即下载1.76G / 09-22
立即下载1.92G / 04-17
立即下载116.2M / 04-10
立即下载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
立即下载561.8M / 07-11
立即下载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
立即下载132M / 07-06
立即下载