In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is Zookeeper". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is Zookeeper".
Zookeeper is an open source distributed framework of Apache, which mainly provides coordination services for distributed applications.
Zookeeper is mainly responsible for storing and managing data that everyone cares about, and Zookeeper notifies services registered on Zookeeper when the state of the data changes. Simply put, it is the zookeeper= file system + notification mechanism.
A data structure of Zookeeper
The data structure of Zookeeper is very similar to that of Unix file system. On the whole, it can be regarded as a tree. Unlike Unix file system, each node of Zookeeper can store data. Each node is called a ZNode. By default, 1MB data is stored, and each ZNode can be uniquely identified by its path.
1.1 four types of ZNode
Persistent directory node: this node still exists after the client is disconnected from Zookeeper.
Persistence sequence numbering directory node: after the client is disconnected from Zookeeper, the node still exists, but the Zookeeper numbers the node name sequentially.
Temporary directory node: this node is deleted after the client is disconnected from Zookeeper.
Temporary sequential numbering directory node: after the client is disconnected from the Zookeeper, the node is deleted, only the Zookeeper gives the node the name of the row sequential number.
Description: set the sequence identification when creating the ZNode. A value will be appended to the ZNode name. The sequence number is a monotonously increasing counter maintained by the parent node.
1.2 stat structure
ZNode mainly contains the following information:
Czxid- creates the transactional zxid of the node:
Each time you modify the ZooKeeper state, you will receive a timestamp in the form of zxid, that is, the ZooKeeper transaction ID.
Transaction ID is the total order of all modifications in ZooKeeper. Each modification has a unique zxid, and if zxid1 is less than zxid2, then zxid1 occurs before zxid2.
Ctime: the number of milliseconds that znode was created (since 1970)
Transaction zxid last updated by mzxid:znode
The number of milliseconds last modified by mtime:znode (since 1970)
Zxid, the last child node updated by pZxid:znode
Cversion:znode child node change number, znode child node modification times
Dataversion:znode data change number
Change number of aclVersion:znode access control list
EphemeralOwner: if it is a temporary node, this is the session id of the znode owner. If it wasn't for the temporary season,
The dot is 0.
Data length of dataLength:znode
Number of numChildren:znode child nodes
Application scenarios of two Zookeeper
The main application scenarios of Zookeeper include unified naming service, unified configuration management, unified cluster management, dynamic online and offline server nodes, and so on.
2.1 Unified naming Service
In a distributed environment, services often need to be uniformly named. If a service is deployed with 2 or 2 copies, it must be inappropriate to invoke a specific service directly, because we do not know which service can process our requests more quickly. At this time, we can name the three services uniformly, and then load them internally. This allows you to invoke the best service.
2.2 Unified configuration Management
In the distributed environment, the synchronization of configuration files can be realized by Zookeeper.
Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community
Write the configuration file to a ZNode of Zookeeper
Various client services listen to this ZNode
Once the ZNode changes, Zookeeper will notify each client service
2.3 Unified Cluster Management
Zookeeper can realize real-time monitoring of node state changes. When there is a service of three nodes, if the other one is down, the other two nodes can immediately receive messages and achieve real-time monitoring. Write these three nodes to a ZNode of Zookeeper, and each node listens to the ZNode. When the ZNode changes, these nodes can receive the change state in real time.
The principle of the listener
Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community
Create a Main () thread
Create two threads in the Main () thread, one responsible for network connection communication (connect) and one for listening (listener)
Send registered listening events to Zookeeper through the connect thread
Add registered listening events to the list of registered listeners in Zookeeper
When Zookeeper listens for a change in data or path, it sends this message to the listener thread
The process () method is called inside the Listener thread
Three Zookeeper clusters
Although the Zookeeper cluster does not specify Master and Slave. However, when Zookeeper works, a Leader node is generated through an internal election mechanism, and the other nodes are Follower or Observer.
Nodes declared as Observer do not participate in the election process and do not participate in the "more than half write success" strategy of write operations.
More than half write success strategy: after the Leader node receives the write request, the Leader broadcasts the write request to each server, and each server will queue the write request to be written and send a success message to the Leader. When the Leader receives more than half of the success messages, the write operation can be performed. Leader sends a submit message to each server, and each server starts writing when it receives the message.
Follower and Observer only provide read operations for data, and when they receive a write request, they forward the request to the Leader node.
As long as more than half of the nodes in the cluster survive, the Zookeeper cluster can serve normally. Therefore, the Zookeeper cluster is suitable for installing odd-numbered machines.
3.1 Election mechanism
(1) Server 1 starts and initiates an election. Server 1 votes for itself. At this time, the number of server 1 votes is less than half (3 votes), the election cannot be completed, and server 1 status remains LOOKING.
(2) Server 2 starts and initiates another election. Servers 1 and 2 respectively cast their own votes and exchange ballot information: at this time, Server 1 finds that the ID of Server 2 is larger than that of Server 1, and changes the ballot to recommendation Server 2. At this time, the number of server 1 votes is 0, server 2 votes is 2 votes, there is no more than half of the results, the election cannot be completed, and the server 1 vote 2 status remains LOOKING.
(3) Server 3 starts and initiates an election. At this point, both servers 1 and 2 will change the vote to server 3. The voting results: 0 votes for server 1, 0 votes for server 2, and 3 votes for server 3. At this time, server 3 has more than half of the votes, and server 3 is selected as Leader. Server 1, 2, change state to FOLLOWING, server 3, change state to LEADING
(4) Server 4 starts and initiates an election. At this time, the server 1 and 2 is no longer in the LOOKING state and will not change the ballot information. The result of exchanging ballot information: server 3 has 3 votes and server 4 has 1 vote. At this point, server 4 obeys the majority, changes the ballot information to server 3, and changes the status to FOLLOWING
(5) Server 5 starts up and acts as a younger brother like 4.
Thank you for your reading, the above is the content of "what is Zookeeper", after the study of this article, I believe you have a deeper understanding of what Zookeeper is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.