Zookeeper cluster

  • The basic concept
  • Zookeeper Cluster role
  • Zookeeper Cluster server status
  • Zookeeper Number of cluster servers

The basic concept

  • Zookeeper is deployed in cluster mode to ensure high availability. In a cluster, the entire Zookeeper service is available as long as most of the machines in the cluster are available

  • Generally, a Zookeeper cluster must have at least three servers

  • Zookeeper cluster mode: Active/standby master-slave mode

    • Master server: The Master server provides the write service
    • Slave server:Obtain the latest data from the primary server through asynchronous replication and provide read services

  • Each Server represents a Server on which the Zookeeper service is installed

  • The servers that make up the Zookeeper service maintain the current server state in memory and communicate with each other

  • The Zookeeper Atomic Broadcast (ZAB) protocol is used to ensure data consistency between Zookeeper clusters

Zookeeper Cluster role

  • Zookeeper does not have the traditional master-slave concept, but contains the following three roles:

    • Leader: Provides read and write services for clients, is responsible for initiating and deciding votes, and updating system status

    • Follower: provides the read service for the client and forwards the read service to the Leader. To vote in the election process

    • Observer :

      • The read service is provided for the client, and if it is a write service, it is forwarded to the Leader
      • Do not participate in voting during the election process and do not participate in writing the success strategy
      • Improves the read performance of the cluster without affecting the write performance
      • ObserverRole isZookeeper3.3Characters added later

  • Election process of the Zookeeper cluster: When the Zookeeper Leader server is abnormal, such as network interruption, crash, exit, or restart, the Leader election process is started. In this process, a new Leader server is generated

    • Leader Election:

      • Nodes are initially in the election phase
      • As long as one node gets more than half of the votes of the nodes, it becomes a quasi-leader
    • Discovery stage:

      • The followers and the would-be Leader communicate to synchronize the latest transaction proposals received by the followers
    • Synchronization stage:

      • Synchronize all replicas in the cluster using the latest proposal history obtained by the would-be Leader during the discovery phase
      • After the synchronization is complete, the would-be Leader becomes the real Leader
    • Broadcast stage:

      • The Zookeeper cluster can formally provide transaction services and the Leader can broadcast messages
      • If a new node is added, it needs to be synchronized

Zookeeper Cluster server status

  • & : look for a Leader
  • LEADING: indicates the Leader status. The corresponding node is Leader
  • FOLLOWING: status of Follower. The corresponding node is Follower
  • OBSERVING: Indicates the Observer status. The corresponding node is Observer. This node does not participate in the Leader election

Zookeeper Number of cluster servers

  • You are advised to configure an odd number of servers in a Zookeeper cluster

    • Zookeeper cluster If some Zookeeper servers fail, ensure that the number of remaining Zookeeper servers is greater than the number of Zookeeper servers that fail, the Zookeeper cluster can still be used
    • In other words, if the number of Zookeeper servers in the cluster is N n N, the number of remaining Zookeeper servers must be greater than N 2 \frac{n}{2} 2N
    • So 2n−1 2n−1 2n−1 is the same tolerance as 2n 2n 2n, both n−1 n-1 n−1
    • Therefore, the number of Zookeeper servers ensures that the odd and even numbers have the same effect. Therefore, you do not need to add an unnecessary Zookeeper server