分享

zookeeper的single模式搭建

sstutu 2014-1-15 16:50:04 发表于 安装配置 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 0 6599
1.安装配置

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




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




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




cd 到conf目录
  1. 01.appletekiMacBook-Pro-2:zookeeper-3.4.5 apple$ cd conf  
复制代码
查看下
  1. 01.appletekiMacBook-Pro-2:conf apple$ cat zoo_sample.cfg  
复制代码
zoo_sample.cfg内容如下:
  1. # The number of milliseconds of each tick
  2. tickTime=2000
  3. # The number of ticks that the initial
  4. # synchronization phase can take
  5. initLimit=10
  6. # The number of ticks that can pass between
  7. # sending a request and getting an acknowledgement
  8. syncLimit=5
  9. # the directory where the snapshot is stored.
  10. # do not use /tmp for storage, /tmp here is just
  11. # example sakes.
  12. dataDir=/tmp/zookeeper
  13. # the port at which the clients will connect
  14. clientPort=2181
  15. #
  16. # Be sure to read the maintenance section of the
  17. # administrator guide before turning on autopurge.
  18. #
  19. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
  20. #
  21. # The number of snapshots to retain in dataDir
  22. #autopurge.snapRetainCount=3
  23. # Purge task interval in hours
  24. # Set to "0" to disable auto purge feature
  25. #autopurge.purgeInterval=1
复制代码
各个参数注释已讲的相当明了,和常见的时间配置不同的是这里有tick的概念

initLimit=10    及10*2000毫秒

粗略看下,然后修改文件名
  1. appletekiMacBook-Pro-2:conf apple$ mv zoo_sample.cfg zoo.cfg
复制代码
启动
  1. sh-3.2# bin/zkServer.sh start  
复制代码
如果看到这个,证明你已经成功启动
  1. JMX enabled by default  
  2. Using config: /Users/apple/soft/zookeeper-3.4.5/bin/../conf/zoo.cfg  
  3. Starting zookeeper ... STARTED  
复制代码
2.命令行接口

客户端连接zookeeper
  1. bin/zkCli.sh -server 127.0.0.1:2181  
复制代码
ls命令查看,zookeeper的数据结构和文件系统类似,以后我们细讲
  1. [zk: 127.0.0.1:2181(CONNECTED) 1] ls /
  2. [zookeeper]
复制代码
创建一个测试节点sweetop_test 并和数据my_data关联
  1. [zk: 127.0.0.1:2181(CONNECTED) 2] create /sweetop_test my_data
  2. Created /sweetop_test
复制代码
再次查看
  1. [zk: 127.0.0.1:2181(CONNECTED) 3] ls /
  2. [sweetop_test, zookeeper]
复制代码
发现已经创建好了测试节点,那么现在查看下sweetop节点,看是否关联数据
  1. [zk: 127.0.0.1:2181(CONNECTED) 4] get /sweetop_test
  2. my_data
  3. cZxid = 0x9
  4. ctime = Fri Apr 12 10:59:37 CST 2013
  5. mZxid = 0x9
  6. mtime = Fri Apr 12 10:59:37 CST 2013
  7. pZxid = 0x9
  8. cversion = 0
  9. dataVersion = 0
  10. aclVersion = 0
  11. ephemeralOwner = 0x0
  12. dataLength = 7
  13. numChildren = 0
复制代码
修改下关联的数据
  1. [zk: 127.0.0.1:2181(CONNECTED) 7] set /sweetop_test lastsweetop
  2. cZxid = 0x9
  3. ctime = Fri Apr 12 10:59:37 CST 2013
  4. mZxid = 0xb
  5. mtime = Fri Apr 12 11:05:29 CST 2013
  6. pZxid = 0x9
  7. cversion = 0
  8. dataVersion = 2
  9. aclVersion = 0
  10. ephemeralOwner = 0x0
  11. dataLength = 11
  12. numChildren = 0
  13. [zk: 127.0.0.1:2181(CONNECTED) 8] get /sweetop_test
  14. lastsweetop
  15. cZxid = 0x9
  16. ctime = Fri Apr 12 10:59:37 CST 2013
  17. mZxid = 0xb
  18. mtime = Fri Apr 12 11:05:29 CST 2013
  19. pZxid = 0x9
  20. cversion = 0
  21. dataVersion = 2
  22. aclVersion = 0
  23. ephemeralOwner = 0x0
  24. dataLength = 11
  25. numChildren = 0
复制代码
删除sweetop_test节点
  1. [zk: 127.0.0.1:2181(CONNECTED) 9] delete /sweetop_test
  2. [zk: 127.0.0.1:2181(CONNECTED) 12] ls /
  3. [zookeeper]
复制代码
欢迎加入about云群425860289432264021 ,云计算爱好者群,关注about云腾讯认证空间

没找到任何评论,期待你打破沉寂

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条