zoukankan      html  css  js  c++  java
  • ZooKeeper

    Zookeeper

    https://zookeeper.apache.org/doc/r3.6.0/index.html

    https://zookeeper.apache.org/doc/r3.6.0/zookeeperOver.html

    ZooKeeper: Because Coordinating Distributed Systems is a Zoo

    ZooKeeper is a high-performance coordination service for distributed applications. It exposes common services - such as naming, configuration management, synchronization, and group services - in a simple interface so you don't have to write them from scratch. You can use it off-the-shelf to implement consensus, group management, leader election, and presence protocols. And you can build on it for your own, specific needs.

    ZooKeeper: A Distributed Coordination Service for Distributed Applications

    ZooKeeper is a distributed, open-source coordination service for distributed applications. It exposes a simple set of primitives that distributed applications can build upon to implement higher level services for synchronization, configuration maintenance, and groups and naming. It is designed to be easy to program to, and uses a data model styled after the familiar directory tree structure of file systems. It runs in Java and has bindings for both Java and C.

    Coordination services are notoriously hard to get right. They are especially prone to errors such as race conditions and deadlock. The motivation behind ZooKeeper is to relieve distributed applications the responsibility of implementing coordination services from scratch.

    Simple API

    One of the design goals of ZooKeeper is providing a very simple programming interface. As a result, it supports only these operations:

    • create : creates a node at a location in the tree

    • delete : deletes a node

    • exists : tests if a node exists at a location

    • get data : reads the data from a node

    • set data : writes data to a node

    • get children : retrieves a list of children of a node

    • sync : waits for data to be propagated

    https://blog.csdn.net/dada_1036/article/details/50352468?utm_medium=distribute.pc_relevant.none-task-blog-OPENSEARCH-3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-OPENSEARCH-3

    Zookeeper是什么?按照Apache官网的描述是:

        ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.

    参照官网的定义,它能够做:

        作为配置信息的存储的中心服务器
        命名服务
        分布式的协调
        Mater选举等

    在定义中特别提到了命名服务。在调研之后,Zookeeper作为服务注册与发现的解决方案,它有如下优点:

        它提供的简单API
        已有互联网公司(例如:Pinterest,Airbnb)使用它来进行服务注册与发现
        支持多语言的客户端
        通过Watcher机制实现Push模型,服务注册信息的变更能够及时通知服务消费方

    缺点是:

        引入新的Zookeeper组件,带来新的复杂性和运维问题
        需自己通过它提供的API来实现服务注册与发现逻辑(包含Python与Java版本)

    命名服务

    https://docs.oracle.com/cd/E24847_01/html/E22302/a00intro-21293.html

    什么是命名服务?

    命名服务在一个集中位置存储信息,这样用户、计算机和应用程序便可通过网络进行通信。此信息包括:

    • 计算机(主机)名和地址

    • 用户名

    • 口令

    • 访问权限

    • 组成员关系、打印机等

    如果没有集中的命名服务,则每台计算机都必须单独保留一份此信息的副本。命名服务信息可以存储在文件、映射或数据库表中。如果集中存储所有数据,管理将变得更加轻松。

    命名服务对任何计算网络都是至关重要的。除了其他特性以外,命名服务还提供能够执行以下操作的功能:

    • 将名称与对象关联(绑定

    • 将名称解析为对象

    • 删除绑定

    • 列出名称

    • 重命名

    网络信息服务使计算机可由通用名称而非数字地址来标识。这样可以简化通信,因为用户不需要记住并尝试输入那些繁琐的地址(例如 192.168.0.0)。

    例如,假设有一个网络具有三台计算机,名称分别为 pineelmoakpine 必须先知道 elmoak 的数字网络地址,才能向其发送消息。因此,pine 需要保留一个文件(/etc/hosts/etc/inet/ipnodes),以存储网络中每台计算机(包括 pine 本身)的网络地址。

    image:图中显示了 pine、elm 和 oak 计算机,以及 pine 中列出的各自的 IP 地址。

    类似地,elmoak 要与 pine 通信或彼此进行通信,也必须保留类似的文件。

    image:图中显示计算机在各自的 /etc/hosts 文件中保留网络中计算机的所有 IP 地址。

    除了存储地址外,计算机还存储安全信息、邮件数据、网络服务信息等。随着网络提供的服务越来越多,存储信息的列表会不断增大。因此,每台计算机都需要保留一整套类似于 /etc/hosts/etc/inet/ipnodes 的文件。

    网络信息服务在服务器中存储网络信息,任何计算机都可以查询该信息。

    这些计算机称为服务器的客户机。下图显示客户机/服务器布局。每次网络信息发生变化时,管理员将只更新网络信息服务存储的信息,而不更新每个客户机的本地文件。这样做可以减少错误、客户机之间的不一致性以及任务的绝对工作量。

    image:图中显示了客户机/服务器计算关系中的服务器和客户机。

    这种由服务器向网络中的客户机提供集中式服务的布局称为客户机/服务器计算

    Kazoo -- a third part python bindings

    https://kazoo.readthedocs.io/en/latest/

    Kazoo is a Python library designed to make working with Zookeeper a more hassle-free experience that is less prone to errors.

    Kazoo features:

    • A wide range of recipe implementations, like Lock, Election or Queue
    • Data and Children Watchers
    • Simplified Zookeeper connection state tracking
    • Unified asynchronous API for use with greenlets or threads
    • Support for gevent >= 1.2
    • Support for eventlet
    • Support for Zookeeper 3.3, 3.4, and 3.5 servers
    • Integrated testing helpers for Zookeeper clusters
    • Pure-Python based implementation of the wire protocol, avoiding all the memory leaks, lacking features, and debugging madness of the C library

    使用示例

    https://github.com/fanqingsong/zookeeper_pyscripts_of_kazoo

    基本使用 (https://www.cnblogs.com/run4life/p/5331040.html 、 https://zhuanlan.zhihu.com/p/34177172)

    观察器 (https://blog.csdn.net/KWSY2008/article/details/52042303)

    分布式锁

    https://blog.csdn.net/KWSY2008/article/details/51909429?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-4&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-4

    http://www.voidcn.com/article/p-umdhyltz-bt.html

    服务发现

    https://blog.csdn.net/dada_1036/article/details/50352468?utm_medium=distribute.pc_relevant.none-task-blog-OPENSEARCH-3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-OPENSEARCH-3

  • 相关阅读:
    【转】程序员杂志:2011程序员薪资调查报告
    过滤HTML格式
    学习ASP.NET中的细节问题
    自己写的一些类代码
    "rs.open sql,conn,1,3 "的1,3的用处
    无须重装 Windows常遇问题通用解决方法
    Vista Beta下载
    asp学习
    SharePoint 和RMS装在同一台机器上可以么?
    介绍SharePoint与RMS集成的两篇重磅文章
  • 原文地址:https://www.cnblogs.com/lightsong/p/12829123.html
Copyright © 2011-2022 走看看