Installation and configuration of zookeeper cluster

As long as more than half of the nodes in the zookeeper cluster are normal, the whole cluster is available to the outside world. Based on this feature, it is more appropriate to set the number of nodes of ZK cluster to an odd number (2n+1: such as 3, 5 and 7 nodes).

Server 1: 192.168.1.81 port: 2181, 2881, 3881
Server 2: 192.168.1.82 port: 2182, 2882, 3882
Server 3: 192.168.1.83 port: 2183, 2883, 3883

1. Modify the / etc/hosts file of the operating system and add the mapping between IP and host name:

192.168.1.81 edu-zk-01
192.168.1.82 edu-zk-02
192.168.1.83 edu-zk-03

2. Download or upload zookeeper-3.4.6 tar. / okeeper / wusez Directory:

​cd /home/wusc/zookeeper 
wget http://apache.fayea.com/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz

3. Unzip the zookeeper installation package and rename the zookeeper directory according to the node number:

$ tar -zxvf zookeeper-3.4.6.tar.gz

Server 1:

$ mv zookeeper-3.4.6 node-01

Server 2:

$ mv zookeeper-3.4.6 node-02

Server 3:

$ mv zookeeper-3.4.6 node-03

4. Create the following directories under each zookeeper node Directory:

$ cd /home/wusc/zookeeper/node-0X  (X Represents node numbers 1, 2 and 3, the same solution below)
$ mkdir data
$ mkdir logs

5. Copy profile

Set the zoo in the zookeeper/node-0X/conf directory_ sample. One copy of CFG file named zoo cfg:

$ cp zoo_sample.cfg zoo.cfg

6. Modify zoo CFG configuration file

The configuration of zookeeper/node-01 (/ home/wusc/zookeeper/node-01/conf/zoo.cfg) is as follows:

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/wusc/zookeeper/node-01/data
dataLogDir=/home/wusc/zookeeper/node-01/logs
clientPort=2181
server.1=edu-zk-01:2881:3881
server.2=edu-zk-02:2882:3882
server.3=edu-zk-03:2883:3883

The configuration of zookeeper/node-02 (/ home/wusc/zookeeper/node-02/conf/zoo.cfg) is as follows:

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/wusc/zookeeper/node-02/data
dataLogDir=/home/wusc/zookeeper/node-02/logs
clientPort=2182
server.1=edu-zk-01:2881:3881
server.2=edu-zk-02:2882:3882
server.3=edu-zk-03:2883:3883

The configuration of zookeeper/node-03 (/ home/wusc/zookeeper/node-03/conf/zoo.cfg) is as follows:

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/wusc/zookeeper/node-03/data
dataLogDir=/home/wusc/zookeeper/node-03/logs
clientPort=2183
server.1=edu-zk-01:2881:3881
server.2=edu-zk-02:2882:3882
server.3=edu-zk-03:2883:3883

Parameter Description:

  • tickTime=2000 * tickTime this time is used as the time interval between Zookeeper servers or between clients and servers to maintain heartbeat, that is, a heartbeat will be sent every tickTime.
  • initLimit=10 ﹐ initLimit this configuration item is used to configure the maximum number of heartbeat intervals that Zookeeper accepts clients (the client mentioned here is not the client that users connect to the Zookeeper server, but the Follower server connected to the Leader in the Zookeeper server cluster) can endure when initializing connections. If the Zookeeper server has not received the return information from the client after 10 heartbeats (that is, tickTime), it indicates that the client connection has failed. The total length of time is 10 * 2000 = 20 seconds.
  • syncLimit=5 * syncLimit this configuration item identifies the length of message sending, request and response time between Leader and Follower. The maximum length of time can not exceed the length of tickTime. The total length of time is 5 * 2000 = 10 seconds.
  • dataDir=/home/wusc/zookeeper/node-01/data dataDir, as its name suggests, is the directory where Zookeeper saves data. By default, Zookeeper also saves the log files that write data in this directory.
  • clientPort=2181. clientPort is the port where the client (application) connects to the zookeeper server. Zookeeper will listen to this port and accept the client's access requests.

server.A=B: C: D
server.1=edu-zk-01:2881:3881
server.2=edu-zk-02:2882:3882
server.3=edu-zk-03:2883:3883
A is a number indicating the server number;
B is the IP address of the server (or the host name mapped with the IP address);
C the first port is used for information exchange among cluster members, indicating the port where this server exchanges information with the Leader server in the cluster;
D is the port specially used for election when the leader hangs up.
Note: in case of pseudo cluster configuration, the communication port numbers of different Zookeeper instances cannot be the same, so they should be assigned different port numbers.

7. Create the myid file under dataDir=/home/wusc/zookeeper/node-0X/data

Edit the myid file and enter the corresponding number on the corresponding IP machine. For example, on node-01, the content of myid file is

1. 2 on node-02 and 3 on node-03:

$ vi /home/wusc/zookeeper/node-01/data/myid  ##The value is 1
$ vi /home/wusc/zookeeper/node-02/data/myid  ##The value is 2
$ vi /home/wusc/zookeeper/node-03/data/myid  ##The value is 3

8. Open ports 218X, 288X and 388X in the firewall

Switch to root and execute the following command:

chkconfig iptables on
service iptables start

Edit / etc/sysconfig/iptables

vi /etc/sysconfig/iptables

For example, add the following three lines to server 01:

-A INPUT -m state –state NEW -m tcp -p tcp –dport 2181 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 2881 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3881 -j ACCEPT

Restart firewall:

service iptables restart

View firewall port status:

service iptables status

9. Start and test zookeeper (to start with wusc user, not root):

(1) Use wusc user to execute in / home/wusc/zookeeper/node-0X/bin directory:

$ /home/wusc/zookeeper/node-01/bin/zkServer.sh start
$ /home/wusc/zookeeper/node-02/bin/zkServer.sh start
$ /home/wusc/zookeeper/node-03/bin/zkServer.sh start

$  jps
1456 QuorumPeerMain

QuorumPeerMain is the zookeeper process, indicating that the startup is normal

(2) View status:

$ /home/wusc/zookeeper/node-01/bin/zkServer.sh status

(3) To view the zookeeper service output information:

Because the service information output file is in / home / wusc / zookeeper / node-0x / bin / zookeeper out

$ tail -500f zookeeper.out

10. To stop the zookeeper process:

$ zkServer.sh stop

11. Configure zookeeper boot to use wusc user boot

Edit / etc / RC. In node-01, node-02 and node-03 Local file, respectively add:

su - wusc -c '/home/wusc/zookeeper/node-01/bin/zkServer.sh start'
su - wusc -c '/home/wusc/zookeeper/node-02/bin/zkServer.sh start'
su - wusc -c '/home/wusc/zookeeper/node-03/bin/zkServer.sh start'

Keywords: Zookeeper Distribution

Added by lookielookies on Sun, 20 Feb 2022 06:46:03 +0200