Zookeeper基础—Zookeeper安装与配制(Linux)

来源:互联网 发布:知乐小说猎情 编辑:程序博客网 时间:2024/06/05 17:55

一、前提准备

1、下载zookeeper

2、安装配置JDK

3、移入Linux环境建立相当目录

二、安装配置

1、解压Zookeeper

tar -xzvf zookeeper-3.4.8.tar.gz

2、修改配置文件

把conf目录下的zoo_sample.cfg文件改成zoo.cfg,并进行修改

# The number of milliseconds of each tick  # 基本事件单元,这个时间是作为Zookeeper服务器之间或客户端与服务器之间维持心跳的时间间隔,# 每隔tickTime时间就会发送一个心跳;最小 的session过期时间为2倍tickTime tickTime=2000# The number of ticks that the initial # synchronization phase can take# 此配置表示,允许follower(相对于Leaderer言的“客户端”)连接并同步到Leader的初始化连接时间,以tickTime为单位。当初始化连接时间超过该值,则表示连接失败。initLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgement# 此配置项表示Leader与Follower之间发送消息时,请求和应答时间长度。如果follower在设置时间内不能与leader通信,那么此follower将会被丢弃。syncLimit=5# the directory where the snapshot is stored.  # do not use /tmp for storage, /tmp here is just # example sakes.# dataDir=/tmp/zookeeper# 存储内存中数据库快照的位置,如果不设置参数,更新食物的日志将被存储到默认位置。dataDir=/public/software/Zookeeper/workspace/data# 这个操作让管理机器把事务日志写入“dataLogDir”所指定的目录中,而不是“dataDir”所指定的目录。这将允许使用一个专用的日志设备,帮助我们避免日志和快照的竞争。# 日志目录# 应该谨慎的选择日志存放的位置,使用专用的日志存储设备能够大大提高系统的性能,如果将日志存储在比较繁忙的存储设备上,那么将会很大程度上影像系统性能。dataLogDir=/public/software/Zookeeper/workspace/logserver.1=192.168.60.150:2888:3888 server.2=192.168.60.151:2888:3888 server.3=192.168.60.152:2888:3888# server.A=B:C:D:其中 A 是一个数字,表示这个是第几号服务器;# B 是这个服务器的 ip 地址;# C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;# D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,# 而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,# 由于 B 都是一样,所以不同的 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# 下面是对maxClientCnxns的解释# 这个操作将限制连接到Zookeeper的客户端数量,并限制并发连接的数量,通过IP来区分不同的客户端。此配置选项可以阻止某些类别的Dos攻击。将他设置为零或忽略不进行设置将会取消对并发连接的限制。#例如,此时我们将maxClientCnxns的值设为1,如下所示:# set maxClientCnxns#   maxClientCnxns=1#启动Zookeeper之后,首先用一个客户端连接到Zookeeper服务器上。之后如果有第二个客户端尝试对Zookeeper进行连接,或者有某些隐式的对客户端的连接操作,将会触发Zookeeper的上述配置。#minSessionTimeout和maxSessionTimeout#即最小的会话超时和最大的会话超时时间。在默认情况下,minSession=2*tickTime;maxSession=20*tickTime。## 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

3、设置myid

在新建的data目录下建立myid

myid和zoo.cfg
除了修改 zoo.cfg 配置文件,集群模式下还要配置一个文件 myid,这个文件在 dataDir 目录下,这个文件里面就有一个数据就是 A 的值,Zookeeper 启动时会读取这个文件,拿到里面的数据与 zoo.cfg 里面的配置信息比较从而判断到底是那个 server。

4、设置环境变量

执行命令:vi /etc/profile,添加 :export ZOOKEEPER_HOME=/usr/local/zookeeper,添加完成后执行source /etc/profile

三、启动验证

启动Zookeeper进行查看(在Zookeeper的bin目录下启动)

./zkServer.sh start  #启动Zookeeper./zkServer.sh stop  #关闭Zookeeper./zkServer.sh status  #查看Zookeeper状态

也可以输入jps进行查年。

0 0
原创粉丝点击