Deploy Zookeeper on the three nodes bigdata111, bigdata112 and bigdata113.
-
Unzip the zookeeper installation package.
tar -zxvf zookeeper-3.4.10.tar.gz -C /usr/local/
-
Create zkData.
cd /usr/local/zookeeper-3.4.10 mkdir -p zkData
-
Rename zoo_sample.cfg to zoo.cfg, and modify the configuration file.
cd /usr/local/zookeeper-3.4.10/conf mv zoo_sample.cfg zoo.cfg vim zoo.cfg dataDir=/usr/local/zookeeper-3.4.10/zkData #######################cluster########################## server.1=bigdata111:2888:3888 server.2=bigdata112:2888:3888 server.3=bigdata113:2888:3888
Server.A=B:C:D.
A is a number, indicating the number of the server;
B is the ip address of the server;
C is the port for the server to exchange information with the Leader server in the cluster;
D is in case the Leader server in the cluster hangs up, you need a The port is used to re-election and a new Leader is elected, and this port is the port used to communicate between servers during the election.Configure a file myid in cluster mode. This file 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 compares the data in it with the configuration information in zoo.cfg to judge Which server is it?
-
Create a myid file in the /usr/local/zookeeper-3.4.10/zkData directory and add the number corresponding to the server.
vim myid 1
-
Copy Zookeeper to the other two machines bigdata112 and bigdata113.
scp -r zookeeper-3.4.10/ root@bigdata112:/usr/local scp -r zookeeper-3.4.10/ root@bigdata113:/usr/local
-
Modify myid on the other two machines.
Bigdata112 is changed to 2, and bigdata113 is changed to 3.
-
Start ZK separately.
[root@bigdata111 zookeeper-3.4.10]# bin/zkServer.sh start [root@bigdata112 zookeeper-3.4.10]# bin/zkServer.sh start [root@bigdata113 zookeeper-3.4.10]# bin/zkServer.sh start
-
Check the status.
[root@bigdata111 zookeeper-3.4.10]# bin/zkServer.sh status JMX enabled by default Using config: /usr/local/zookeeper-3.4.10/bin/../conf/zoo.cfg Mode: follower [root@bigdata112 zookeeper-3.4.10]# bin/zkServer.sh status JMX enabled by default Using config: /usr/local/zookeeper-3.4.10/bin/../conf/zoo.cfg Mode: leader [root@bigdata113 zookeeper-3.4.5]# bin/zkServer.sh status JMX enabled by default Using config: /usr/local/zookeeper-3.4.10/bin/../conf/zoo.cfg Mode: follower
It can be seen that bigdata112 is the Leader, while bigdata111 and bigdata113 are Followers.