Category:微服务-dubbo
Article From:https://www.cnblogs.com/cxxjohnson/p/9121584.html

1. Download zookeeper

https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/

The author downloads here zookeeper-3.3.6

Two. Configuring zookeeper

1.Unzip to three directories

We want to build 3 server pseudo clusters on a single machine, and we need to decompress the downloaded zookeeper compression pack to three directory. The author’s catalogue is as follows:
server1 : F:\paths\zookeeper\server1\zookeeper-3.3.6
server2 : F:\paths\zookeeper\server2\zookeeper-3.3.6
server3 : F:\paths\zookeeper\server3\zookeeper-3.3.6

2.Create a configuration file (cfg file)

After decompression, enter conf directory separately, you can see zoo_sample.cfg, log4j.properties and configuration.xsl three files.

Create a zoo.cfg file in this directory (or you can use zoo_sample.cfg directly).

 

[html] view plain copy

 
  1. <span style=“font-size:14px;”># The number of milliseconds of each tick  
  2. tickTime=2000(2000ms,The heartbeat interval is also the time unit of zookeeper.
  3. # The number of ticks that the initial synchronization phase can take  
  4. initLimit=10(10*tickTime = 20s,Defining the time limit for initialization
  5. # The number of ticks that can pass between sending a request and getting an acknowledgement  
  6. syncLimit=5 (5*tickTime = 10s,Defining synchronization time limit
  7. # the directory where the snapshot is stored.  
  8. dataDir=F:\paths\zookeeper\server1\zookeeper-3.3.6\data (The storage directory of the custom data snapshot, the data directory needs to be created by itself.
  9. dataLogDir=F:\paths\zookeeper\server1\zookeeper-3.3.6\log (The custom log store directory, the log directory needs to be created by itself.
  10. # the port at which the clients will connect  
  11. clientPort=2181 (zookeeperService port)
  12. server.1=localhost:2887:3887 (Server1 identification of pseudo cluster zookeeper
  13. server.2=localhost:2888:3888 (Server2 identification of pseudo cluster zookeeper
  14. server.3=localhost:2889:3889 (Server3 identity of pseudo cluster zookeeper)</span>  

The above is the configuration file of Server1 in zookeeper pseudo cluster. Similarly, create a configuration file zoo.cfg for server2 and Server3 under the other two decompressing paths of the conf directory. The difference in parameters is only dataDir, dataLoGDir and clientPort

server2Zoo.cfg

 

[html] view plain copy

 
  1. <span style=“font-size:14px;”># The number of milliseconds of each tick  
  2. tickTime=2000  
  3. # The number of ticks that the initial synchronization phase can take  
  4. initLimit=10  
  5. # The number of ticks that can pass between sending a request and getting an acknowledgement  
  6. syncLimit=5  
  7. # the directory where the snapshot is stored.  
  8. dataDir=F:\paths\zookeeper\server2\zookeeper-3.3.6\data  
  9. dataLogDir=F:\paths\zookeeper\server2\zookeeper-3.3.6\log  
  10. # the port at which the clients will connect  
  11. clientPort=2182  
  12. server.1=localhost:2887:3887  
  13. server.2=localhost:2888:3888  
  14. server.3=localhost:2889:3889</span>  

server3Zoo.cfg

 

[html] view plain copy

 
  1. <span style=“font-size:14px;”># The number of milliseconds of each tick  
  2. tickTime=2000  
  3. # The number of ticks that the initial synchronization phase can take  
  4. initLimit=10  
  5. # The number of ticks that can pass between sending a request and getting an acknowledgement  
  6. syncLimit=5  
  7. # the directory where the snapshot is stored.  
  8. dataDir=F:\paths\zookeeper\server3\zookeeper-3.3.6\data  
  9. dataLogDir=F:\paths\zookeeper\server3\zookeeper-3.3.6\log  
  10. # the port at which the clients will connect  
  11. clientPort=2183  
  12. server.1=localhost:2887:3887  
  13. server.2=localhost:2888:3888  
  14. server.3=localhost:2889:3889</span>  

3.Create a myid file

In the last step, we specify the snapshot storage directory in dataDir, switch to the directory, and create a file named myid (without a suffix name). The content of the file is an integer.

The myid file in the data directory of Server1 has a content of 1.

The myid file in the data directory of server2 has a content of 2.

The myid file in the data directory of Server3 has a content of 3.

Three. Start zookeeper

Switch to the bin directory under the three unzip path respectively, enter the zkServer.cmd boot service on the CMD, and start three server with three CMD windows at the same time. The author’s starting order is Server1 -> server2 – ≫ Server3. The information will be wrong during the startup process. The information is as follows:

This is the exception information of the zookeeper Leader election algorithm. When the node has not been started, the Leader can not work properly. This error information can be ignored, and other nodes are normal after starting.

Four. Verify whether the zookeeper service is started

Input JPS in CMD, you can see the corresponding java process.

Leave a Reply

Your email address will not be published. Required fields are marked *