ZooKeeper 简介

什么是 ZooKeeper

官网地址:https://zookeeper.apache.org/

ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. All of these kinds of services are used in some form or another by distributed applications. Each time they are implemented there is a lot of work that goes into fixing the bugs and race conditions that are inevitable. Because of the difficulty of implementing these kinds of services, applications initially usually skimp on them, which make them brittle in the presence of change and difficult to manage. Even when done correctly, different implementations of these services lead to management complexity when the applications are deployed.

ZooKeeper 为分布式程序提供分布式协调服务

ZooKeeper 为大型分布式计算提供开源的分布式配置服务、同步服务和命名注册。

ZooKeeper 设计目标

  • 命名空间

    ZooKeeper 允许分布式进程通过共享的层级命名空间(目录树)相互协调,该命名空间的组织类似于标准文件系统。名称空间由数据寄存器 (在 ZooKeeper 中称为 znodes )组成,它们类似于文件和目录

znodes 类似于文件和目录。说明 Znode 节点上既可以直接存储数据,也可以创建目录

  • 高性能

    ZooKeeper 数据保存在内存中,这意味着 ZooKeeper 可以获得高吞吐量和低延迟数。 ZooKeeper 的数据也会持久化存储。

  • 高可用

  • ZooKeeper 实现重视高性能、高可用性和严格有序的访问。ZooKeeper 的性能方面意味着它可以用于大型分布式系统。可靠性方面使它不会成为单点故障。严格的顺序意味着可以在客户端实现复杂的同步原语。

    所谓原语,一般是指由若干条指令组成的程序段,用来实现某个特定功能,在执行过程中不可被中断。

ZooKeeper 基本功能

ZooKeeper 是大数据的基础组件,提供两个基本功能

  • 读写数据:客户端可以向 ZooKeeper 存取少量数据
  • watch 数据:ZooKeeper 可以 watch(监控)数据状态变化并通知客户端

ZooKeeper 应用场景

应用场景一:Hadoop HDFS(HA)高可用 NameNode 单点故障问题

ZooKeeper 应用场景二:服务器上下线动态感知

  • ZooKeeper 集群保存服务器信息(IP地址、端口)并监控数据状态
  • 客户端访问服务器时,从 ZooKeeper 集群 中获取可用服务器列表,然后选择一个服务器进行连接
  • 当有服务器下线,ZooKeeper 集群将监控到,马上从服务器列表中删除不可用服务器信息
  • 当有服务器上线,ZooKeeper 集群将监控到,马上将服务器信息添加到可用服务器列表中
  • 通过服务器上下线动态感知,可以确保客户端始终连接的是可用服务器
ZooKeeper 应用场景三:服务器配置文件同步

  • ZooKeeper 集群保存服务器上传的 Config.xml 配置文件并进行监控
  • 只要有服务器修改 Config.xml 配置文件,会被 ZooKeeper 监控发现数据状态改变
  • ZooKeeper 会通知其他服务器 Config.xml 配置文件已修改,其他服务器则从 ZooKeeper 服务器下载最新的配置文件并替换本地配置文件
posted @ 2021-11-29 23:14  追こするれい的人  阅读(75)  评论(0编辑  收藏  举报