zoukankan      html  css  js  c++  java
  • Zookeeper

    Zookeeper

    什么是Zookeeper?

    官网传送门

    ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。

    从设计模式来说基于观察者模式设计的分布式服务管理框架,存储大家都关心的数据,然后接受观察者的注册。一旦这些数据状态发生变化,zookeeper就将负责通知已经注册的观察者做出反应.

    Zookeeper的安装

    镜像链接

    Zookeeper的安装很简单,只需要下载压缩包,然后解压。

    解压后的目录:

    有几个重要文件目录要注意,bin里面存放着zookeeper命令操作文件,conf就是配置了。

     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 初始连接时间,超过这个时间连接失败 10 * tickTime
     6 # The number of ticks that can pass between 
     7 # sending a request and getting an acknowledgement
     8 syncLimit=5 数据同步时间 5 * tickTime
     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 # the maximum number of client connections.
    16 # increase this if you need to handle more clients
    17 #maxClientCnxns=60
    18 #
    19 # Be sure to read the maintenance section of the 
    20 # administrator guide before turning on autopurge.
    21 #
    22 # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
    23 #
    24 # The number of snapshots to retain in dataDir
    25 #autopurge.snapRetainCount=3
    26 # Purge task interval in hours
    27 # Set to "0" to disable auto purge feature
    28 #autopurge.purgeInterval=1
    29 ~                                                                                                                                              
    30 ~                                      

    修改conf文件下的zoo_sample.cfg 改成zoo.cfg

    • 然后进入到zookeeper/bin/下

    windows使用zkServer.cmd启动服务zkCli.cmd启动客户端,

    linux是使用./zkService.sh start启动服务./zkCli.sh start启动服务

    也可以用四字命令查看

    echo ruok | nc localhost 2181

    出现imok就代表启动了

    这样我们就已经安装好了zookeeper了

    zookeeper数据结构

    zookeeper的数据结构很像文件系统。在zookeeper中每一个结构称为znode(zookeeper node).

    /app1等就是路径PATH
    在每个Znode节点中还可以存储少量的数据,官网的解释是(ZooKeeper旨在存储协调数据:状态信息,配置,位置信息等,因此存储在每个节点的数据通常很小,在字节到千字节范围内。)

    通过

    create /amber hahaha

    可以创建一个PATH为/amber value为hahaha的Znode节点

    get /amber

    通过get /amber 我们可以在第一行看到znode的value “hahaha” 

     橙色部分统称为Stat结构体,描述当前znode的信息

    hahaha //znode的value值
    cZxid = 0x1d //创建znode的事务id
    ctime = Mon Dec 03 23:19:30 CST 2018 //创建时间
    mZxid = 0x1d //修改znode的事务id
    mtime = Mon Dec 03 23:19:30 CST 2018 //修改时间
    pZxid = 0x1d 
    cversion = 0 
    dataVersion = 0
    aclVersion = 0
    ephemeralOwner = 0x0 
    dataLength = 6 //value的length
    numChildren = 0 //子节点的个数

     除此之外可以通过help查看zookeeper的操作命令

  • 相关阅读:
    Atitit 图像处理类库 halcon11  安装与环境搭建attilax总结
    Atitit  undac网络设备管理法案 (路由器 交换机等)    法案编号USRr101510
    Atitit 图像处理 halcon类库的使用  范例边缘检测 attilax总结
    Atitit Seed-Filling种子填充算法attilax总结
    Atitti 图像处理 特征提取的科技树 attilax总结
    Atitit 软件体系的进化,是否需要一个处理中心
    Atitit 项目的主体设计与结构文档 v5
    Atitti 过程导向 vs 结果导向 attilax的策略
    Atitti 过程导向 vs 结果导向 attlax的策
    Atitit 版本管理----分支管理
  • 原文地址:https://www.cnblogs.com/amberbar/p/10057927.html
Copyright © 2011-2022 走看看