Environment Setup
Target system: CentOS 7.3 (sinngle machine)
ZooKeeper version: 3.5.2
Installation path: /opt/zk
Instance ports: 2181, 2182, 2183
Config files: /opt/zk/conf/node1.cfg through node3.cfg
Install rqeuired Java runtime:
yum install java-1.8.0-openjdk -y
Installation Steps
Download the distribution package:
wget https://archive.apache.org/dist/zookeeper/zookeeper-3.5.2-alpha/zookeeper-3.5.2-alpha.tar.gz
Extract and relocate:
tar -xzf zookeeper-3.5.2-alpha.tar.gz
mv zookeeper-3.5.2-alpha /opt/zk
Prepare per-instance directories:
cd /opt/zk
mkdir node_data_1 node_data_2 node_data_3
mkdir -p /var/log/zk_logs/inst1 /var/log/zk_logs/inst2 /var/log/zk_logs/inst3
Duplicate base configuration template:
cp /opt/zk/conf/zoo_sample.cfg /opt/zk/conf/node1.cfg
cp /opt/zk/conf/zoo_sample.cfg /opt/zk/conf/node2.cfg
cp /opt/zk/conf/zoo_sample.cfg /opt/zk/conf/node3.cfg
Edit /opt/zk/conf/node1.cfg:
clientPort=2181
dataDir=/opt/zk/node_data_1
dataLogDir=/var/log/zk_logs/inst1
tickTime=2000
initLimit=10
syncLimit=5
dynamicConfigFile=/opt/zk/conf/node1.cfg.dyn
Adjust clientPort, dataDir, and dataLogDir similarly for node2.cfg (port 2182) and node3.cfg (port 2183).
Copy dynamic membership file:
cp /opt/zk/conf/zoo.cfg.dynamic /opt/zk/conf/node1.cfg.dyn
cp /opt/zk/conf/zoo.cfg.dynamic /opt/zk/conf/node2.cfg.dyn
cp /opt/zk/conf/zoo.cfg.dynamic /opt/zk/conf/node3.cfg.dyn
Customize /opt/zk/conf/node1.cfg.dyn:
server.1=127.0.0.1:2777:3777
server.2=127.0.0.1:2888:3888
server.3=127.0.0.1:2999:3999
Create identifier files matching server IDs:
echo 1 > /opt/zk/node_data_1/myid
echo 2 > /opt/zk/node_data_2/myid
echo 3 > /opt/zk/node_data_3/myid
Launch and Verification
Start each instance:
/opt/zk/bin/zkServer.sh start /opt/zk/conf/node1.cfg
/opt/zk/bin/zkServer.sh start /opt/zk/conf/node2.cfg
/opt/zk/bin/zkServer.sh start /opt/zk/conf/node3.cfg
Check role of each node:
/opt/zk/bin/zkServer.sh status /opt/zk/conf/node1.cfg
/opt/zk/bin/zkServer.sh status /opt/zk/conf/node2.cfg
/opt/zk/bin/zkServer.sh status /opt/zk/conf/node3.cfg
Sample output for one node:
ZooKeeper JMX enabled by default
Using config: /opt/zk/bin/../conf/node2.cfg
Client port found: 2182. Client address: localhost.
Mode: follower