ZooKeeper完全分布式安装和配置

ZooKeeper简介见官方网站。

1.环境说明

在两台装有centos6.4(32位)的server上安装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 接受client(这里所说的client不是用户连接 Zookeeperserver的client,而是 Zookeeper server集群中连接到 Leader 的 Follower server)初始化连接时最长能忍受多少个心跳时间间隔数。当已经超过 10 个心跳的时间(也就是 tickTime)长度后 Zookeeper server还没有收到client的返回信息,那么表明这个client连接失败。

总的时间长度就是 10*2000=20 秒。

③syncLimit:这个配置项标识 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 5*2000=10 秒。

④dataDir:存储内存中数据库快照的位置。

⑤clientPort:监听客户端连接的port

⑥server.A=B:C:D:当中 A 是一个数字,表示这个是第几号server;B 是这个server的 ip 地址。C 表示的是这个server与集群中的 Leader server交换信息的port;D 表示的是万一集群中的 Leader server挂了,须要一个port来又一次进行选举,选出一个新的 Leader。而这个port就是用来运行选举时server相互通信的port。假设是伪集群的配置方式,因为 B 都是一样,所以不同的 Zookeeper 实例通信port号不能一样,所以要给它们分配不同的port号。

5)dataDir文件夹下创建myid文件,将内容设置为上⑥中的A值,用来标识不同的server。


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

版权声明:本文博客原创文章,博客,未经同意,不得转载。