Zhiyu-what is zookeeper


Where is the zookeeper entrance

Insert picture description here
First, start zookeeper through ./zkServer.sh start and
view the classes that have been run by java threads through jps -l. The figure shows that QuorumPeerMain is running

Start zookeeper from source code

Download the zookeeper source code on github
1. Import the code into idea, the configuration information is as follows
Insert picture description here
2. Download the jar package through maven,
insert the picture description here
Insert picture description here

-Dlog4j.configuration=file:F:\message\study\framework\zookeeper\zookeeper源码\zookeeper-master/conf/log4j.properties

3. If the jar package here reports a red line, delete the jar package and download
Insert picture description here
it again according to the path . 4. If it is still not good, clean the bad project first, and then
try not to use clean and complile in the compile. If the class is not compiled well, you can try
Insert picture description here
5. Then add the following interface to the zookeeper-server project

package org.apache.zookeeper.version;

public interface Info {
    
    
    int MAJOR = 3;
    int MINOR = 5;
    int MICRO = 6;
    String QUALIFIER = null;
    String REVISION_HASH = "c11b7e26bc554b8523dc929761dd28808913f091";
    String BUILD_DATE = "10/08/2019 20:18 GMT";
}

6. For the stand-alone version and the cluster version, start corresponding to two categories:
stand-alone: ​​ZooKeeperServerMain
cluster: QuorumPeerMain just
start QuorumPeerMain
Insert picture description here

zk startup process
1. Initialize configuration
2. Initialize datatree
3. Monitor client port
4. Leader election
5. Initialize other server information

Why is more than half of the nodes available on this server

If the number of nodes is 5, the number of nodes must be greater than or equal to 3 so that
Zookeeper can be used with more than half of the nodes? Why is this setting
mainly to deploy the nodes to multiple servers when deploying the zookeeper cluster, and if the servers are due to If the network is interrupted due to the interruption, zookeeper will elect a node as the leader within this period of time. When the number of nodes deployed on the server is more than half, the leader node can be elected , and if it is less than half, the leader node can be elected If so, then the two servers will elect two leader nodes, so when the network returns to normal, there will be problems (split brain).
When zk is running, only one leader or no leader can continue to run.
Insert picture description here

Paxos algorithm

Paxos algorithm is to ensure consistency, the Paxos algorithm is preferably consistent
prerequisite Paxos algorithm Byzantine fault tolerance is not present (information transfer can not be tampered with)
to achieve uniformity in two ways shared memory and message passing
shared memory : It can be understood that there is a center that stores all voting information, and finally makes a decision (the center can not serve it if it is hung up)
Message delivery: Without a center, each node communicates with all other nodes separately.
Paxos algorithm uses a message delivery solution to solve consistency

Guess you like

Origin blog.csdn.net/fenkanghong9779/article/details/104047871