Zookeeper's cluster configuration

The role of a cluster

To get reliable ZooKeeper service, users can deploy ZooKeeper on a cluster. As long as the majority of ZooKeeper services on the cluster are up, the total ZooKeeper service will be available. Also, it's better to use an odd number of machines. If zookeeper has 5 machines, then it can handle the failure of 2 machines.

Two  zookeeper pseudo-distributed cluster configuration 

The so-called "pseudo-distributed cluster" is to start multiple instances of ZooKeeper in one PC. A "fully distributed cluster" is where each PC starts a ZooKeeper instance. The following describes the configuration method under Windows.
1. Unzip the three zookeeper directories

D:\zookeeper\zookeeper-1

D:\zookeeper\zookeeper-2

D:\zookeeper\zookeeper-3


2. Create data and log directories under these three directories, and create a new myid file under the data directory. The file contents of myid are: 1, 2, and 3. This file contains only one line of content, specifying its own id. value. For example, the server " 1 " should write " 1 " in the myid file. This id value must be unique within the ensemble and have a size between 1 and 255.
Ps: The myid.txt file can be created under Windows, and the suffix can be deleted after modifying the content.
 
3. Modify the zoo.cfg file in the conf directory of each server

?
# The number of milliseconds of each tick  tickTime=2000 
# The number of ticks that the initial 
# synchronization phase can take  initLimit=10 
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement  syncLimit=5 
# the directory where the snapshot is stored. 
dataDir=D:\\zookeeper\\zookeeper-1data 
# the directory where the log 
dataLogDir=D:\\zookeeper\\zookeeper-1log
# the port at which the clients will connect  clientPort=2181 
#Clusters  server.1=127.0.0.1:2888:3888  server.2=127.0.0.1:2889:3889 
server.3=127.0.0.1:2890:3890


In the configuration of the following clusters, " server.id=host:port:port. " indicates the self-identification of different ZooKeeper servers, and the machines that are part of the cluster should know about other machines in the cluster. Users can read related information from " server.id=host:port:port. ". The id is the id we set in the myid file created in the data (the directory specified by the dataDir parameter) directory in the previous step. In this line of configuration, the first port is used for information exchange among cluster members, and the second port is used for leader election when the leader hangs up. It should be noted that if you deploy multiple servers on one machine, each machine needs a different clientPort. For example, my server1 is 2181, server2 is 2182, server3 is 2183, and dataDir and dataLogDir also need to be distinguished. Down. Because on the same machine, the 2 ports and 3 servers connected behind should not be the same, otherwise the ports will conflict.

4. Start all the servers of the ZooKeeper pseudo-cluster and
enter the zookeeper/bin directory of the three servers respectively, and start the service

Three fully distributed clusters

The fully distributed cluster is the same as the pseudo-cluster configuration, but the three zookeepers are distributed on different machines, so there is no problem of port conflict. The clientport and the ports of each server configured in the clusters below can be the same.
 

Four project connection cluster configuration

Configure the zookeeper address of the cluster into the spring-service.xml configuration file in the project.
Such as:

spring-service.xml

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326450333&siteId=291194637