zookeeper从安装到学习到初步总结及相关问题解决方案

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33333654/article/details/79433697

一 zookeeper个人理解

这是官方的中文讲解:什么是zookeeper

其实简单来讲就是:在使用集群服务器时,有一个管理者身份的集群管理框架。负责任务管理分发,各项任务的监听,警报及自动处理请求等。举个例子来讲,三台服务器,某一天突然有一台挂了,这时候zookeeper会报警,并把挂掉的这台服务器的业务操作分配到正常的两条服务器上保持项目不被整体挂掉而影响整体功能使用。这仅仅是个人的简单理解,喜欢的可以自行深入了解。

二 下载及安装

下载地址:各版本列表  本人JDK为1.7 下载的是最新的3.5.3   也可以下载稳定版的3.4

安装很简单,就是解压到指定目录,打开进入目录:D:\zookeeper-3.5.3-beta\conf (注:我放到了D盘)

找到zoo_sample.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=D:\\zookeeper\\data  
dataLogDir=D:\\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

zoo_sample.cfg配置文件简单解析
1、tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。
2、dataDir:顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。
3、dataLogDir:顾名思义就是 Zookeeper 保存日志文件的目录

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

保存后,将zoo_sample.cfg文件改名为zoo.cfg。(注:若不想改名,复制一份zoo_sample.cfg文件再改也可以,其实就是启动时读取的是zoo.cfg文件

修改好配置文件以后进入目录:D:\zookeeper-3.5.3-beta\bin  找到zkServer.cmd文件,使用编辑器打开,在内容最下方添加pause  

扫描二维码关注公众号,回复: 4470139 查看本文章

为什么要这么做呢?因为,若不添加,双击会闪退。当然你也可以不添加,使用cmd进入到该目录启动zkServer.cmd文件也是一样的效果。

双击zkServer.cmd文件可以看到启动成功的信息,如图:


若启动错误,请检查是否在D:\zookeeper-3.5.3-beta\conf目录下存在zoo.cfg配置文件。

三 zookeeper的三种安装模式

在第二步的安装中其实是属于单机安装模式。zookeeper的重要作用其实是集群。所以,还有两种安装模式,分别是集群安装模式和伪集群安装模式。

所谓集群,就是多个服务器安装,伪集群就是单个服务器,但是有多个zookeeper。具体我就不多说了,这里推荐一个文章,写的非常好,建议喜欢的同学可以看一看:zookeeper三种安装模式

四 zookeeper的优缺点

有人说zookeeper是集群的救星,他解决了集群管理复杂性,操控性,管理性等各种问题。而又的人又说,其权限控制,性能,数据一致性存在弊端。其实个人觉得zookeeper还是很好的,特别是针对中小型项目来说,在访问量,数据量不是非常大,并且对数据精度要求不是非常高的情况下,zookeeper的作用是很大的。下面推荐一篇文章,讲解的非常好,也可以当故事来读,也可以给以后使用的人又点醒和借鉴作用,不多说了请看文章:zookeeper优缺点

猜你喜欢

转载自blog.csdn.net/qq_33333654/article/details/79433697