Zookeeper 3.7.0 installation and deployment

Keywords: Apache Zookeeper Distribution

1, Introduction

1.1 general

Zookeeper It is an open source distributed framework that provides coordination services for distributed frameworks Apache project

  Working mechanism:

1.2 features

1.3 data structure

         Structure and of ZooKeeper data model Unix The file system is very similar , as a whole, it can be regarded as a tree, and each node is called a tree ZNode . every last ZNode It can be stored by default 1MB Data for each ZNode Fine Uniquely identified by its path.

  1.4 application scenarios

         The services provided include: unified naming service, unified configuration management, unified cluster management, dynamic uplink and downlink of server nodes, soft load balancing, etc.

1.5 download address

Official website address: https://zookeeper.apache.org/

Download address of this version: https://archive.apache.org/dist/zookeeper/zookeeper-3.7.0/

2, Local installation

2.1 Installation Preparation

(1) Install JDK

Refer to: https://blog.csdn.net/qq_37056683/article/details/121099742 

(2) Upload apache-zookeeper-3.7.0-bin.tar.gz to / opt/software on the server and unzip it to / opt/module

[hadoop@ggl201 software]# tar -zxvf apache-zookeeper-3.7.0-bin.tar.gz -C /opt/module/

(3) Modify name

[hadoop@ggl201 module]# mv apache-zookeeper-3.7.0-bin/ zookeeper-3.7.0

2.2 configuration modification

(1) Set / opt/module/zookeeper-3.7.0/conf to the path of zoo_ Modify sample.cfg to zoo.cfg;

[hadoop@ggl201 conf]$ mv zoo_sample.cfg zoo.cfg

(2) Open the zoo.cfg file and modify the dataDir path:

[hadoop@ggl201 zookeeper-3.7.0]$ vim zoo.cfg


#Amend the following:
dataDir=/opt/module/zookeeper-3.7.0/zkData

(3) Create the zkData folder in the directory / opt/module/zookeeper-3.7.0 /

[hadoop@ggl201 zookeeper-3.7.0]$ mkdir zkData

2.3 operation

#(1) Start Zookeeper

[hadoop@ggl201 zookeeper-3.7.0]$ bin/zkServer.sh start

#(2) Check whether the process starts

[hadoop@ggl201 zookeeper-3.7.0]$ jps

#(3) View status

[hadoop@ggl201 zookeeper-3.7.0]$ bin/zkServer.sh status

#(4) Start client

[hadoop@ggl201 zookeeper-3.7.0]$ bin/zkCli.sh

#(5) Exit client:

[zk: localhost:2181(CONNECTED) 0] quit

#(6) Stop Zookeeper

[hadoop@ggl201 zookeeper-3.7.0]$ bin/zkServer.sh stop

2.4 interpretation of configuration parameters

Zookeeper Configuration files in zoo.cfg The meaning of parameters in is interpreted as follows:
(1) Ticketime = 2000: Communication heartbeat time, heartbeat time between Zookeeper server and client, unit: Ms

(2) initLimit = 10: initial communication time limit of LF

The maximum number of heartbeats that leaders and followers can tolerate during initial connection (the number of ticktimes)
(3) syncLimit = 5: LF synchronous communication time limit

  If the communication time between Leader and Follower exceeds syncLimit * tickTime, Leader thinks Follower is dead and deletes Follower from the server list.
(4) dataDir: save data in Zookeeper

Note: the default tmp directory is easy to be deleted regularly by the Linux system, so the default tmp directory is generally not used.
(5) clientPort = 2181: the client connection port, which is usually not modified.

  3, Cluster deployment

  3.1 cluster installation

(1) Cluster planning

         Zookeeper is deployed on the three nodes ggl201, ggl202 and ggl203 (odd sets are installed)

(2) Distribute Zookeeper
[hadoop@ggl201 module]$ sudo xsync zookeeper-3.7.0/

(3) Configure server number

[hadoop@ggl201 zkData]$ vim myid
[hadoop@ggl202 zkData]$ vim myid
[hadoop@ggl203 zkData]$ vim myid


#Add the number corresponding to the server in the file (Note: there should be no blank lines at the top and bottom, and no spaces at the left and right)
#Add separately 
1 2 3

(4) Configuration zoo.cfg file

#Rename the zoo in the directory / opt/module/zookeeper-3.5.7/conf_ Sample.cfg is zoo.cfg
[hadoop@ggl201 conf]$ mv zoo_sample.cfg zoo.cfg

#Open the zoo.cfg file
[hadoop@ggl201 conf]$ vim zoo.cfg

#Modify data storage path configuration
dataDir=/opt/module/zookeeper-3.7.0/zkData

#Add the following configuration
#######################cluster##########################
server.1=ggl201:2888:3888
server.2=ggl202:2888:3888
server.3=ggl203:2888:3888

#Interpretation of configuration parameters
server.A=B:C:D.  
A Is a number indicating the server number;
Configure a file in cluster mode myid,This file is in dataDir Under the directory, there is a data in this file A The value of, Zookeeper Read this file at startup and get the data and zoo.cfg Compare the configuration information inside to determine which one it is server. 
B Is the address of this server;
C This is the server Follower With in the cluster Leader The port where the server exchanges information;
D It's in the cluster Leader The server is down. You need a port to re elect and choose a new one
Leader,This port is used to communicate with each other during the election.

#Synchronize the zoo.cfg configuration file
[hadoop@ggl201 conf]$ xsync zoo.cfg

(5) Cluster operation

#Start Zookeeper separately
[hadoop@ggl201 zookeeper-3.7.0]$ bin/zkServer.sh start
[hadoop@ggl202 zookeeper-3.7.0]$ bin/zkServer.sh start
[hadoop@ggl203 zookeeper-3.7.0]$ bin/zkServer.sh start

#View status
[hadoop@ggl201 zookeeper-3.7.0]$ bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.7.0/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower

[hadoop@ggl202 zookeeper-3.7.0]$ bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.7.0/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower

[hadoop@ggl203 zookeeper-3.7.0]$ bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.7.0/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leader

3.2 electoral mechanism

(1) First start

  (2) Not the first start

3.3 cluster startup script

(1) Create the script in / home/hadoop/bin directory of ggl201

[hadoop@ggl201 zookeeper-3.7.0]$ cd /home/hadoop/bin/
[hadoop@ggl201 bin]$ vim zk.sh

  Add the following:

#!/bin/bash
case $1 in
"start"){
for i in ggl201 ggl202 ggl203
do
 echo ---------- zookeeper $i start-up ------------
ssh $i "/opt/module/zookeeper-3.7.0/bin/zkServer.sh 
start"
done
};;
"stop"){
for i in ggl201 ggl202 ggl203
do
 echo ---------- zookeeper $i stop it ------------ 
ssh $i "/opt/module/zookeeper-3.7.0/bin/zkServer.sh 
stop"
done
};;
"status"){
for i in ggl201 ggl202 ggl203
do
 echo ---------- zookeeper $i state ------------ 
ssh $i "/opt/module/zookeeper-3.7.0/bin/zkServer.sh 
status"
done
};;
esac

(2) Add execution permission

[hadoop@ggl201 bin]$ chmod +x zk.sh

(3) Test script

[hadoop@ggl201 zookeeper-3.7.0]$ zk.sh status
[hadoop@ggl201 zookeeper-3.7.0]$ zk.sh stop
[hadoop@ggl201 zookeeper-3.7.0]$ zk.sh start

(4) Distribute script

[hadoop@ggl201 bin]$ xsync zk.sh

4, Client command line operation

4.1 command line syntax

  (1) Start client

[hadoop@ggl201 zookeeper-3.7.0]$ bin/zkCli.sh -server ggl201:2181

  four point two   znode node data information

(1) View the information contained in the current node

        

(2) View current node details

         

         1> Czxid: create the transaction zxid of the node. Each time the ZooKeeper state is modified, a ZooKeeper transaction ID will be generated. The transaction ID is the total order of all modifications in ZooKeeper. Each modification has a unique zxid. If zxid1 is less than zxid2, zxid1 occurs before zxid2.
         2> CTime: the number of milliseconds that znode was created (since 1970)
         3> Mzxid: transaction zxid last updated by znode
         4> Mtime: the number of milliseconds the znode was last modified (since 1970)
         5> Pzxid: the last updated child node zxid of znode
         6> Cversion: change number of znode child node and modification times of znode child node
         7> Data version: znode data change number
         8> Aclversion: change number of znode access control list
         9> Ephemeral owner: if it is a temporary node, this is the session id of the znode owner. 0 if it is not a temporary node.

         10> Datalength: the data length of znode

        11> Numchildren: number of child nodes of znode

four point three   Node type (persistent / transient / with sequence number / without sequence number)

four point four   Listener principle

The client registers and listens to the directory node it cares about. When the directory node changes (data changes, node deletion, sub directory node addition and deletion), ZooKeeper will notify the client. The monitoring mechanism ensures that any change of any data saved by ZooKeeper can quickly respond to the application listening to the node.

 

 

 

Posted by wildteen88 on Wed, 03 Nov 2021 15:20:03 -0700