In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Definition of zookeeper
Zookeeper is a high-performance coordination service for distributed applications. As its name implies, zookeeper is used to save state, configuration and other information among multiple nodes of distributed applications, so as to ensure the correct and high-speed operation of distributed programs.
Zookeeper cluster role: leader, follower, observer (add Observer role when the cluster is visited heavily)
1 when a client accesses zookeeper, what is the difference between connecting to leader and connecting to follower?
Leader can handle transaction operations (addition, deletion and modification), and all transaction operations can only be handled by leader. When other roles receive transaction requests, they can only handle non-transactional operations (read operations); follower can participate in cluster leader elections; Observer function: increase the horizontal scalability of non-transactional requests (read operations) When the demand for read operations is particularly large, the performance of the cluster can be improved by adding or decreasing observer nodes.
2. Cluster building
Number of machines: zookeeper cluster uses posix algorithm when electing leader, so generally select odd machines (2n+1) zookeeper cluster needs to configure sun java environment (sun JDK) deploy leader+follower cluster (https://www.cnblogs.com/wrong5566/p/6056788.html) between hosts set hosts of each machine modify zookeeper configuration zoo.cfg (when zookeeper starts, if the specified configuration file is not displayed Then read the zoo.cfg configuration file under the conf directory by default) create a new myid file configuration zookeeper directory and configure the environment variable zookeeper data model
Zookeeper's data model is a tree (guessed to be a b + tree, but not confirmed)
1 each node on the tree, called Znode;Znode, consists of three parts: stat (status information of znode), data (data information in znode), and children (information of znode child nodes)
Characteristics of 2-node Znode:
Znode can store data as either a file or a directory; operations on Znode are atomic; Znode nodes limit the size of files (up to 1m); and access to Znode requires an absolute path.
3 attributes of Znode node:
DataVersion: local value, the data version of the current node; each time you set a value for the current node, the dataVersion value of the current node is increased by 1, and the default is 0 position cversion: the local value, the version number of the child node of the current node; after each change of the child node, the value of cversion is increased by 1, and the default is 0 position cZxid: global value to create the transaction id of the current node Every time a new znode is created, the value of the cZxid is added by 1: the global value, the transaction id of the current node that was last modified After any Znode is modified, the value of mzxid is added by 1, where mZxid is not necessarily related to cZxid; pZxid: global value, cZxid;ephemeralOwner when the Znode child node was last created: local value, record the session id of the temporary node, if not temporary node, the value is 0bot data length: local value, data length of the current node (bytes); numChildren: number of child znode Zookeeper node type temporary node: the temporary node depends on the session. When the session that creates the temporary node ends, the temporary node is deleted; and the temporary node is not allowed to have child nodes; permanent node: the life cycle of the permanent node does not depend on the session and can have child nodes. Zookeeper shell- jps View zookeeper process: QuorumPeerMain- Connect zookeeper Cluster: zkCli.sh-server zookeeper:2181- create Node: create [- s] [- e] path data acl -s means sequential node,-e means temporary node-read node: ls path [watch] gets the child node of the node, get path [watch] acquires the data and node attribute information saved by the node, ls2 path [watch] gets the child node and current node attribute information of the node-update node data: set path data [version]-delete node: delete path [version], Rmr path recursively delete data zookeeper election mechanism-algorithm: concept used by FastLeaderElection- election algorithm: server ID: numerical type The larger the number, the greater the weight. Election status: LOOKING, wait-and-see status FOLLOWING, follower status, OBSERVING, Observer status, synchronous leader status, do not participate in Election LEADING, Leader State data ID: ID logical clock of newly written data: each round of voting, the same number of logical clocks (judge whether the nodes in the cluster are unstable according to the logical clock)-New cluster election: 1. Premise: 1.1. Each machine votes for itself; 1.2. With more than half of the votes cast, the election is over. Idea: after the machines in the cluster start up, cast a vote for themselves, and then start exchanging the voting results with other machines. If there are no other machines to exchange votes, then enter the LOOKING state; if there are other machines that can exchange votes, the server ID small machine will vote for the server ID big machine according to the server ID size; when one machine gets more than half the votes, the election will be closed. In the same cluster, the machines that start the service first will have a better chance of getting leader. -running cluster elections: 1. The premise is the same as above; at this time, the election needs to use data ID, server ID, logical clock 2. Idea: first, the same logical clock, small logical clock is eliminated, and machines with the same logical clock will revote; then, the data ID in the machine wins; if the data ID is the same, then the server ID wins. Zookeeper application scenario: data publish and subscribe; naming service; distributed lock; data publish and subscribe center (configuration center)-publishers publish data to zookeeper, subscribers get new data to update their configuration;-Note: 1. The data under unified management should not be too large;-principle: 1. When all subscribers start for the first time, visit the node specified by zk to get the relevant subscription information; 2. When getting data, set the listening for node data changes; zk.getData (path, true); set the listening for the specified path 3. When the node data on the monitored path changes, the monitoring is triggered, and all subscribers to the secondary path will receive a zookeeperde notification, and then visit the zookeeper to get new configuration information. 4. When getting data, set listening to path again;-question: how does zookeeper notify subscribers when the data in zookeeper changes? What notifications have been sent to subscribers?
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.