zookeeper 安装和使用

Zookeeper 安装过程
1. 下载 zookeeper-3.4.6
2. 解压后目录为:




3.复制zoo_sample.cfg 重新命名为: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=/usr/zookeeper-3.4.6_2/data
### log file 保存日志文件
dataLogDir=/usr/zookeeper-3.4.6_2/logs
# 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  保留快照文件个数 默认3
autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature 1小时清理一下日志
autopurge.purgeInterval=1

#2888,3888 are election port 设置集群通讯

#server.1=192.168.90.107:2889:3881
#server.2=192.168.6.24:2890:3882
#server.3=192.168.6.24:2891:3883

#其中,
#2888 端口号是 zookeeper 服务之间通信的端口。

4.进入:/usr/zookeeper-3.4.6_2/bin 目录执行

[root@localhost bin]# ./zkServer.sh start




启动成功

6. 客户端登录
登录:
[root@localhost bin]# ./zkCli.sh -server 127.0.0.1:2181
查看节点:
[zk: 127.0.0.1:2181(CONNECTED) 0] ls /






命令格式:







建立伪集群:
在 zookeeper-3.4.9\conf 中如下配置:
配置第一个:
# cp zoo_sample.cfg zoo1.cfg
# vi  zoo1.cfg
配置内容:
tickTime=2000
clientPort=2181 
initLimit=5
syncLimit=2
dataDir=/zookeeperdata/1 
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890

各个参数的意义:
tickTime:心跳检测的时间间隔(毫秒),缺省:2000
clientPort:其他应用(比如solr)访问ZooKeeper的端口,缺省:2181
initLimit:初次同步的阶段(followers连接到leader的阶段),允许的时长(tick数量),缺省:10
syncLimit:允许followers同步到ZooKeeper的时长(tick数量),缺省:5
dataDir:数据(比如所管理的配置文件)的存放路径,初始时应该为空
server.X:X是ensemble中一个服务器的id,后面指定该server的hostname、第一个端口号用于ZooKeeper之间的通信、第二个端口用于和其他应用之间的通信

配置第二个:
# cp zoo1.cfg zoo2.cfg
修改:dataDir=zookeeperdata/2
修改:clientPort=2182

配置第三个:
# cp zoo1.cfg zoo3.cfg
修改:dataDir=zookeeperdata/3
修改:clientPort=2183

分布在目录1,2,3下建立myid文件,文件中按照目录分别写入1,2,3(目录为1的myid中写入1,
目录为2的myid中写入2)

分别启动:

#bin/zkServer.sh start ./conf/zoo1.cfg
# bin/zkServer.sh start ./conf/zoo2.cfg
# bin/zkServer.sh start ./conf/zoo3.cfg

当启动没有全部启动时,看日志在报错, 全部启动后,就不会报错了。


猜你喜欢

转载自gjp014.iteye.com/blog/2369673