Deploying ZooKeeper
Downloading and Decompressing ZooKeeper
- Log in to the agent1 node and go to the /usr/local directory. Download zookeeper-3.4.6.tar.gz and decompress it.
1 2 3
cd /usr/local wget http://archive.apache.org/dist/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz tar -zxvf zookeeper-3.4.6.tar.gz
- Create a soft link for subsequent version update.
1ln -s zookeeper-3.4.6 zookeeper
Adding ZooKeeper to Environment Variables
- Log in to the agent1 node and open the configuration file.
1vi /etc/profile - Press i to enter the insert mode and add ZooKeeper to environment variables.
1 2
export ZOOKEEPER_HOME=/usr/local/zookeeper export PATH=$ZOOKEEPER_HOME/bin:$PATH
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Make the environment variables take effect.
1source /etc/profile
- Repeat steps 1 to 4 on agent2 and agent3 to set ZooKeeper environment variables.
Modifying the ZooKeeper Configuration Files
- Log in to the agent1 node and go to the directory where ZooKeeper is located.
1cd /usr/local/zookeeper/conf
- Copy the configuration file.
1cp zoo_sample.cfg zoo.cfg
- Modify the common settings.
- Open the file.
1vi zoo.cfg - Press i to enter the insert mode and modify the data directory.
1dataDir=/usr/local/zookeeper/tmp
- Optional: Add the AdminServer configuration. (This configuration item is introduced in ZooKeeper 3.5.0. For an earlier version, skip this step.)
1admin.enableServer=false
- Add the following code to the end of the file. server.1 to server.3 are the nodes where ZooKeeper is deployed.
1 2 3
server.1=agent1:2888:3888 server.2=agent2:2888:3888 server.3=agent3:2888:3888
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Open the file.
- Add the JMX configuration.
- Open the zkServer.sh file.
1vi /usr/local/zookeeper/bin/zkServer.sh - Press i to enter the insert mode and add the JMX configuration to the line shown in the following figure:
1JMXDISABLE=true

If the ZooKeeper version is 3.6 or later, you can create a zookeeper-env.sh file in the /usr/local/zookeeper/conf directory and add the JMX configuration to the file.
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Open the zkServer.sh file.
- Optional: Add the JVM configuration.
If the ZooKeeper version is 3.6 or later, skip this step because the configuration has been preset.
- Open the zkEnv.sh file.
1vi /usr/local/zookeeper/bin/zkEnv.sh - Press i to enter the insert mode and add the following content to the end of the file:
1 2 3 4 5 6 7
# default heap for zookeeper server ZK_SERVER_HEAP="${ZK_SERVER_HEAP:-10000}" export SERVER_JVMFLAGS="-Xmx${ZK_SERVER_HEAP}m $SERVER_JVMFLAGS" # default heap for zookeeper client ZK_CLIENT_HEAP="${ZK_CLIENT_HEAP:-256}" export CLIENT_JVMFLAGS="-Xmx${ZK_CLIENT_HEAP}m $CLIENT_JVMFLAGS"
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Open the zkEnv.sh file.
- Create a tmp directory as the data directory.
1mkdir /usr/local/zookeeper/tmp - Create an empty file in the tmp directory and write myid to the file.
1 2
touch /usr/local/zookeeper/tmp/myid echo 1 > /usr/local/zookeeper/tmp/myid
- Configure the file permission.
1 2 3 4 5
chmod 750 /usr/local/zookeeper find /usr/local/zookeeper/bin -name "*.sh" | xargs -i chmod 500 {} find /usr/local/zookeeper/conf -name "*" -type f | xargs -i chmod 600 {} chown -R root /usr/local/zookeeper-3.4.6 chgrp -R root /usr/local/zookeeper-3.4.6
Synchronizing the Configuration to Other Nodes
- Log in to the agent1 node and copy the ZooKeeper configuration to other nodes.
1 2
scp -r /usr/local/zookeeper-3.4.6 root@agent2:/usr/local scp -r /usr/local/zookeeper-3.4.6 root@agent3:/usr/local
- Create a soft link and modify myid on agent2 and agent3.
- agent2:
1 2 3
cd /usr/local ln -s zookeeper-3.4.6 zookeeper echo 2 > /usr/local/zookeeper/tmp/myid
- agent3:
1 2 3
cd /usr/local ln -s zookeeper-3.4.6 zookeeper echo 3 > /usr/local/zookeeper/tmp/myid
- agent2:
Parent topic: Deployment Guide (CentOS & openEuler)