This is the third day of my participation in the August Text Challenge.More challenges in August

1. Zookeeper environment construction

The following uses the Linux operating system as an example to describe how to install ZooKeeper.

1) Stand-alone environment

1. Install JDK

There are a lot of information online, you can find it yourself.

2. Download ZooKeeper

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

3. Decompress the package

Tar ZXVF – apache – they are – 3.6.1 track – bin. Tar. Gz

4. Go to the apache-zookeeper-3.6.1-bin directory and change the zoo_sample. CFG file name CD apache-zookeeper-3.6.1-bin

cd conf

mv zoo_sample.cfg zoo.cfg

5. The ZooKeeper service is started

cd ..

bin/zkServer.sh start

If the following information is displayed, the startup is successful

Viewing the Startup Status

bin/zkServer.sh status

Shut down the server

bin/zkServer.sh stop

Check the server status again

2) Cluster environment

A real cluster needs to be deployed on different servers, but in our test, it consumes too much memory to start multiple virtual machines, so we usually build a pseudo cluster, that is, all the services are built on one VIRTUAL machine and distinguished by ports.

The preparatory work

1. Install JDK

2. Download ZooKeeper

3. Decompress zooKeeper, copy the zoo_sample. CFG file from the conf file to zoo1. CFG, zoo2. CFG, and zoo3. CFG

4. Create a data directory in the decompressed ZooKeeper directory and create three subdirectories data1, data2, and data3 respectively

5. Set the dataDir (zoo.cfg) clientPort of each ZooKeeper to 2181, 2182, and 2183

Configure the cluster

1. Create a myID file in the data directory of each ZooKeeper with the contents 1, 2, and 3 respectively. This file records the ID of each server

2. In zookeeper zoo. CFG, configure the client access port clientPort and cluster server IP address list.

Server. 1 = 127.0.0.1:2881-3881

Server. 2 = 127.0.0.1:2882-3882

Server. 3 = 127.0.0.1:2883-3883

Server. server ID= SERVER IP address: communication port between servers: port for voting between servers To start a cluster

Start three ZK instances in turn, with a leader and two followers

2. Basic use of ZooKeeper

The data structure

The result of the ZooKeeper data model is similar to the Unix file system and can be viewed as a tree as a whole, with each node called a ZNode and each ZNode uniquely identified by its path

ZNode Node type

1. Persistent directory node (Persisitent) : After the client disconnects from ZooKeeper, Persisitent still exists

Persisitent_Sequential: When a client disconnects from ZooKeeper, the node still exists, and ZooKeeper numbers the node sequentially

3. Ephemeral node: This node was removed after the client was disconnected from ZooKeeper

Ephemeral_Sequential node: After the client disconnects from ZooKeeper, the node is deleted and zooKeeper numbers the node sequentially

Command execution

Use zkClient to access the ZooKeeper client cli and enter help to view the ZooKeeper client commands

The preceding figure lists all zooKeeper client command lines. The following describes some common command lines

1. View the current node data and the number of updates

ls -w /

Create node -s with sequence -e temporary

create zktest data

3. Get the node value

get /zktest

4. Set the node value

set /zktest data1

5. View the node status

stat /

6. Delete the node

delete /zktest

7. Delete nodes recursively

rmr /zktest