一、压缩包下载
图1.1 下载bin版本二、本地配置
- 每个server配置的clientPort不同
server1的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=/Users/luffy/Documents/zookeeper/server1/data
dataLogDir=/Users/luffy/Documents/zookeeper/server1/dataLog
# the port at which the clients will connect
clientPort=4051
# 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
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
三、启用集群
常用命令:
./zkServer.sh start - 启动
./zkServer.sh stop - 停止
./zkServer.sh restart - 重启
./zkServer.sh status - 查看状态
./zkServer.sh start-foreground - 查看日志
分别启动三个server,查看状态,当选主成功时则整个集群启动成功。
图3-1 server1状态 图3-2 server2状态 图3-3 server3状态四、命令使用
./zkCli.sh -server 127.0.0.1:4052
命令基本语法 | 功能描述 |
---|---|
help | 显示所用操作命令 |
ls path [watch] | 使用 ls 命令查看当前 znode 中所包含的内容 |
ls2 path [watch] | 查看当前节点数据并能看到更新次数等数据 |
create | 普通创建(永久节点) -s(含有序列)-e临时(重启或者超时消失) |
get path [watch] | 获得节点的值 |
set | 设置节点的具体值 |
stat | 查看节点具体值 |
delete | 删除节点 |
rmr | 递归删除节点 |
stat path [watch] | 设置watch事件 |
get path [watch] | 设置watch事件 |
网友评论