ZooKeeper deployment

Published 2026-07-28 12:55 Updated 2026-10-13 17:14 642 words 4 min read ... Page views Reviewed The content has been read through by me or a friend I trust. Written by someone else Someone else wrote most of this; I only made small edits.

Reviewed The content has been read through by me or a friend I trust.

This article introduces the installation, configuration and operation process of ZooKeeper, including setting environment variables, creating data directories, configuring myid files, configuring server nodes and permissions, and starting and verifying whether the ZooKeeper service is running normally through commands, and finally confirming the appearance of the leader node in the election results.

Configuration of ZooKeeper

Installation of ZooKeeper

Download ZooKeeper

wget -P /export/software/ https://repo.huaweicloud.com/apache/zookeeper/zookeeper-3.8.5/apache-zookeeper-3.8.5-bin.tar.gz

Install ZooKeeper

tar -zxvf /export/software/apache-zookeeper-3.8.5-bin.tar.gz -C /export/servers/
cd /export/servers/
mv /export/servers/apache-zookeeper-3.8.5-bin /export/servers/zookeeper

Configure environment variables

sudo vim /etc/profile

Add the following configuration to the end of the file

export ZOOKEEPER_HOME=/export/servers/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin

Reload environment variables

source /etc/profile

edit the configuration file

cd /export/servers/zookeeper/conf

Copy the template into a formal configuration file

sudo cp /export/servers/zookeeper/conf/zoo_sample.cfg /export/servers/zookeeper/conf/zoo.cfg

sudo vim zoo.cfg

then enterggdG(Delete all content, strictly follow case), enter the following configuration

# 数据同步的基本时间单位(毫秒),默认2000
tickTime=2000

#  follower初始化连接到leader的最大心跳数(tickTime的倍数)
initLimit=10

#  follower与leader之间发送消息的最大心跳数(超过则认为连接失效)
syncLimit=5

# ZooKeeper数据存储目录(需与HBase的hbase.zookeeper.property.dataDir一致)
dataDir=/export/servers/zookeeper/data

# 客户端连接ZooKeeper的端口(默认2181,HBase会通过此端口连接)
clientPort=2181

# 集群节点配置(格式:server.编号=主机名:通信端口:选举端口)
# 编号需与每个节点的myid文件内容一致
server.1=hadoop01:2888:3888
server.2=hadoop02:2888:3888
server.3=hadoop03:2888:3888

# 允许客户端连接的最大数量(默认60,按需调整)
maxClientCnxns=60

# 自动清理事务日志的时间(小时),默认0表示不自动清理
autopurge.purgeInterval=1

Create a data directory on hadoop01 and write myid

mkdir -p /export/servers/zookeeper/data

sudo vim /export/servers/zookeeper/data/myid

Write the following

1

Distribution of ZooKeeper

Distribution of environmental variables

scp /etc/profile hadoop02:/tmp/profile

ssh hadoop02 "sudo cp /tmp/profile /etc/profile && sudo rm /tmp/profile"

scp /etc/profile hadoop03:/tmp/profile

ssh hadoop03 "sudo cp /tmp/profile /etc/profile && sudo rm /tmp/profile"

Distribution of ZooKeeper

scp -r /export/servers/zookeeper hadoop02:/tmp/

ssh hadoop02 "sudo cp -r /tmp/zookeeper/ /export/servers/ && sudo rm -rf /tmp/zookeeper"

scp -r /export/servers/zookeeper hadoop03:/tmp/

ssh hadoop03 "sudo cp -r /tmp/zookeeper/ /export/servers/ && sudo rm -rf /tmp/zookeeper"

Edit the myids of the other 2 servers separately

Enter hadoop02:

sudo vim /export/servers/zookeeper/data/myid

Go to hadoop03

sudo vim /export/servers/zookeeper/data/myid

Reload environment variables

ssh hadoop02 "bash -c 'source /etc/profile'"

ssh hadoop03 "bash -c 'source /etc/profile'"

Operation of ZooKeeper

Check whether the port is occupied

sudo netstat -tunlp | grep 2181

If yes, usesudo kill pidConduct a forced end to the process

Empowering ZooKeeper folders

sudo chown -R hadooper /export/servers/zookeeper

sudo chmod -R 755 /export/servers/zookeeper

ssh hadoop02 "sudo chown -R hadooper /export/servers/zookeeper && sudo chmod -R 755 /export/servers/zookeeper"

ssh hadoop03 "sudo chown -R hadooper /export/servers/zookeeper && sudo chmod -R 755 /export/servers/zookeeper"

turn off the firewall

sudo ufw disable

ssh hadoop02 "sudo ufw disable"

ssh hadoop03 "sudo ufw disable"

Execute ZooKeeper run instructions

Execute the following instructions, and then execute jps to check whether zookeeper starts normally. If it starts normally, it will be as shown in the following figure

$ZOOKEEPER_HOME/bin/zkServer.sh start

ssh hadoop02 "bash -c 'source /etc/profile && $ZOOKEEPER_HOME/bin/zkServer.sh start'"

ssh hadoop03 "bash -c 'source /etc/profile && $ZOOKEEPER_HOME/bin/zkServer.sh start'"

Check election results

$ZOOKEEPER_HOME/bin/zkServer.sh status

ssh hadoop02 "bash -c 'source /etc/profile && $ZOOKEEPER_HOME/bin/zkServer.sh status'"

ssh hadoop03 "bash -c 'source /etc/profile && $ZOOKEEPER_HOME/bin/zkServer.sh status'"

The leader can appear at any node

Written by Written by someone else

If you enjoyed this, leave a comment~

Loading...