ZooKeeper介绍与环境搭建

Posted 骑着龙的羊

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ZooKeeper介绍与环境搭建相关的知识,希望对你有一定的参考价值。

ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。由于ZooKeeper的开源特性,后来我们的开发者在分布式锁的基础上,摸索了出了其他的使用方法:配置维护、组服务、分布式消息队列、分布式通知/协调等。

ZooKeeper是可以集群复制的,通过Zab(Zookeeper Atomic Broadcast)协议保持数据一致性,协议主要包括两个阶段:leader selection和Atomic broadcast。集群中有一个leader,通过broadcast更新其余的follower。当leader崩溃或者失去多数follower,则leader会面临重选。

1. 进入到/usr目录,wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz

[[email protected] Downloads]# cd /usr
[[email protected] usr]# ls
bin  etc  games  include  lib  lib64  libexec  local  sbin  share  src  tmp
[[email protected] usr]# wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
--2017-05-24 23:37:12--  http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
Resolving mirror.bit.edu.cn (mirror.bit.edu.cn)... 202.204.80.77, 2001:da8:204:2001:250:56ff:fea1:22
Connecting to mirror.bit.edu.cn (mirror.bit.edu.cn)|202.204.80.77|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 35042811 (33M) [application/octet-stream]
Saving to: ??òzookeeper-3.4.10.tar.gz???

31% [====================>                                               ] 11,160,899   494KB/s  eta 42s    

2.解压缩下载的文件,并重命名为zookeeper文件夹

[[email protected] usr]# tar -xvf zookeeper-3.4.10.tar.gz 
[[email protected] usr]# mv zookeeper-3.4.10 zookeeper

3.修改环境变量,vi /etc/profile,在文件尾部追加如下

export ZOOKEEPER_HOME=/usr/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin

4.创建zookeeper配置文件

[[email protected] zookeeper]# cd conf/
[[email protected] conf]# ls
configuration.xsl  log4j.properties  zoo_sample.cfg
[[email protected] conf]# cp zoo_sample.cfg zoo.cfg 

5.配置zookeeper的数据目录和日志目录,把这两个目录存放在/tmp/zookeeper下面

[[email protected] ~]# cd /tmp
[[email protected] tmp]# ls
hogsuspend
systemd-private-3ff79a0765994743931501169ad962cf-cups.service-uQcMzj
systemd-private-3ff79a0765994743931501169ad962cf-vmtoolsd.service-aovBEQ
[[email protected] tmp]# mkdir zookeeper
[[email protected] tmp]# cd zookeeper/
[[email protected] zookeeper]# mkdir log
[[email protected] zookeeper]# mkdir data
[[email protected] zookeeper]# ls
data  log

6.配置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=/tmp/zookeeper/data
dataLogDir=/tmp/zookeeper/log
# 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

7.启动zookeeper,进入到/usr/zookeeper/bin目录

[[email protected] bin]# pwd
/usr/zookeeper/bin
[[email protected] bin]# ls
README.txt  zkCleanup.sh  zkCli.cmd  zkCli.sh  zkEnv.cmd  zkEnv.sh  zkServer.cmd  zkServer.sh
[[email protected] bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

 

以上是关于ZooKeeper介绍与环境搭建的主要内容,如果未能解决你的问题,请参考以下文章

Zookeeper[2]- Zookeeper集群环境搭建

zookeeper环境的搭建

Flink+kafka实时统计本地环境搭建与代码实战

Flink+kafka实时统计本地环境搭建与代码实战

CentOS6.6 zookeeper完全集群搭建

ZooKeeper系列3.ZooKeeper源码环境搭建