Zookeeper 00 安装

来源:互联网 发布:懒人眼镜 淘宝 编辑:程序博客网 时间:2024/06/15 18:07

ZooKeeper是一个分布式开源框架,提供了协调分布式应用的基本服务,它向外部应用暴露一组通用服务——分布式同步(Distributed Synchronization)、命名服务(Naming Service)、集群维护(Group Maintenance)等,简化分布式应用协调及其管理的难度,提供高性能的分布式服务。ZooKeeper本身可以以Standalone模式安装运行,不过它的长处在于通过分布式ZooKeeper集群(一个Leader,多个Follower),基于一定的策略来保证ZooKeeper集群的稳定性和可用性,从而实现分布式应用的可靠性。

下面,我们简单说明一下ZooKeeper的配置。

ZooKeeper Standalone模式

从Apache网站上(zookeeper.apache.org)下载ZooKeeper软件包,我选择了3.3.4版本的(zookeeper-3.3.4.tar.gz),在一台Linux机器上安装非常容易,只需要解压缩后,简单配置一下即可以启动ZooKeeper服务器进程。

将zookeeper-3.3.4/conf目录下面的 zoo_sample.cfg修改为zoo.cfg,配置文件内容如下所示:

tickTime=2000dataDir=/home/hadoop/storage/zookeeperclientPort=2181initLimit=5syncLimit=2

上面各个配置参数的含义也非常简单,引用如下所示:

tickTime —— the basic time unit in milliseconds used by ZooKeeper. It is used to do heartbeats and the minimum session timeout will be twice the tickTime.dataDir —— the location to store the in-memory database snapshots and, unless specified otherwise, the transaction log of updates to the database.clientPort —— the port to listen for client connections

启动ZooKeeper服务器进程

bin/zkServer.sh start

在客户端连接ZooKeeper服务器

bin/zkCli.sh -server localhost:2181

ZooKeeper Distributed模式

ZooKeeper分布式模式安装(ZooKeeper集群)也比较容易,这里说明一下基本要点。

第一步:主机名称到IP地址映射配置

ZooKeeper集群中具有两个关键的角色:Leader和Follower。集群中所有的结点作为一个整体对分布式应用提供服务,集群中每个结点之间都互相连接,所以,在配置的ZooKeeper集群的时候,每一个结点的host到IP地址的映射都要配置上集群中其它结点的映射信息。

例如,我的ZooKeeper集群中每个结点的配置,以slave-01为例,/etc/hosts内容如下所示:

192.168.0.179   slave-01192.168.0.178   slave-02192.168.0.177   slave-03

在其中一台机器(slave-01)上,解压缩zookeeper-3.3.4.tar.gz,修改配置文件conf/zoo.cfg,内容如下所示:

tickTime=2000dataDir=/home/hadoop/storage/zookeeperclientPort=2181initLimit=5syncLimit=2server.1=slave-01:2888:3888server.2=slave-02:2888:3888server.3=slave-03:2888:3888
在之前设置的dataDir中新建myid文件, 写入一个数字, 该数字表示这是第几号server. 该数字必须和zoo.cfg文件中的server.X中的X一一对应.
cd /home/hadoop/installation/scp -r zookeeper-3.3.4/ hadoop@slave-02:/home/hadoop/installation/scp -r zookeeper-3.3.4/ hadoop@slave-03:/home/hadoop/installation/
hadoop@slave-01:~/installation/zookeeper-3.3.4$ bin/zkServer.sh starthadoop@slave-02:~/installation/zookeeper-3.3.4$ bin/zkServer.sh starthadoop@slave-03:~/installation/zookeeper-3.3.4$ bin/zkServer.sh start
hadoop@slave-01:~/installation/zookeeper-3.3.4$ bin/zkServer.sh status  JMX enabled by default  Using config: /home/hadoop/installation/zookeeper-3.3.4/bin/../conf/zoo.cfg  Mode: follower

0 0