1.Zookeeper

1.1 they are introduced

ZooKeeper is a distributed, open source distributed application coordination service. It is an open source implementation of Google’s Chubby and an important component of Hadoop and Hbase. It provides consistency services for distributed applications, including configuration and maintenance, domain name service, distributed synchronization, and group service. ZooKeeper aims to encapsulate key services that are complex and error-prone, and provide users with easy-to-use interfaces, efficient performance, and stable functions. ZooKeeper contains a simple set of primitives that provide Java and C interfaces. The ZooKeeper code version, which provides an interface for distributed exclusive locks, elections, and queues, is in Zookeeper-3.4.3 SRC \recipes. Distribution locks and queues have Java and C versions, and elections have only Java versions.

Summary :Zookeeper is responsible for service coordination and scheduling. When the client initiates a request, the correct server address is returned.

1.2 they download

Address: zookeeper.apache.org/releases.ht…

As shown in the figure:To download it, click Download

Zookeeper:Mirrors.hust.edu.cn/apache/zook…


2. They are installed

2.1 to install the JDK

Upload the JDK1.8 file to the /src/usr/local/java/ file in Linux

As shown in the figure:1. Decompress files

tar -xvf jdk-8u51-linux-x64.tar.gz
Copy the code

2. Configure environment variables

Edit the environment variable configuration file

vim /etc/profile
Copy the code

As shown in the figure:Enable the JDK to take effect, and then check whether the JDK was installed successfully

source /etc/profile
Copy the code

As shown in the figure:

2.2 Uploading the Installation File

Note: Upload the ZooKeeper installation file and decompress it.

As shown in the figure:

Unzip directory:

tar -xvf apache-zookeeper-3.6. 0-bin.tar.gz 
Copy the code

Delete compressed packages:

rm -f apache-zookeeper-3.6. 0-bin.tar.gz 
Copy the code

Modify file name:

mv apache-zookeeper-3.6. 0-bin zookeeper
Copy the code

2.3 Modifying the Configuration File (Single-Boot Device)

Skip this step and install the Zookeeper cluster

Create the data/log folder in the root directory of ZooKeeper

mkdir data log
Copy the code

As shown in the figure:

Jump into the conf directory to modify the configuration file

Copy the configuration file and change the name

cp zoo_sample.cfg zoo.cfg
Copy the code

As shown in the figure:

2.4 start the zk

To switch to the bin directory, run the following command to start or stop zk:

Sh start or./zkServer.sh start sh zkserver. sh stop sh zkServer.sh statusCopy the code

As shown in the figure:


3. Install the Zookeeper cluster

3.1 Preparing a Folder

Create a new folder zkCluster in the root directory of ZooKeeper

As shown in the figure:

As shown in the figure:

createzk1/zk2/zk3folder

Create a data/log folder in each folder

mkdir {zk1,zk2,zk3}/{data,log}
Copy the code

As shown in the figure:

3.2 Adding the myID file

Create a new file myID in the data folder of zk1/zk2/zk3 with the contents 1/2/3 corresponding to the ZK node number.

vim zk1/data/myid
vim zk2/data/myid
vim zk3/data/myid
Copy the code

As shown in the figure:

Open a new window:

Look at the myID file, the number defined. As shown in the figure:

3.3 Editing a Configuration File

CFG is copied to zoo_sample. CFG and modified.

As shown in the figure:

3.4 modify zoo1. CFG

As shown in the figure:After the configuration is completezoo1.cfgMake two copies, and then modify the corresponding folder directory and different ports.

3.5 ZK Cluster Test

Start the ZK cluster by running the following command.

Sh zkserver. sh start zoo1. CFG # Start zoo1. CFG # Stop zoo1. CFG # Stop zoo1. CFG # Stop zoo1. CFG # Check zkserver. sh status zoo1. CFG # Check zoo1. CFGCopy the code

As shown in the figure:

Check the master/slave relationship and slave information.

As shown in the figure:

Check the master/slave relationship and the host information.

As shown in the figure:

Configuration successful:

3.6 About the ZooKeeper Cluster

In a Zookeeper cluster, the leader monitors the cluster status, while followers obtain service list information from clients and vote.