sstutu 发表于 2014-1-15 16:50:04

zookeeper的single模式搭建

1.安装配置

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




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




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




cd 到conf目录01.appletekiMacBook-Pro-2:zookeeper-3.4.5 apple$ cd conf查看下01.appletekiMacBook-Pro-2:conf apple$ cat zoo_sample.cfgzoo_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.命令行接口

客户端连接zookeeperbin/zkCli.sh -server 127.0.0.1:2181ls命令查看,zookeeper的数据结构和文件系统类似,以后我们细讲 ls /
创建一个测试节点sweetop_test 并和数据my_data关联 create /sweetop_test my_data
Created /sweetop_test再次查看 ls /
发现已经创建好了测试节点,那么现在查看下sweetop节点,看是否关联数据 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修改下关联的数据 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
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节点 delete /sweetop_test
ls /
页: [1]
查看完整版本: zookeeper的single模式搭建