下载安装
wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz
解压:
tar -zxvf zookeeper-3.4.13.tar.gz
把名字改短一些
mv zookeeper-3.4.13 /usr/local/apps/zookeeper
配置环境变量:
vi /etc/profile
在配置文件中添加:export ZOOKEEPER_HOME=/usr/local/apps/zookeeperexport PATH=$PATH:$ZOOKEEPER_HOME/bin
复制一份zoo_sample.cfg并改名为zoo.cfg
cp zoo_sample.cfg zoo.cfg
vi zoo.cfg 查看配置
修改dataDir
# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just # example sakes.dataDir=/usr/local/apps/tmp/zkData# the port at which the clients will connectclientPort=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
启动zookeeper
zkServer.sh start
运行客户端
zkCli.sh
help查看命令
stat path [watch] set path data [version] ls path [watch] delquota [-n|-b] path ls2 path [watch] setAcl path acl setquota -n|-b val path history redo cmdno printwatches on|off delete path [version] sync path listquota path rmr path get path [watch] create [-s] [-e] path data acl addauth scheme auth quit getAcl path close connect host:port
查看节点:ls /
[zk: localhost:2181(CONNECTED) 0] ls /
[cluster, brokers, zookeeper, dubbo, admin,config]创建节点:create /test
[zk: localhost:2181(CONNECTED) 3] create /test "aaa" [zk: localhost:2181(CONNECTED) 4] ls /[cluster, brokers, zookeeper, dubbo, admin,config,test][zk: localhost:2181(CONNECTED) 5]
删除节点:delete /test
[zk: localhost:2181(CONNECTED) 8] delete /test[zk: localhost:2181(CONNECTED) 9] ls /[cluster, brokers, zookeeper, dubbo, admin,config][zk: localhost:2181(CONNECTED) 10]
获取节点数据 get /dubbo
[zk: localhost:2181(CONNECTED) 10] get /dubbo192.168.23.1cZxid = 0xactime = Tue Sep 25 20:42:48 CST 2018mZxid = 0xamtime = Tue Sep 25 20:42:48 CST 2018pZxid = 0x15cversion = 2dataVersion = 0aclVersion = 0ephemeralOwner = 0x0dataLength = 12numChildren = 2[zk: localhost:2181(CONNECTED) 11]