the installation and configuration of the zookeeper is simple and can be configured as a stand-alone mode or as a cluster mode. The following will be described separately. Stand-alone mode
Click here to download the Zookeeper installation package and unzip to the appropriate directory. Enter the Conf subdirectory under the Zookeeper directory to create the ZOO.CFG:
Bash code
- ticktime=
- Datadir=/users/apple/zookeeper/data
- Datalogdir=/users/apple/zookeeper/logs
- clientport=4180
Parameter description:
- The base time unit, millisecond value, used in Ticktime:zookeeper.
- DataDir: Data directory. can be any directory.
- The Datalogdir:log directory can also be any directory. If this parameter is not set, the same settings are used and DataDir.
- ClientPort: Listens for the port number of the client connection.
So far, zookeeper's stand-alone mode has been configured. To start the server, simply run the script:
Bash code
- bin/zkserver.sh Start
After the server is started, you can start the Client connection server, execute the script: Bash code
- bin/zkcli.sh-server localhost:4180
Pseudo-Cluster mode
The so-called pseudo-cluster, is to start multiple zookeeper processes in a single machine, and form a cluster. Take the example of starting 3 zookeeper processes.
Copy 2 copies of the Zookeeper directory:
Bash code
- |--zookeeper0
- |--zookeeper1
- |--zookeeper2
Change the zookeeper0/conf/zoo.cfg file to:
Bash code
- ticktime=
- initlimit=5
- synclimit=2
- Datadir=/users/apple/zookeeper0/data
- Datalogdir=/users/apple/zookeeper0/logs
- clientport=4180
- server. 0=127.0. 0.1:8880:7770
- server. 1=127.0. 0.1:8881:7771
- server. 2=127.0. 0.1:8882:7772
Several new parameters have been added, meaning the following:
- The Initlimit:zookeeper cluster contains more than one server, one of which is leader and the rest of the servers in the cluster are follower. The Initlimit parameter configures the maximum heartbeat time between follower and leader when the connection is initialized. At this point the parameter is set to 5, stating that the time limit is 5 times times ticktime, or 5*2000=10000ms=10s.
- Synclimit: This parameter configures the maximum length of time to send messages, requests, and responses between leader and follower. At this point the parameter is set to 2, stating that the time limit is twice times ticktime, or 4000ms.
- Server. X=A:B:C where x is a number that indicates which is the first server. A is the IP address where the server resides. b Configure the port used by the server and the leader in the cluster to exchange messages. C Configure the port to use when electing leader. Because the pseudo-cluster mode is configured, the B and C parameters of each server must be different.
Refer to Zookeeper0/conf/zoo.cfg, configure Zookeeper1/conf/zoo.cfg, and zookeeper2/conf/zoo.cfg files. Just change the DataDir, Datalogdir, clientport parameters.
Create a new myID file in the previously set DataDir, write a number that indicates the number of server. The number must correspond to x one by one in the server.x in the Zoo.cfg file.
Write 0 in the/users/apple/zookeeper0/data/myid file, write 1 in/users/apple/zookeeper1/data/myid file,/users/apple/zookeeper2/data/ Write 2 in the myID file.
Enter/users/apple/zookeeper0/bin,/users/apple/zookeeper1/bin,/users/apple/zookeeper2/bin three directories, and start the server respectively.
Select one of the server directories to start the client:
Bash code
- bin/zkcli.sh-server localhost:4180
Cluster mode
Cluster mode configuration and pseudo-cluster are basically consistent.
Because the server is deployed on different machines in cluster mode, the CONF/ZOO.CFG files for each server can be identical.
Here is an example:
Bash code
- ticktime=
- initlimit=5
- synclimit=2
- Datadir=/home/zookeeper/data
- Datalogdir=/home/zookeeper/logs
- clientport=4180
- server. =10.1. 39.43:2888:3888
- server. =10.1. 39.47:2888:3888
- server. =10.1. 39.48:2888:3888
The example deploys 3 zookeeper servers, each deployed on 10.1.39.43, 10.1.39.47, 10.1.39.48. It is important to note that the numbers in the myID file in the DataDir directory of each server must be different.
10.1.39.43 server myID, 10.1.39.47 server myID is a, 10.1.39.48 server of myID is 48.
Zookeeper Installation and Configuration