What is zookeeper?

Source: Internet
Author: User

Service cluster in the process of providing services to the outside, there are many configuration needs to be updated at any time, the service needs to coordinate work,the emergence of zookeeper is to push this information to each node, and ensure the consistency and reliability of information


Zookeeper is a configuration file management system remember to remember!


What is zookeeper?

Citing the official saying: "Zookeeper is a high-performance, distributed, open-source distributed Application coordination Service. It provides simple and original functionality, and distributed applications can be based on it to achieve more advanced services, such as synchronization, configuration management, cluster management, and name space. It is designed to be easy to program, using the file system tree as the data model. The server runs on Java, providing the Java and C client APIs.


Zookeeper overall structure

The zookeeper service itself consists of a cluster (2n+1 service allows N to fail). Zookeeper Service has two roles, one is leader, responsible for writing services and data synchronization, the rest is follower, provide read service, leader after the failure will be in follower to re-elect the new leader.


Zookeeper logic diagram is as follows

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/79/0E/wKioL1aGjzuyBoUPAAHEED_FFd0308.png "title=" capture. PNG "alt=" Wkiol1agjzuyboupaaheed_ffd0308.png "/>

1. The client can connect to each server, and the data for each server is exactly the same.

2. Each follower is connected to the leader and accepts the leader data update operation.

3.Server logs transaction logs and snapshots to persistent storage.

4. Most servers are available and the overall service is available


Zookeeper Data Model

Zookeeper is represented as a hierarchical file system directory tree structure (unlike file systems, nodes can have their own data, while the directory nodes in the file system have only child nodes).


The data model structure diagram is as follows

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/79/0F/wKiom1aGj_nTMXzzAACTmxlA8Fk795.png "title=" Capture 1. PNG "alt=" Wkiom1agj_ntmxzzaactmxla8fk795.png "/>

A circular node can contain child nodes, and a polygon node cannot contain child nodes. One node corresponds to an application, and the data stored by the node is the configuration information required by the application.


1, zookeeper in the storage of data, using a tree-like structure (similar to the directory tree)

2, zookeeper "directory" tree, each node is called a znode  

3, each znode has its own path

4. each znode has its own data (user's)

5. each znode has its own type:

A)persistent permanent (as long as the client does not delete, it will always exist)

b)persistent_sequential Permanent and sequential

c)empemeral Short (as long as the client drops the line, it will be automatically deleted)

d)empemeral_sequential Short and sequential


Znode maintained data is mainly used for the storage of coordinated data, such as status, configuration, location and other information, each node stores a small amount of data, KB level, maximum not more than 1M


Zookeeper Features

Sequential consistency: Updates the data in the order in which the client sends the request.

Atomicity: The update either succeeds or fails, and no partial updates occur.

Singleness: You see the same view regardless of which server the client connects to.

Reliability: Once the data has been updated successfully, it will remain until the new update.

Timeliness: The client gets up-to-date data within a certain time period.


Zookeeper Application Scenario


1. Data publishing and subscription (my business uses this feature, which is described in more detail later)

The application configuration is centralized to the node, the app is actively fetched at startup, and a watcher is registered on the node, and the app is notified every time the configuration update is applied.


2. Name Space Service

Distributed naming service, after creating a node, the path of the node is globally unique and can be used as a global name.


3. Distributed Notification/coordination

Different systems listen to the same node, and once an update is available, the other system is notified.


4. Distributed lock

Zookeeper can guarantee strong data consistency, and users can trust that the data of each node in the cluster is the same at any time. One user creates a node as a lock, another user detects the node, if it exists, it is locked on behalf of another user, and if it does not exist, it can create a node that represents a lock.


5. Cluster Management

Each machine that joins the cluster creates a node that writes its own state. Users who monitor the parent node are notified and processed accordingly. Delete the node when you leave, and users who monitor the parent node will also receive notifications.


=============================================================================================================== =====


Core features of Zookeeper:

1. Access data for customers

2, to provide customers with data monitoring services


Zookeeper distributed coordination services that can be implemented include:

1. Unified Name Service

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/79/0E/wKioL1aGkg2DwTGpAADl1eftNA0745.png "title=" Capture 2. PNG "alt=" Wkiol1agkg2dwtgpaadl1eftna0745.png "/>

Load balancing can be added to which server the action accesses

2. Configuration Management

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/79/0E/wKioL1aGnSzBY77qAAA_RT65dcs593.png "title=" Capture 3. PNG "alt=" Wkiol1agnszby77qaaa_rt65dcs593.png "/>

Understand that when doing cluster management, you need to modify the configuration file on each server if one server configuration file changes the other servers on the cluster also need to follow a manual change, But with zookeeper to manage these profiles, if the configuration file needs to be changed, only the configuration files that are managed on zookeeper can be changed, and all the configuration files on the cluster will read the configuration management files on that zookeeper. So you don't have to change the configuration file on the server with a single one.


3. Cluster node State coordination (load Balancing/master-slave coordination)

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/79/0E/wKioL1aGpAfio4iFAAFdvBAR9bw980.png "title=" Capture 4. PNG "alt=" Wkiol1agpafio4ifaafdvbar9bw980.png "/>

The master-slave is the zookeeper from the election when the primary server hangs, zookeeper will be aware of, and then remove the master node from the zookeeper, after receiving notification from the node, enter the election of the new master node process


This article from "in order to finger that direction" blog, declined reprint!

What is zookeeper?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.