1. zookeeper 是apache旗下的hadoop子项目,它一个开源的,分布式的服务协调器。同样通过zookeeper可以实现服务间的同步与配置维护。通常情况下,在分布式应用开发中,协调服务这样的工作不是件容易的事,很容易出现死锁,不恰当的选举竞争等。zookeeper就是担负起了分布式协调的重担。
  2. zookeeper的特点:
    1. 使用简单:ZooKeeper允许分布式程序通过一个类似于标准文件系统的共享的层次化名称空间来相互协调。名称空间由数据寄存器(称为znode)组成,在ZooKeeper中,它们类似于文件和目录。与为存储而设计的典型文件系统不同,ZooKeeper数据保存在内存中,这意味着ZooKeeper可以达到高吞吐量和低延迟数
    2. 同步与复制:组成ZooKeeper服务的服务器必须互相有感知。客户端连接到一个ZooKeeper服务器。客户端维护一个TCP连接,通过它发送请求、获取响应、获取观察事件和发送心跳。如果连接到服务器的TCP连接中断,客户端将连接到另一个服务器。 zookeeper快速入门  
    3. 有序
    4. 在进行大量读操作时,运行速度奇快
  3. ZooKeeper提供的名称空间非常类似于标准文件系统。名称是由斜杠(/)分隔的路径元素序列。在ZooKeeper的名称空间中,每一个节点都是通过一条路径来标识的。如图所示 :
    zookeeper快速入门
  4. 当然zookeeper与标准文件系统不同的是,它的节点分为永久节点和临时节点(随着会话断开而消失)
  5. 客户端的节点都会被设置一个监控,当znode发生更改时,这个变化会通知所有客户端然后删除

 

二。zookeeper快速上手

  1. 下载zookeeper:地址,并解压,然后得到如下目录: zookeeper快速入门
  2. 进入conf目录下我们复制一份zoo_sample.cfg并改名为zoo.cfg  
    cp zoo_sample.cfg zoo.cfg

    运行 vi zoo.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=../zookeeper-data
    # 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
    View Code

相关文章:

  • 2021-05-12
  • 2021-10-22
  • 2021-11-30
  • 2021-07-13
  • 2021-07-05
  • 2021-11-15
  • 2022-01-09
猜你喜欢
  • 2021-09-12
  • 2021-07-11
  • 2021-07-14
  • 2021-11-07
  • 2022-02-09
  • 2021-09-28
相关资源
相似解决方案