zookeeper在linux环境安装

因为1月份须要处理各种年终事情,未能写一篇博客,深(cai)表(guai)惭愧,从如今开始好好写做,争取完成今年50篇的目标。
zookeeper是apache hadoop的子项目,是一个开源的分布式应用协调服务,能够用来完成统一命名服务、状态同步服务、集群管理、分布式应用配置项的管理等工做。html

下载

能够在zookeeper官网找一个最快的镜像下载,http://zookeeper.apache.org/r...apache

@iZ23ow0rbyyZ:~$ wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
--2018-02-05 21:28:58--  http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.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: 36668066 (35M) [application/octet-stream]
Saving to: ‘zookeeper-3.4.11.tar.gz’

100%[=======================================================================================================================================================================>] 36,668,066  1.68MB/s   in 21s    

2018-02-05 21:29:19 (1.68 MB/s) - ‘zookeeper-3.4.11.tar.gz’ saved [36668066/36668066]

解压

tar -zxvf zookeeper-3.4.11.tar.gz zookeeper-3.4.11

配置

zookeeper的配置的文件,在其根目录的conf文件夹中,默认有个zoo_sample.cfg配置文件,需求将其改成zoo.cfg文件才能正常使用。服务器

cd zookeeper-3.4.11/conf/
cp zoo_sample.cfg zoo.cfg
vi zoo.cfg

能够看到zookeeper的配置文件以下:app

# 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
# 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
# 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

tickTime:这个时间是做为Zookeeper 服务器之间或客户端与服务器之间心跳的时间间隔,也就是每一个 tickTime 时间就会发送一个心跳。分布式

dataDir:顾名思义就是Zookeeper 保存数据的目录,在未设置dataLogDir的状况下,Zookeeper 将写数据的日志文件也保存在这个目录里。oop

dataLogDir:顾名思义就是Zookeeper 保存日志文件的目录。this

clientPort:这个端口就是客户端链接Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。.net

若是是集群模式还须要一下的配置:日志

initLimit:这个配置项是用来配置Zookeeper 接受客户端(这里所说的客户端不是用户链接 Zookeeper 服务器的客户端,而是 Zookeeper 服务器集群中链接到 Leader 的 Follower 服务器)初始化链接时最长能忍受多少个心跳时间间隔数。当已经超过 10 个心跳的时间(也就是 tickTime)长度后 Zookeeper 服务器尚未收到客户端的返回信息,那么代表这个客户端链接失败。总的时间长度就是 5*2000=10 秒。code

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

server.A=B:C:D:其中 A 是一个数字,表示这个是第几号服务器;B 是这个服务器的 ip 地址;C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;D 表示的是万一集群中的 Leader 服务器挂了,须要一个端口来从新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通讯的端口。若是是伪集群的配置方式,因为 B 都是同样,因此不一样的 Zookeeper 实例通讯端口号不能同样,因此要给它们分配不一样的端口号。

启动

wwk@iZ23ow0rbyyZ:~/zookeeper-3.4.11/bin$ ./zkServer.sh 
ZooKeeper JMX enabled by default
Using config: /home/wwk/zookeeper-3.4.11/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

启动zookeeper服务后,能够链接使用zkCli.sh链接服务

wwk@iZ23ow0rbyyZ:~/zookeeper-3.4.11/bin$ ./zkCli.sh

后记

好了关于zookeeper的安装配置说到这里,能够说zookeeper的安装仍是很简单的,下一次再讲讲zookeeper的详细运用。

参考文章:
http://blog.csdn.net/clj198606061111/article/details/21887219

相关文章
相关标签/搜索