gogoWebsite

Zookeeper download and install

Updated to 1 hour ago

Zookeeper

1. Download

Official download address: /

Version: apache-zookeeper-3.7.

2. Installation

2.1 Local installation

2.1.1 Install JDK

See:Hadoop cluster construction

2.1.2 Upload the installation package

Use remote tools to copy the installation package to Linux specified path

/opt/software
2.1.3 Unzip to the specified directory

Unzip the installation package into /opt/module

[li@hadoop102 software]$ tar -zxvf apache-zookeeper-3.7. -C /opt/module/
2.1.4 Modify the installation package name
[li@hadoop102 module]$ mv apache-zookeeper-3.7.1-bin/ zookeeper-3.7.1
2.1.5 Configuration modification

(1) Change zoo_sample.cfg in the path /opt/module/zookeeper-3.7.1/conf to ;

[li@hadoop102 conf]$ mv zoo_sample.cfg 

(2) Open the file and modify the dataDir path:

[li@hadoop102 zookeeper-3.7.1]$ vim 

Modify the following content:

dataDir=/opt/module/zookeeper-3.7.1/zkData

Configuration parameter interpretation:

1) tickTime = 2000: Communication heartbeat time, Zookeeper server and client heartbeat time, unit milliseconds

2) initLimit = 10: LF initial communication time limit. The maximum number of heartbeats that the Leader and Follower can tolerate during initial connection (number of tickTimes)

3) syncLimit = 5: LF synchronous communication time limit

4) dataDir: Save data in Zookeeper Note: The default tmp directory is easily deleted regularly by Linux systems, so the default tmp directory is generally not used.

5) clientPort = 2181: Client connection port, usually no modification is made.

(3) Create the zkData folder on /opt/module/zookeeper-3.7.1/ directory

[li@hadoop102 zookeeper-3.7.1]$ mkdir zkData
2.1.6 Operation of Zookeeper

(1) Start Zookeeper

[li@hadoop102 zookeeper-3.7.1]$ bin/ start

(2) Check whether the process is started

[li@hadoop102 zookeeper-3.7.1]$ jps
4020 Jps
4001 QuorumPeerMain

(3) Check the status

[li@hadoop102 zookeeper-3.7.1]$ bin/ stutas
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.7.1/bin/../conf/
Usage: /opt/module/zookeeper-3.7.1/bin/ [--config <conf-dir>] {start|start-foreground|stop|version|restart|status|print-cmd}

(4) Start the client

[li@hadoop102 zookeeper-3.7.1]$ bin/

(5) Exit the client:

[zk: localhost:2181(CONNECTING) 3] quit

(6) Stop Zookeeper

[li@hadoop102 zookeeper-3.7.1]$ bin/ stop
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.7.1/bin/../conf/
Stopping zookeeper ... STOPPED

2.2 Cluster operation

2.2.1 Cluster installation

(1) Cluster Planning

Zookeeper is deployed on three nodes: hadoop102, hadoop103 and hadoop104.

(2) Unzip and install

  1. Unzip the Zookeeper installation package in hadoop102 to /opt/module/ directory
[li@hadoop102 software]$ tar -zxvf apache-zookeeper-3.7. -C /opt/module/
  1. Modify the name of apache-zookeeper-3.7.1-bin to zookeeper-3.7.1
[li@hadoop102 software]$ mv apache-zookeeper-3.7.1-bin/ zookeeper-3.7.1

(3) Configure server number

  1. Create zkData in /opt/module/zookeeper-3.7.1/
[li@hadoop102 software]$ mkdir zkDate
  1. Create a myid file in the /opt/module/zookeeper-3.7.1/zkData directory
[li@hadoop102 software]$ vim myid

Add the number corresponding to the server in the file (note: there are no blank lines up and down, and no spaces on the left and right)

2
  1. Copy the configured zookeeper to another machine
[li@hadoop102 software]$ xsync zookeeper-3.7.1

And modify the contents of the myid file on hadoop103 and hadoop104 respectively to 3 and 4

(4) Configuration file

  1. Rename the zoo_sample.cfg in this directory as
[li@hadoop102 software]$ mv zoo_sample.cfg 
  1. Open the file
[li@hadoop102 software]$ vim 
# Add the following configuration
 server.2=hadoop102:2888:3888
 server.3=hadoop103:2888:38888
 server.4=hadoop104:2888:38888

Configuration parameter interpretation:

=B:C:D

  • A is a number, indicating which server this is; configure a file myid in cluster mode. This file is in the dataDir directory. There is a data in this file, which is the value of A. Zookeeper reads this file when it starts, and gets the data inside and compares the configuration information inside to determine which server it is;
  • B is the address of this server;
  • C is the port where this server Follower exchanges information with the Leader server in the cluster;
  • D is in case the Leader server in the cluster hangs up, and a port is needed to re-election and select a new leader, and this port is the port used to perform the communication between the servers during the election.
  1. Synchronize configuration files
[li@hadoop102 conf]$ xsync 
2.2.2 Cluster operation

(1) Start Zookeeper separately

[li@hadoop102 zookeeper-3.7.1]$ bin/ start
[li@hadoop103 zookeeper-3.7.1]$ bin/ start
[li@hadoop104 zookeeper-3.7.1]$ bin/ start

(2) Check the status

[li@hadoop102 zookeeper-3.7.1]$ bin/ status
[li@hadoop103 zookeeper-3.7.1]$ bin/ status
[li@hadoop104 zookeeper-3.7.1]$ bin/ status
2.2.3 Cluster start-stop script

(1) Create a script in the /home/li/bin directory of hadoop102

[li@hadoop102 bin]$ vim 

Write the following content in the script:

#!/bin/bash

case $1 in
"start")
	for i in hadoop102 hadoop103 hadoop104
	do
 		echo ---------- zookeeper $istart up ------------ssh $i "/opt/module/zookeeper-3.7.1/bin/ start"
	done
;;
"stop")
	for i in hadoop102 hadoop103 hadoop104
    do
 		echo ---------- zookeeper $istop ------------ssh $i "/opt/module/zookeeper-3.7.1/bin/ stop"
    done
;;
"status")
	for i in hadoop102 hadoop103 hadoop104
    do
 		echo ---------- zookeeper $istate ------------ssh $i "/opt/module/zookeeper-3.7.1/bin/ status"
	done
;;
esac

(2) Increase script execution permissions

[li@hadoop102 bin]$ chmod u+x 

(3) Zookeeper cluster startup script

[li@hadoop102 bin]$  start

(4) Zookeeper cluster stop script

[li@hadoop102 bin]$   stop
2.3.4 Adding environment variables

Configure Zookeeper environment variables in my_env.sh and add the following content:

export ZK_HOME=/opt/module/zookeeper-3.7.1
export PATH=$PATH:$ZK_HOME/bin
2.3.5 Distribution of files

Synchronize the changed files to hadoop103, hadoop104

[li@hadoop102 ]$ xsync my_env.sh