Install 3 machines as zookeeper cluster, 3 machine IP is 192.168.174.7,192.168.174.8,192.168.174.9 respectively. Zookeeper is written by Java, so install the JDK environment before installing zookeeper.
- Create zookeeper installation directories on 3 machines, respectively
mkdir -p /usr/local/software/zookeeper
- Download the TAR package on the official website and unzip each of the 3 machines separately.
tar -xvf zookeeper-3.4.11.tar.gz -C /usr/local/software/zookeeper/
- 3 Machines Enter the installation directory, rename the zoo.sample.cfg to Zoo.cfg, and modify the DataDir configuration to Datadir=/opt/data/zookeeper/data
- Start the cluster configuration, modify the Zoo.cfg file under 3 machines and add the following:
server.1=192.168.174.7:2888:3888server.2=192.168.174.8:2888:3888server.3=192.168.174.9:2888:3888
There are n servers on the SERVER.N. The IP address and port are configured later. The 2888 port is the port where the server exchanges information with the leader in the cluster, and 3888 is the port that the server communicates with each other at the time of the election.
- The myID file is created under the ${datadir} path of the 3 machine, which is the DataDir directory specified in the third step above, and only the number of the corresponding server is written in the myID file (the fourth step above) n. In this configuration, the server with IP 174.7 writes 1 to the file, and the other server writes n values (2,3 ...).
mkdir -p /opt/data/zookeeper/datavim /opt/data/zookeeper/data/myid
- In order to execute the Zookeeper command conveniently, configure the Zookeeper environment variable.
vim /etc/profile
Add the following content to the file:
export ZOOKEEPER_HOME=/usr/local/software/zookeeper/zookeeper-3.4.11export PATH=$PATH:$ZOOKEEPER_HOME/bin
- Start each of the three zookeeper and see the roles of each machine, leader or follower
Open Zookeeper ServicezkServer.sh start
View Zookeeper Status
zkServer.sh status
When the first set is turned on, the view status display is not running, and when at least two units are turned on, the cluster mode will be normal before the leader and follower are elected, and if an error is initiated, check the Zookeeper.out log file under ${datadir}.
3. Deploying zookeeper clusters in a Linux centos6.8 environment