The installation and configuration of the zookeeper is simple and can be configured as a standalone mode or as a cluster mode. The following are described separately.
Stand-alone mode
After downloading the Zookeeper installation package (http://mirror.bit.edu.cn/apache/zookeeper/), 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:
Ticktime: Basic event Unit, in milliseconds, to control heartbeat and timeout, with a default time-out of twice times the ticktime
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.
Additional Configuration items:
Maxclientcnxns limits the number of clients connected to zookeeper and limits the number of concurrent connections, which differentiate clients by IP.
Minsessiontimeout and Maxsessiontimeout
Minimum session timeout and maximum session timeout, by default, the minimum time-out is twice times the ticktime time, the maximum session time-out is 20 times times the session time-out, and the system starts with the appropriate information. Default is-1
Initlimit
The parameter sets the time to allow all followers to connect and synchronize with the leader, and if more than half of the followers fail to synchronize during the set time period, the leader will announce the abandonment of leadership and conduct another leadership election. If the number of ZK clusters is indeed large, the time to synchronize the data will be longer, so the parameter can be properly adjusted in this case. Default is 10
Synclimit
The parameter sets the time that allows a follower to synchronize with a leader, and if the follower does not complete the synchronization during the set time period, it will be discarded by the cluster. All clients associated to this follower will be connected to the other one following.
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 and 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.
Installation and configuration instructions for ZooKeeper