download

Download address: http://zookeeper.apache.org/

Regardless of the download process, we downloaded the latest ZooKeeper-3.4.11.

The installation

1. Upload the installation package

Upload the latest downloaded package (for example, zookeeper-3.4.11.tar.gz) to the server.

2, decompression

$tar ZXVF zookeeper – 3.4.11. Tar. Gz

3. Go to the /usr/local directory

$mv zookeeper – 3.4.11 / usr/local/zookeeper

The cluster configuration

In principle, a Zookeeper cluster requires 2n+1 instances to ensure cluster validity. Therefore, at least three Zookeeper clusters are required.

The following shows how to create a three-node Zookeeper cluster, as well as an n-node cluster.

1. Create a directory for storing data files

$ cd /usr/local/zookeeper

$ mkdir data

2. Add the master configuration file

$ cd conf

$ cp zoo_sample.cfg zoo.cfg

3. Modify the configuration

$ vi zoo.cfg

Comment out dataDir=/ TMP /zookeeper and add the following core configuration.

dataDir=/usr/local/zookeeper/data

Server. 1 = 192.168.10.31:2888-3888

Server. 2 = 192.168.10.32:2888-3888

Server. 3 = 192.168.10.33:2888-3888

Create myID file

$ cd .. /data

$ touch myid

$ echo 1myid

The value in myID for each machine corresponds to the number X after server.

5. Open 3 ports

$ sudo /sbin/iptables -I INPUT -p tcp –dport 2181 -j ACCEPT

$ sudo /sbin/iptables -I INPUT -p tcp –dport 2888 -j ACCEPT

$ sudo /sbin/iptables -I INPUT -p tcp –dport 3888 -j ACCEPT

$ sudo /etc/rc.d/init.d/iptables save

$ sudo /etc/init.d/iptables restart

$ sudo /sbin/iptables -L -n

Chain INPUT (policy ACCEPT)

target prot opt source destination

ACCEPT TCP — 0.0.0.0/0 0.0.0.0/0 TCP DPT :3888

ACCEPT TCP — 0.0.0.0/0 0.0.0.0/0 TCP DPT :2888

ACCEPT TCP — 0.0.0.0/0 0.0.0.0/0 TCP DPT :2181

6. Configure other machines in the cluster

Copy the Zookeeper directory to the other two machines and repeat steps 4-5.

$SCP – r/usr/local/zookeeper [email protected]: / usr/local /

7. Restart the cluster

$ /usr/local/zookeeper/bin/zkServer.sh start

All three ZooKeepers need to be started.

8. Check the cluster status

$ /usr/local/zookeeper/bin/zkServer.sh status

ZooKeeper JMX enabled by default

Using config: /usr/local/zookeeper/bin/.. /conf/zoo.cfg

Mode: follower

Client connection

. / zkCli. Sh – server 192.168.10.31:2181

Do not use -server when connecting to the local computer.

Pay attention to

If multiple Pseudo Zookeeper clusters are created on a single node, modify configurations such as ports, log files, and data file locations.