ZooKeeper Perfect Installation Guide: From Single Node to Cluster Deployment Raiders in CentOS

1 Introduction

  ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. Its efficient and stable features make it an indispensable component in a distributed environment. This article will take an in-depth look at how to install and configure the latest version of ZooKeeper on a CentOS system, covering a full deployment from a single node to a cluster.

2. Environment preparation

2.1 Software version

System version: centos7.6
jdk version: jdk8 (starting from zookeeper3.5.5, the minimum jdk version is jdk8)
zookeeper version: 3.8.1

2.2 install jdk

  1. Log in to the jdk8 download address , download jdk8, or use the address I copied
  2. Unzip to /usr/local/jdk
  3. Configure environment variables, vi /etc/profileadd at the end
#java environment
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

Execute the refresh command to make the configuration take effect:source /etc/profile

  1. Execute java -versionand print jdk information
[root@localhost ~]# java -version
java version "1.8.0_301"
Java(TM) SE Runtime Environment (build 1.8.0_301-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.301-b09, mixed mode)
[root@worker1 zookeeper]# 

3. Download and unzip

Log in to the download address , choose to download the latest 3.8.1 version or use the address I copied
insert image description here
to perform decompression tar -zxvf apache-zookeeper-3.8.1-bin.tar.gz
and move the directorymv apache-zookeeper-3.8.1-bin /usr/local/zookeeper

4. Detailed configuration file

# 设置ZooKeeper的基本时间单元(单位:毫秒)。该时间用于心跳和超时等。
tickTime=2000
# 设置ZooKeeper集群中的Follower服务器初始化连接到Leader服务器的超时时间(以tickTime的倍数表示)
initLimit=10
# 设置ZooKeeper集群中Follower服务器与Leader服务器之间的同步限制(以tickTime的倍数表示)
syncLimit=5
# 指定ZooKeeper数据存储目录 
dataDir=/usr/local/zookeeper/data
# 指定ZooKeeper事务日志目录,如果不配置默认使用dataDir配置
dataLogDir=/usr/local/zookeeper/logs
# 指定ZooKeeper客户端访问端口
clientPort=2181
# 设置ZooKeeper的最大客户端连接数。设置为0表示无限制
maxClientCnxns=60
# 设置自动清理旧的事务快照文件的保留数量
autopurge.snapRetainCount=3
# 设置自动清理旧的事务快照文件的时间间隔(以小时为单位),设置为"0"以禁用自动清理功能
autopurge.purgeInterval=1

5. Single node installation

Go to the zookeeper directory to create the data directory and log directory

[root@localhost zookeeper]# mkdir {data,logs}

In the conf directory, copy zoo_sample.cfg and rename it to zoo.cfg. When zookeeper starts, it will look for the zoo.cfg configuration file in the conf directory

[root@localhost zookeeper]# cp conf/zoo_sample.cfg  conf/zoo.cfg

Modify the zoo.cfg file, mainly modify the data directory and log directory

dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/logs

Execute the startup command
bin/zkServer.sh start
Or, what needs to be noted here is that –config is the directory with the configuration file, not the configuration file.
bin/zkServer.sh --config conf start
Check whether it is started, execute it jps, and you can see that there is an additional QuorumPeerMain process, indicating that the startup is successful

[root@localhost zookeeper]# jps
7698 QuorumPeerMain
7810 Jps
[root@localhost zookeeper]# 

6. Cluster installation

6.1 Machine preparation

I have prepared three machines with jdk8 installed, respectively 192.168.1.21 , 192.168.1.22 , 192.168.1.23
. For the convenience of subsequent configuration, the hostname of the machine needs to be modified respectively.
Machine 1 execution: hostnamectl set-hostname worker1
Machine 2 execution: hostnamectl set-hostname worker2
Machine 2 execution: hostnamectl set-hostname worker3
Yes uname -aIt takes effect by checking the usage
. At the same time, the contents of the local host files of these three machines need to be modified:

192.168.1.21 worker1
192.168.1.22 worker2
192.168.1.23 worker3

Modify the host content to execute vi /etc/hosts, and save it after modification to take effect

6.2 Modify the configuration file

The three machines need to create the data directory data and the log directory logs in the zookeeper installation directory.
Because the three machines are configured with hostname and modified host , the three machines can use the same configuration as follows:

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/logs
clientPort=2181
maxClientCnxns=60
autopurge.snapRetainCount=3
autopurge.purgeInterval=1
server.1=worker1:2888:3888
server.2=worker2:2888:3888
server.3=worker3:2888:3888

server.1=worker1:2888:3888Detailed explanation about :
1 : It is the unique identifier of the server, and then create a myid file in the data directory, and the content of the file is the value of the ID (the content created in step 6.3) worker1: It is the host
name or IP address of the server, and the host content has been modified earlier , so you can use worker1
2888 : Communication port for data synchronization between nodes
3888 : Communication port for electing Leader nodes

6.3 Create myid file

Machine 1 executes: echo 1 >> /usr/local/zookeeper/data/myid
Machine 2 executes: echo 2 >> /usr/local/zookeeper/data/myid
Machine 3 executes:echo 3 >> /usr/local/zookeeper/data/myid

6.4 Start the cluster

Execute the startup command on the three machines separatelybin/zkServer.sh start

7. Recommended GUI tools

I recommend using PrettyZoo here , I am using it under windows, so download prettyZoo-win.zip,
insert image description here
download and decompress it, and double-click prettyZoo.exe to use it
insert image description here

8. Test cluster

Use the prettyZoo tool to add the address of our machine 1. After adding the ip address, click save to save.
insert image description here
Add data, enter the path and data, and click create to create
insert image description here
. Add and connect to machine 2
insert image description here
to see the data we added in machine 1.
insert image description here

  1. Summary
      This article details the installation and configuration of ZooKeeper latest 3.8.1 on CentOS 7.6. It starts from the environment preparation, and proceeds to the download and installation of zookeeper, and provides a detailed explanation of the configuration file. At the same time, a practical GUI tool is also recommended, and the cluster installation is verified through actual tests. Through this article, I hope you can understand and master how to configure and use ZooKeeper in the CentOS 7.6 environment.

Guess you like

Origin blog.csdn.net/dougsu/article/details/131503755