Zookeeper (1) first acquaintance

Zookeeper (1) first acquaintance

Overview

Meituan, Are you hungry, Taobao, 58.com and other apps are all real life versions of zookeeper.
I opened a restaurant, how can we make everyone eat our food? Need to be stationed in Meituan, so that everyone can see my restaurant in Meituan app, place an order, and complete a transaction.
Zookeeper is an open source distributed (multiple servers do one thing), which provides for distributed applications Coordinating services for the Apache project.
In the big data technology ecosystem, zookeeper (animal manager), Hadoop (elephant), Hive (bee), Pig (pig) and other technologies

Working Mechanism

Zookeeper understands from the perspective of design patterns: it is a distributed service management framework designed based on the observer pattern (one person works, someone stares at him).
It is responsible for storing and managing the data that everyone cares about
and then accepting the observer’s registration. When these data changes,
Zookeeper will be responsible for notifying the registered observers to respond accordingly,
so as to achieve a similar Master/Slave management mode in the cluster.
Zookeeper = file system + notification mechanism

Insert picture description here

  1. Merchant opens and settles in
  2. Get the list of currently open restaurants
  3. Server node goes offline
  4. Server node online and offline event notification
  5. Go to get the server list again and register to listen

Features

The difference between distributed and cluster?
Whether distributed or clustered, many people are doing things. The specific differences are as follows:
For example: I have a restaurant, which is getting more and more popular. I have to recruit more staff.
Distributed: recruit 1 chef, 1 waiter, 1 front desk, three people are responsible for different tasks, but the ultimate goal They all work for restaurants.
Cluster: recruit 3 waiters, 3 people work the same

Insert picture description here

  1. It is a cluster composed of a leader (head) and multiple followers (followers) (in the lion group, one male lion, N lionesses)
  2. As long as more than half of the nodes in the cluster survive, ZooKeeper can work normally (5 servers with 2 units, no problem; 4 servers with 2 units, stop) [Generally choose an odd number of servers, 1, 3, 5...]
  3. Global data consistency, each server saves a copy of the same data, no matter which server the client connects to, the data is consistent
  4. Data update atomicity, one time data either succeeds or fails (unsuccessful will become benevolent) [strong consistency]
  5. Real-time, within a certain time range, the client can read the latest data
  6. Update requests are executed in order, and will be executed one by one in the order sent (send 123, execute 123, not 321 or other)

data structure

Insert picture description here

The structure of the ZooKeeper data model is very similar to that of the Linux file system. It can be seen as a tree as a whole, and each node is called a ZNode (ZookeeperNode [Zookeeper node]).
Each ZNode can store 1MB of data (metadata) by default, and the path of each ZNode is unique
metadata (Metadata), also known as intermediary data and relay data, which are data about data. It is the information describing the data property (property), used to support functions such as indicating storage location, historical data, resource search, file recording, etc.

Application scenario

The services provided include: unified naming service, unified configuration management, unified cluster management, server node dynamic online and offline, soft load balancing, etc.

Unified Naming Service

In a distributed environment, it is usually necessary to name applications or services uniformly for easy identification.
For example, the IP address of the server is not easy to remember, but the domain name is relatively easy to remember.

Insert picture description here

Unified configuration management

In a distributed environment, the configuration file synchronization is the only way to go through
1000 servers. If the configuration file is modified, the operation and maintenance personnel will definitely be crazy if the configuration file is modified. Server

Insert picture description here

Hand over configuration management to Zookeeper
1. Write configuration information to a node of Zookeeper
2. Each client listens to this node
3. Once the data file in the node is modified, Zookeeper’s chatbox will notify each customer End server

It's like something happened in the countryside, tell a person who likes to talk, almost the whole village will know

Server nodes dynamically go online and offline

The client can obtain real-time changes of the server's online and offline.
On the Meituan APP, you can see whether the business is open or proofing in real time

Insert picture description here

Soft load balancing

Zookeeper will record the number of visits to each server, so that the server with the least number of visits can handle the latest customer requests (even if it is wet with rain and dew). It
is its own child, and it has to be balanced.

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_49741990/article/details/112502484