ZooKeeper cluster deployment

I. Experimental objectives
(1) Learn about ZooKeeper distributed application coordination services.
(2) Use three machines to build a ZooKeeper cluster.
(3) Use ZooKeeper cluster.
II. Experimental analysis
2.1 planning nodes

IP

host name

node

192.168.32.140

zookeeper1

Cluster node

192.168.32.141

zookeeper2

Cluster node

192.168.32.142

zookeeper3

Cluster node

2.2 foundation preparation
Log in to OpenStack platform and use CentOS provided_ 7.2_ x86_ 64_ Xd.qcow2 image, flavor uses 2vCPU/4GB memory / 50GB hard disk to create virtual machine. Use the provided zookeeper-3.4.14.tar.gz package and gpmall repo folder to install the ZooKeeper service.
III. experimental implementation
3.1 basic environment configuration
(1) Host name configuration
Use secureCRT to connect three virtual machines.
Modify the host names of the three nodes as zookeeper1, zookeeper2 and zookeeper3. The commands are as follows:
zookeeper1 node:

[root@localhost ~]# hostnamectl set-hostname zookeeper1

  zookeeper2 node:

[root@localhost ~]# hostnamectl set-hostname zookeeper2

zookeeper3 node:

[root@localhost ~]# hostnamectl set-hostname zookeeper3

After modification, reconnect secureCRT and view the host name:
zookeeper1 node:

[root@zookeeper1 ~]# hostnamectl 
   Static hostname: zookeeper1
         Icon name: computer-vm
           Chassis: vm
        Machine ID: dae72fe0cc064eb0b7797f25bfaf69df
           Boot ID: c642ea4be7d349d0a929e557f23ce3dc
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-229.el7.x86_64
      Architecture: x86_64

zookeeper2 node:

[root@zookeeper2 ~]# hostnamectl 
   Static hostname: zookeeper2
         Icon name: computer-vm
           Chassis: vm
        Machine ID: dae72fe0cc064eb0b7797f25bfaf69df
           Boot ID: cfcaf92af7a44028a098dc4792b441f4
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-229.el7.x86_64
      Architecture: x86_64

zookeeper3 node:

[root@zookeeper3 ~]# hostnamectl 
   Static hostname: zookeeper3
         Icon name: computer-vm
           Chassis: vm
        Machine ID: dae72fe0cc064eb0b7797f25bfaf69df
           Boot ID: cff5bbd45243451e88d14e1ec75098c0
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-229.el7.x86_64
      Architecture: x86_64

(2) Configure hosts file
Modify the / etc/hosts file for the three nodes, and modify the three nodes to the following code:

# vi /etc/hosts
192.168.32.140zookeeper1
192.168.32.141zookeeper2
192.168.32.142zookeeper3

(3) Configure YUM source
Upload the provided gpmall repo directory to the / opt directory of the three nodes. First move the files in the / etc/yum.repo.d directory of the three nodes to the / media directory. The commands are as follows:

# mv /etc/yum.repos.d/* /media/

Create / etc/yum.repo.d/local.repo on 3 nodes. The file contents are as follows:

# cat /etc/yum.repos.d/local.repo 
[gpmall]
name=gpmall
baseurl=file:///opt/gpmall-repo
gpgcheck=0
enabled=1
# yum clean all
# yum list

3.2 build ZooKeeper cluster
(1) Install JDK environment
The three nodes install the Java JDK environment, and the three nodes execute the following commands:

# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
# java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

(2) Unzip the ZooKeeper package
Upload the zookeeper-3.4.14.tar.gz package to the / root directory of the three nodes for decompression. The three nodes execute the following commands:

# tar -zxvf zookeeper-3.4.14.tar.gz

(3) Modify 3 node profiles
At the zookeeper1 node, enter the zookeeper-3.4.14/conf directory and modify the zoo_ The sample.cfg file is zoo.cfg, and edit the file as follows:

[root@zookeeper1 conf]# vi zoo.cfg 
[root@zookeeper1 conf]# grep -n '^'[a-Z] zoo.cfg 
2:tickTime=2000
5:initLimit=10
8:syncLimit=5
12:dataDir=/tmp/zookeeper
14:clientPort=2181
29:server.1=172.16.51.23:2888:3888
30:server.2=172.16.51.32:2888:3888
31:server.3=172.16.51.41:2888:3888

Command resolution:
         initLimit: in ZooKeeper cluster mode, there are multiple zk processes, one of which is leader and the other is follower. When the follower initially establishes a connection with the leader, a considerable amount of data will be transmitted between them, especially the data of the follower lags far behind the leader. initLimit configures the maximum time for synchronization after the connection between the follower and the leader is established.
         syncLimit: configure the maximum length of time for sending messages, requests and responses between follower and leader.
         tickTime: tickTime is the basic unit of the above two timeout configurations. For example, for initLimit, the configuration value is 5, indicating that the timeout time is 2000ms * 5 = 10 seconds.
         server.id=host:port1:port2: where id is a number indicating the ID of zk process, which is also the content of myid file in dataDir directory. Host is the IP address where the zk process is located. Port1 represents the port used by follower and leader to exchange messages, and port2 represents the port used by leader election.
         dataDir: the meaning of its configuration is similar to that in stand-alone mode, except that there is a myid file in cluster mode. There is only one line in the myid file, and the content can only be a number between 1 and 255. This number, that is, the ID in the server.id described above, represents the ID of the zk process.
Note: the operation of the zookeeper2 and zookeeper3 nodes is the same as that of the modified configuration and zookeeper1 nodes.
(4) Create myid file
Create a myid file in the dataDir directory of the three machines (here, / tmp/zookeeper). The contents of the file are 1, 2 and 3. That is, there is only one number in the file, which is the value specified in the zoo.cfg configuration file above. ZooKeeper determines the identity allocation of each machine in the ZooKeeper cluster according to the file.
Create a myid file with the following command:
zookeeper1 node:

[root@zookeeper1 ~]# mkdir /tmp/zookeeper
[root@zookeeper1 ~]# vi /tmp/zookeeper/myid
[root@zookeeper1 ~]# cat /tmp/zookeeper/myid 

zookeeper2 node:

[root@zookeeper2 ~]# mkdir /tmp/zookeeper
[root@zookeeper2 ~]# vi /tmp/zookeeper/myid
[root@zookeeper2 ~]# cat /tmp/zookeeper/myid

zookeeper3 node:

[root@zookeeper3 ~]# mkdir /tmp/zookeeper
[root@zookeeper3 ~]# vi /tmp/zookeeper/myid
[root@zookeeper3 ~]# cat /tmp/zookeeper/myid 

(5) Start ZooKeeper service
Execute the following command in the zookeeper-3.4.14/bin directory of the three machines:
zookeeper1 node:

[root@zookeeper1 bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@zookeeper1 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: follower

zookeeper2 node:

[root@zookeeper2 bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... already running as process 10175.
[root@zookeeper2 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: leader

zookeeper3 node:

[root@zookeeper3 bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@zookeeper3 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: follower

As you can see, there are three nodes. zookeeper2 is a leader and the others are follower s. So far, ZooKeeper cluster configuration is completed.
Note: when there is a problem viewing the status, start all nodes and then view the status.

Tags: Linux Operation & Maintenance Zookeeper

Posted on Fri, 26 Nov 2021 01:37:16 -0500 by mcl