Zookeeper stand-alone cluster construction

1. Download zookeeper

Refer to the official document download section: https://zookeeper.apache.org/doc/current/zookeeperStarted.html#sc_Download

2. Create multiple instances of zookeeper

Create a zookeeper-cluster directory to store multiple zookeeper instances. You can see that there are three zookeeper instances in my zookeeper-cluster directory (as shown in Figure 1), and configure them as follows:

Figure 1: Zookeeper single-machine cluster creation instance

1. Configure conf/zoo.cfg

Figure 2: The zoo.cfg configuration file for server-1

  • clientPort: The port number developed by zookeeper for the client, the default is 2181, I changed the three instances to 9200, 9201, 9202 respectively (as long as there is no conflict)
  • tickTime: 
  • dataDir: The path to the folder where the instance data is stored
  • initLimit: 
  • syncLimit: 
  • admin.serverPort: 
  • server.1/2/3: The number behind the server is the id number of each zookeeper instance. How to set this id will be described later. The format of the latter value is ip :port1:port2 , and ip is where this instance runs. The ip address of the machine, port1 is the port number used to communicate with the leader when this instance is a follower, port2 is the port number used to re-execute the election after the leader accidentally hangs up (it is not clear why the election requires a port number )


2. In the first step, there is a server.1/2/3, this number, create a file named myid in each zookeeper instance, and write the number as the id number of the server, here I correspond to each Instances filled in 1, 2, 3

Figure 3: Create myid under the dataDir path of zookeeper

3. Start the cluster

Execute in each instance directory

➜  zookeeper-3.5.2-server-1 ./bin/zkServer.sh start
➜  zookeeper-3.5.2-server-2 ./bin/zkServer.sh start
➜  zookeeper-3.5.2-server-3 ./bin/zkServer.sh start

You can check whether they are leader or master through status, and some other information

➜  zookeeper-3.5.2-server-1 ./bin/zkServer.sh status

Figure 4: Instance 1 running state - it is a follower

Guess you like