你好,游客 登录 注册 搜索
背景:
阅读新闻

zookeeper研究笔记(一)—— single模式搭建 - 独自登高楼 望断天涯路

[日期:2013-04-12] 来源:  作者: [字体: ]

1.安装配置

下载地址   http://www.apache.org/dyn/closer.cgi/zookeeper/

目前我用的版本是3.4.5   下载解压后 cd 到根目录

由于zookeeper是由jar启动,那么所谓的安装就是修改配置文件。

cd 到conf目录
 appletekiMacBook-Pro-2:zookeeper-3.4.5 apple$ cd conf

查看下
appletekiMacBook-Pro-2:conf apple$ cat zoo_sample.cfg

zoo_sample.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=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
#
# 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

各个参数注释已讲的相当明了,和常见的时间配置不同的是这里有tick的概念
initLimit=10    及10*2000毫秒
粗略看下,然后修改文件名
appletekiMacBook-Pro-2:conf apple$ mv zoo_sample.cfg zoo.cfg

启动
sh-3.2# bin/zkServer.sh start
如果看到这个,证明你已经成功启动
JMX enabled by default
Using config: /Users/apple/soft/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

2.命令行接口

客户端连接zookeeper
bin/zkCli.sh -server 127.0.0.1:2181

ls命令查看,zookeeper的数据结构和文件系统类似,以后我们细讲
[zk: 127.0.0.1:2181(CONNECTED) 1] ls /
[zookeeper]

创建一个测试节点sweetop_test 并和数据my_data关联
[zk: 127.0.0.1:2181(CONNECTED) 2] create /sweetop_test my_data
Created /sweetop_test

再次查看
[zk: 127.0.0.1:2181(CONNECTED) 3] ls /
[sweetop_test, zookeeper]

发现已经创建好了测试节点,那么现在查看下sweetop节点,看是否关联数据
[zk: 127.0.0.1:2181(CONNECTED) 4] get /sweetop_test
my_data
cZxid = 0x9
ctime = Fri Apr 12 10:59:37 CST 2013
mZxid = 0x9
mtime = Fri Apr 12 10:59:37 CST 2013
pZxid = 0x9
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 7
numChildren = 0

修改下关联的数据
[zk: 127.0.0.1:2181(CONNECTED) 7] set /sweetop_test lastsweetop
cZxid = 0x9
ctime = Fri Apr 12 10:59:37 CST 2013
mZxid = 0xb
mtime = Fri Apr 12 11:05:29 CST 2013
pZxid = 0x9
cversion = 0
dataVersion = 2
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 11
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 8] get /sweetop_test
lastsweetop
cZxid = 0x9
ctime = Fri Apr 12 10:59:37 CST 2013
mZxid = 0xb
mtime = Fri Apr 12 11:05:29 CST 2013
pZxid = 0x9
cversion = 0
dataVersion = 2
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 11
numChildren = 0

删除sweetop_test节点
[zk: 127.0.0.1:2181(CONNECTED) 9] delete /sweetop_test
[zk: 127.0.0.1:2181(CONNECTED) 12] ls /
[zookeeper]






收藏 推荐 打印 | 录入:admin | 阅读:
相关新闻