Zookeeper cluster environment construction
This cluster uses 3 machines to build the zookeeper distributed coordination framework, and the 3 machines are respectively server01,server02,server03
.
1. Download
Go to the zookeeper download page:
https://www.apache.org/dyn/closer.cgi/zookeeper/
Download the corresponding tar.gz package. Such as:zookeeper-3.4.5.tar.gz
Will zookeeper-3.4.5.tar.gz
upload to the hadoop
user, /hadoop
directory on the linux machine.
scp zookeeper-3.4.5.tar.gz hadoop@server01:/hadoop
After server01
the configuration is done in the first, it is distributed to server02
the server03
machine.
2. Decompression
enter the /hadoop
directory
cd /hadoop
decompresszookeeper-3.4.5.tar.gz
tar -zxvf zookeeper-3.4.5.tar.gz
Change the unzipped zookeeper-3.4.5
directory to the zookeeper
directory
mv zookeeper-3.4.5 zookeeper
3. Configure the zoo.cfg file of zookeeper
Enter the zookeeper/conf directory
cd ./zookeeper/conf/
copy file zoo_sample.cfg
as zoo.cfg
file
cp zoo.cfg.sample zoo.cfg
Edit the zoo.cfg file as follows:
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/hadoop/zookeeper/data
dataLogDir=/hadoop/zookeeper/log
# the port at which the clients will connect
clientPort=2181
server.1=server01:2888:3888
server.2=server02:2888:3888
server.3=server03:2888:3888
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
zookeeper
Create data
directory and directory under log
directory
# 进入zookeeper目录
cd /hadoop/zookeeper
mkdir data
mkdir log
4. Configure myid (important)
enter the data
directory
cd ./data
write 1 to myid file
echo 1 > myid
The myid in each machine cannot be repeated, otherwise it will cause the zookeeper to hang up after it gets up.
5. Distribute the zookeeper folder to other machines
# 将zookeeper目录分发到server02机器上的/hadoop目录
scp -r /hadoop/zookeeper hadoop@server02:/hadoop
# 将zookeeper目录分发到server03机器上的/hadoop目录
scp -r /hadoop/zookeeper hadoop@server03:/hadoop
6. Modify the myid of each machine (important)
Change the myid on the server02 machine to 2
Enter the zookeeper/data directory, edit the myid file, and change 1 to 2
Change the myid on the server03 machine to 3
Enter the zookeeper/data directory, edit the myid file, and change 1 to 3
7. Configure environment variables on each machine
Configure environment variables on each machine
vim /etc/profile
write environment variable
export ZOOKEEPER_HOME=/hadoop/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
Use source to make environment variables take effect
source /etc/profile
8. Start zookeeper
Execute the zookeeper start command on each machine:
zkServer.sh start
It is recommended to use tools such as Xshell to execute the command in multiple session windows at the same time
9. View the zookeeper cluster status
Use the following command to view the status of zookeeper
zkServer.sh status