See the ZooKeeper series of articles in the Zookeeper series of notes, taking you from entry to mastery
Overview
This article briefly describes how to build a zookeeper cluster.
installation steps
1. Cluster planning
A zookeper cluster requires at least 3 servers, and an odd number of servers is strongly recommended. Because zookeeper uses the half mechanism to determine whether the entire cluster is available, that is to say, if more than half of the nodes in the cluster hang up, the cluster is unavailable. 2 out of 3 nodes are considered to be down, and 2 out of 4 nodes are considered to be down, so an odd number of servers is sufficient.
Three ZooKeeper servers:
server address | Numbering |
---|---|
10.100.1.24 | 1 |
10.100.1.13 | 2 |
10.100.1.14 | 3 |
2. Unzip the installation
1). Download the latest version of the installation package apache-zookeeper-3.8.0-bin.tar.gz from the official website .
/opt/zookeer
2). Upload to the directory of the 3 servers respectively
3). Unzip the installation package to the /opt/zookeer
directory
tar -zxvf apache-zookeeper-3.8.0-bin.tar.gz -C /opt/zookeeper/
3. Configuration
1). /opt/zookeeper/apache-zookeeper-3.8.0-bin
Create zkData in this directory
mkdir zkData
2). Create a myid file in the zkData directory, and add the number corresponding to the server in the file (note: no blank lines up and down, no spaces left and right)
vim myid
3). Copy /opt/zookeeper/apache-zookeeper-3.8.0-bin/conf
zoo_sample.cfg in this directory to zoo.cfg
cp zoo_sample.cfg zoo.cfg
4). Modify the zoo.cfg file, modify the data storage path, and use the default for other configurations.
dataDir=/opt/zookeeper/apache-zookeeper-3.8.0-bin/zkData
Configuration description in zoo.cfg
configuration item | illustrate |
---|---|
tickTime=2000 | Heartbeat time, the default is 2000 milliseconds |
initLimit=10 | The initial communication time between the leader node and the follower node in the zkserver, the maximum number of heartbeats (the number of tickTimes) that can be tolerated when the leader and the follower are initially connected |
syncLimit=5 | The leader node and the follower node in the zkserver synchronize the communication time limit. If the communication time between the leader and the follower exceeds syncLimit * tickTime, the leader thinks that the follower is dead and deletes the follower from the server list. |
dataDir | Save data in Zookeeper Note: The default tmp directory is easily deleted by the Linux system on a regular basis, so the default tmp directory is generally not used. |
clientPort | Client connection port, usually not modified. |
5). Add the following cluster related configuration at the end of zoo.cfg
#######################cluster##########################
server.1=10.100.1.24:2888:3888
server.2=10.100.1.13:2888:3888
server.3=10.100.1.14:2888:3888
Configuration parameter description:
Format:server.A=B:C:D
- A is a number, indicating which server this is. In cluster mode, configure a file myid, which is in the dataDir directory. There is a data in this file that is the value of A. Zookeeper reads this file when it starts, and gets it Compare the data with the configuration information in zoo.cfg to determine which server it is.
- B is the server address.
- C is the port through which this server's Follower exchanges information with the Leader server in the cluster.
- D is that in case the leader server in the cluster hangs, a port is needed to re-elect and elect a new leader, and this port is the port used to communicate with each other during the election.
4. Synchronize the above operations to the remaining servers
Note: You need to modify the values 2 and 3 in the myid file.
5. Start
1). Start zookeeper of 3 servers respectively
bin/zkServer.sh start
2). Check the status
bin/zkServer.sh status
3). Shut down the service
bin/zkServer.sh stop