码迷,mamicode.com
首页 > 其他好文 > 详细

zookeeper入门之介绍与安装

时间:2019-08-24 18:54:07      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:ima   简单   turn   apach   hat   img   too   应用   存储   

一:zookeeper是什么

What is ZooKeeper?

ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. All of these kinds of services are used in some form or another by distributed applications. Each time they are implemented there is a lot of work that goes into fixing the bugs and race conditions that are inevitable. Because of the difficulty of implementing these kinds of services, applications initially usually skimp on them, which make them brittle in the presence of change and difficult to manage. Even when done correctly, different implementations of these services lead to management complexity when the applications are deployed.

有道中文翻译:ZooKeeper是一个集中的服务,用于维护配置信息、命名、提供分布式同步和提供组服务。所有这些服务都以某种形式由分布式应用程序使用。每次实现它们时,都需要做大量工作来修复不可避免的bug和竞争条件。由于难以实现这些服务,应用程序最初通常会节省这些服务,这使得它们在出现更改时变得脆弱,并且难以管理,即使处理正确,这些服务的不同实现在部署应用程序时也会导致管理复杂性。

看图:

1.1节点

技术图片

 

每个子目录项如 NameService 都被称作为 znode(目录节点),和文件系统一样,我们能够自由的增加、删除znode,在一个znode下增加、删除子znode,唯一的不同在于znode是可以存储数据的。

有四种类型的znode:

  • PERSISTENT-持久化目录节点

    客户端与zookeeper断开连接后,该节点依旧存在

  • PERSISTENT_SEQUENTIAL-持久化顺序编号目录节点

    客户端与zookeeper断开连接后,该节点依旧存在,只是Zookeeper给该节点名称进行顺序编号

  • EPHEMERAL-临时目录节点

    客户端与zookeeper断开连接后,该节点被删除

  • EPHEMERAL_SEQUENTIAL-临时顺序编号目录节点

    客户端与zookeeper断开连接后,该节点被删除,只是Zookeeper给该节点名称进行顺序编号

1.2、 监听通知机制(watch机制)

客户端注册监听它关心的目录节点,当目录节点发生变化(数据改变、被删除、子目录节点增加删除)时,zookeeper会通知客户端。

技术图片

1.3总结之说人话:zookeeper=文件系统+监听通知机制

 

二:能做什么

zookeeper功能非常强大,可以实现诸如分布式应用配置管理统一命名服务状态同步服务集群管理等功能,我们这里拿比较简单的分布式应用配置管理为例来说明。

假设我们的程序是分布式部署在多台机器上,如果我们要改变程序的配置文件,需要逐台机器去修改,非常麻烦,现在把这些配置全部放到zookeeper上去,保存在 zookeeper 的某个目录节点中,然后所有相关应用程序对这个目录节点进行监听,一旦配置信息发生变化,每个应用程序就会收到 zookeeper 的通知,然后从 zookeeper 获取新的配置信息应用到系统中。

三.下载及配置

解压好了之后,进入conf文件夹,会发现有2个文件,log4j.properties和zoo_sample.cfg这2个文件。对于zoo_sample.cfg文件,需要先将文件名字修改成zoo.cfg文件才行,接下来修改里面配置,如下所示,给出了注释和简单的配置信息。

技术图片

 1 # ZK中的一个时间单元。ZK中所有时间都是以这个时间单元为基础,进行整数倍配置的。例如,session的最小超时时间是2*tickTime。
 2 tickTime=2000
 3 
 4 # Follower在启动过程中,会从Leader同步所有最新数据,然后确定自己能够对外服务的起始状态。Leader允许F在 initLimit 时间内完成这个工作。
 5 initLimit=10
 6 
 7 # 在运行过程中,Leader负责与ZK集群中所有机器进行通信,例如通过一些心跳检测机制,来检测机器的存活状态。
 8 syncLimit=5
 9 
10 # 存储快照文件snapshot的目录。默认情况下,事务日志也会存储在这里。建议同时配置参数dataLogDir, 事务日志的写性能直接影响zk性能。
11 dataDir=D:/Program Service Files/zookeeper-3.5.0-alpha/data
12 
13 # 事务日志输出目录。尽量给事务日志的输出配置单独的磁盘或是挂载点,这将极大的提升ZK性能。 
14 dataLogDir=D:/Program Service Files/zookeeper-3.5.0-alpha/dataLog
15 
16 # 客户端连接server的端口,即对外服务端口,一般设置为2181吧。
17 clientPort=2181
18 
19 # 单个客户端与单台服务器之间的连接数的限制,是ip级别的,默认是60,如果设置为0,那么表明不作任何限制。
20 #maxClientCnxns=60
21 
22 #
23 # Be sure to read the maintenance section of the 
24 # administrator guide before turning on autopurge.
25 #
26 # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
27 #
28 # The number of snapshots to retain in dataDir
29 #autopurge.snapRetainCount=3
30 # Purge task interval in hours
31 # Set to "0" to disable auto purge feature
32 #autopurge.purgeInterval=1
技术图片

 

zookeeper入门之介绍与安装

标签:ima   简单   turn   apach   hat   img   too   应用   存储   

原文地址:https://www.cnblogs.com/tongcc/p/11405454.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!