Zookeeper installation and deployment

Posted by Tory on Fri, 17 Dec 2021 20:13:15 +0100

official

Official website

File download

1. Introduction to Zookeeper

ZooKeeper is a distributed, distributed application coordination service. It is a software that provides consistency services for distributed applications. ( Source: Baidu Encyclopedia)

Zookeeper features

  1. A cluster composed of one Leader and multiple followers;
  2. As long as more than half of the nodes in the cluster survive, the Zookeeper cluster can serve normally;
  3. Global data consistency: each Server saves a copy of the same data. No matter where the Client links to the Server, the data is consistent;
  4. The update requests are made in sequence, and the update requests from the same Client are executed in sequence according to the scheduled sending sequence;
  5. The atomicity of data update. A data update either succeeds or fails;
  6. Real time. Within a certain time range, the Client can read the latest data.

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

2. Installation deployment

2.1 environmental description

Operating system: CentOS Linux release 7.6 1810 (Core)

Operating system installation package: CentOS-7-x86_64-Minimal-1810.iso

JDK version: 1.8

JDK installation package: jdk-8u261-linux-x64.0 rpm

Zookeeper version: 3.6 three

Zookeeper installation package: apache-zookeeper-3.6 3.tar. gz

2.2. Local mode installation and deployment (stand-alone)

Install jdk

# Install jdk
rpm -ivh jdk-8u261-linux-x64.rpm
# View version
java -version

Upload & unzip files

# Create directory
mkdir /opt/module
# decompression
tar -zxvf apache-zookeeper-3.6.3-bin.tar.gz -C /opt/module/

Modify configuration

# Enter directory
cd /opt/module/apache-zookeeper-3.6.3-bin
# Create directory
mkdir zkData
# Enter the configuration file directory
cd conf
# Copy the configuration file. By default, read the zoo cfg
cp zoo_sample.cfg zoo.cfg
# Edit profile
vi zoo.cfg

zoo. Contents to be modified in CFG

# Data directory (can not be changed)
dataDir=/opt/module/apache-zookeeper-3.6.3-bin/zkData

Start service

# Enter the bin directory
cd /opt/module/apache-zookeeper-3.6.3-bin/
# Start service
bin/zkServer.sh start
# Check to see if it starts
jps
# View port occupancy (used to judge whether the service starts normally)
ss -ntl|grep 2181
# View status
bin/zkServer.sh status

# Start client
bin/zkCli.sh
# View files in directory
ls /
# Exit client
quit

# Out of Service
bin/zkServer.sh stop

2.3 Distributed installation and deployment

Note: as long as more than half of the nodes in the Zookeeper cluster survive, the Zookeeper cluster can serve normally. Therefore, Zookeeper cluster requires at least 3 servers. (a cluster composed of two servers, one of which is down, and the cluster will be down.)

Note: in the following installation steps, except that the numbers written in myid are different, the other three servers can be operated the same.

Install jdk

# Install jdk
rpm -ivh jdk-8u261-linux-x64.rpm
# View version
java -version

Upload & unzip files

# Create directory
mkdir /opt/module
# decompression
tar -zxvf apache-zookeeper-3.6.3-bin.tar.gz -C /opt/module/

Modify configuration

# Enter the bin directory
cd /opt/module/apache-zookeeper-3.6.3-bin
# Create data directory
mkdir zkData
# Configuration server number (unique identification)
cd zkData
# Create myid file
touch myid
# Edit myid file
vi myid
# Each server writes a unique identifier (number)

# to configure
cd /opt/module/apache-zookeeper-3.6.3-bin/conf
cp zoo_sample.cfg zoo.cfg
vi zoo.cfg

zoo. Contents to be modified in CFG (same for 3 servers)

# Data directory
dataDir=/opt/module/apache-zookeeper-3.6.3-bin/zkData
# Configure the information of 3 servers in the cluster
# server.A=B:C:D
# A is a number, indicating the server number, corresponding to the number in myid
# B is the IP address of this server
# C is the port where this server exchanges information with the Leader server in the cluster
# D is that if the Leader server in the server cluster hangs up, a port is needed to re elect and select a new Leader, and this port is the interface used to communicate with each other during the election
server.1=192.168.1.1:2888:3888
server.2=192.168.1.2:2888:3888
server.3=192.168.1.3:2888:3888

Open port

# View port opening
firewall-cmd --zone=public --list-ports
# Open port
firewall-cmd --zone=public --add-port=2181/tcp --permanent
firewall-cmd --zone=public --add-port=2888/tcp --permanent
firewall-cmd --zone=public --add-port=3888/tcp --permanent
# service iptables restart 
systemctl restart firewalld.service

Start service

# Enter the bin directory
cd /opt/module/apache-zookeeper-3.6.3-bin/
# Start service
bin/zkServer.sh start
# Check to see if it starts
jps
ss -ntl|grep 2181
# View status (Mode: leader or Mode: follower)
bin/zkServer.sh status

# Start client
bin/zkCli.sh
# View files in directory
ls /
# Exit client
quit

# Out of Service
bin/zkServer.sh stop

summary

Zookeeper single machine deployment is relatively simple, and cluster deployment is not too complex. Just pay attention to the details.

Topics: Big Data Zookeeper Distribution