zookeeper学习相关

一:安装html

    1:下载 zookeeper 安装包,解压;node

    2:修改配置文件。apache

          a:将文件目录下的z oo_sample.cfg 文件复制一份到该目录,而且更名为 zoo.cfg;ide

          b:修改zoo.cfg的文件内容。打开文件,修改  dataDir 属性的值,修改成本机存在的目录;ui

# 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=/tmp/zookeeper
dataDir=D:/zookeperSpace
# 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

3,启动 zookeeper的服务。对应的启动文件---zkServer.cmd;this

4,启动zookeeper的客户端。对应的启动文件--zkCli.cmd;spa

二。zookeeper简单使用code

1,建立节点htm

  命令格式: create /node_1blog

 

说明:

a:建立临时节点: create -e /node_2  "555";

b:建立有序节点:create -s /node_2 "555"

能够用于生成主键

2,查询节点

get /node_1

3.更新节点

命令格式:set /node_1  123  

说明:

命令格式:set  /node_1  "value "version (可选)

set 命令后,节点的version字段会增长;

 

set 时,若是version和当前节点的version不一致,则不能set成功。能够经过version,查看该节点被修改的次数,也能够经过该属性,查看别人是否修改了节点;

4,删除节点

命令格式:delete  /node_1 version 

说明:

a:该节点没有子节点,则删除成功;

b:version 字段设置同  set;

c:若是要所有删除节点,则使用 rmr  /节点名称

d:节点 /zookeeper不能删除;

5,列出目录下的节点

命令格式:ls /节点路径  

说明:节点路径必须以"/"开始;

相关文章
相关标签/搜索