First, download zookeeper
https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/
Here the author downloads is zookeeper-3.3.6
Second, configure the Zookeeper1. Extract to three directories we want to build 3 server pseudo-clusters on a single machine, we need to extract the downloaded zookeeper compressed package to three directories. The author's catalogue is as follows: server1:f:\paths\zookeeper\server1\zookeeper-3.3.6server2:f:\paths\zookeeper\server2\ zookeeper-3.3.6server3:f:\paths\zookeeper\server3\zookeeper-3.3.62. Creating a configuration file (cfg file)
After decompression, enter the Conf directory respectively, you can see the zoo_sample.cfg,log4j.properties and configuration.xsl three files.
Create a zoo.cfg file under this directory (you can also use Zoo_sample.cfg directly), configured as follows:
[HTML]View PlainCopy
- <span style="FONT-SIZE:14PX;" ># The number of milliseconds of each tick
- Ticktime=(2000ms, heartbeat interval, also zookeeper time unit)
- # The number of ticks that the initial synchronization phase can take
- initlimit=(10*ticktime = 20s, defines the time limit for initialization)
- # The number of ticks that can pass between sending a request and getting an acknowledgement
- synclimit=5 (5*ticktime = 10s, defining the time limit for synchronization)
- # The directory where the snapshot is stored.
- Datadir=F:\paths\zookeeper\server1\zookeeper-3.3.6\data (the storage directory for custom data snapshots, the data directory needs to be created by itself)
- datalogdir=F:\paths\zookeeper\server1\zookeeper-3.3.6\log (custom log storage directory, log directory needs to be created by itself)
- # The port at which the clients would connect
- clientport=2181 (Zookeeper service port)
- server.1=localhost:2887:3887 (Server1 identity of pseudo-cluster zookeeper)
- server.2=localhost:2888:3888 (Server2 identity of Pseudo-cluster zookeeper)
- server.3=localhost:2889:3889 (Server3 identity of Pseudo-cluster zookeeper)</span>
The above is the Server1 configuration file in zookeeper pseudo-cluster. Similarly, create Server2 and Server3 configuration file zoo.cfg in the Conf directory of the other two decompression paths. The parameters differ only in DataDir, Datalogdir, and ClientPort
Server2 's Zoo.cfg
[HTML]View PlainCopy
- <span style="FONT-SIZE:14PX;" ># The number of milliseconds of each tick
- Ticktime=
- # The number of ticks that the initial synchronization phase can take
- initlimit=Ten
- # 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=F:\paths\zookeeper\server2\zookeeper-3.3.6\data
- datalogdir=F:\paths\zookeeper\server2\zookeeper-3.3.6\log
- # The port at which the clients would connect
- clientport=2182
- server.1=localhost:2887:3887
- server.2=localhost:2888:3888
- server.3=localhost:2889:3889</span>
Server3 's Zoo.cfg
[HTML]View PlainCopy
- <span style="FONT-SIZE:14PX;" ># The number of milliseconds of each tick
- Ticktime=
- # The number of ticks that the initial synchronization phase can take
- initlimit=Ten
- # 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=F:\paths\zookeeper\server3\zookeeper-3.3.6\data
- datalogdir=F:\paths\zookeeper\server3\zookeeper-3.3.6\log
- # The port at which the clients would connect
- clientport=2183
- server.1=localhost:2887:3887
- server.2=localhost:2888:3888
- server.3=localhost:2889:3889</span>
3. Create a myID file
In the previous step, we specified the snapshot directory in DataDir, switch to each directory, create a file named myID (no suffix). The file content is an integer number.
The myID file in the Server1 data directory, with the content of 1.
The myID file in the Server2 data directory, with the content of 2.
The myID file in the Server3 data directory, with the content of 3.
Third, start zookeeper
respectively, switch to the bin directory under the three decompression path, the cmd input zkserver.cmd start service, you can use three cmd windows to start three server respectively, the author's boot sequence is server1-Server2-Server3. During startup, the error message is as follows:
This is zookeeper's leader election algorithm exception information, when the node does not start to complete, leader can not work properly, this error message is negligible, and other nodes after the start of normal.
Iv. Verify that the Zookeeper service starts entering JPS in CMD and can view the corresponding Java process.
Build zookeeper pseudo-cluster under WIN10 environment