Installation of zookeeper learning

Zookeeper has three deployment methods: stand-alone, pseudo-cluster, and cluster. You can choose the appropriate deployment method according to your reliability requirements. The three deployment methods are explained one by one below.

 

1. Stand-alone installation

1.1 Download

Enter the directory of the version you want to download and select the .tar.gz file to download

Download link: http://archive.apache.org/dist/zookeeper/

 

1.2 Installation

Use tar to decompress the directory to be installed, take version 3.4.5 as an example

Here, unzip it to /usr/myapp, and the actual installation is modified according to the directory you want to install (note that if you modify it, the following commands and paths in the configuration file must be modified accordingly)

tar -zxf zookeeper-3.4.5.tar.gz -C /usr/myapp

 

1.3 Configuration

Create two directories, data and logs, in the main directory to store data and logs:

cd /usr/myapp/zookeeper-3.4.5
mkdir data
mkdir logs

 

Create a new zoo.cfg file in the conf directory and save it with the following content:

tickTime=2000
dataDir=/usr/myapp/zookeeper-3.4.5/data
dataLogDir=/usr/myapp/zookeeper-3.4.5/logs
clientPort=2181

 

1.4 Start and stop

Enter the bin directory, start, stop, restart, and view the current node status (including what role is in the cluster) and execute:

./zkServer.sh start
./zkServer.sh stop
./zkServer.sh restart
./zkServer.sh status

 

2. Pseudo-cluster mode

The pseudo-cluster mode is to start multiple zookeepers on the same host and form a cluster. The following is an example of creating three zookeeper groups on the 192.168.220.128 host.

Copy the zookeeper installed through the first major point into three copies of zookeeper1/zookeeper2/zookeeper3

 

2.1 zookeeper1 configuration

The zookeeper1 configuration file conf/zoo.cfg is modified as follows:

copy code
tickTime=2000
dataDir=/usr/myapp/zookeeper1/data
dataLogDir=/usr/myapp/zookeeper1/logs
clientPort=2181
initLimit=5
syncLimit=2
server.1=192.168.220.128:2888:3888
server.2=192.168.220.128:4888:5888
server.3=192.168.220.128:6888:7888
copy code

The data/myid configuration of zookeeper1 is as follows:

echo'1' > data/myid 

 

2.2 zookeeper2 configuration

The zookeeper2 configuration file conf/zoo.cfg is modified as follows:

copy code
tickTime=2000
dataDir=/usr/myapp/zookeeper2/data
dataLogDir=/usr/myapp/zookeeper2/logs
clientPort=3181
initLimit=5
syncLimit=2
server.1=192.168.220.128:2888:3888
server.2=192.168.220.128:4888:5888
server.3=192.168.220.128:6888:7888
copy code

The data/myid configuration of zookeeper2 is as follows:

echo'2' > data/myid 

 

2.3 zookeeper3 configuration

The zookeeper3 configuration file conf/zoo.cfg is modified as follows:

copy code
tickTime=2000
dataDir=/usr/myapp/zookeeper3/data
dataLogDir=/usr/myapp/zookeeper3/logs
clientPort=4181
initLimit=5
syncLimit=2
server.1=192.168.220.128:2888:3888
server.2=192.168.220.128:4888:5888
server.3=192.168.220.128:6888:7888
copy code

 The data/myid configuration of zookeeper3 is as follows:

echo'3' > data/myid 

Finally, use the 1.4 command to start all three zookeepers, and the startup order is not required.

 

3. Cluster Mode

Cluster mode is a mode in which zookeeper is installed on different hosts and then forms a cluster; the following is an example of three hosts on 192.168.220.128/129/130.

Copy the zookeeper package installed in steps 1.1 to 1.3 to 129 and 130, and extract them to the same directory.

 

3.1 conf/zoo.cfg file modification

The conf/zoo.cfg of the three zookeepers are modified as follows:

copy code
tickTime=2000
dataDir=/usr/myapp/zookeeper-3.4.5/data
dataLogDir=/usr/myapp/zookeeper-3.4.5/logs
clientPort=2181
initLimit=5
syncLimit=2
server.1=192.168.220.128:2888:3888
server.2=192.168.220.129:2888:3888
server.3=192.168.220.130:2888:3888
copy code

For 129 and 130, since the installation directory is zookeeper-3.4.5, dataDir and dataLogDir do not need to be changed, and because they are on different machines, clientPort does not need to be changed.

So at this time, the content of conf/zoo.cfg of 129 and 130 is the same as that of 128.

 

3.2 data/myid file modification

128 data/myid is modified as follows:

 
 

129 data/myid is modified as follows:

echo'2' > data/myid 

130 data/myid is modified as follows:

echo'3' > data/myid 

Finally, use the 1.4 command to start all three zookeepers, and the startup order is not required.

 

4. Error reporting and handling

The application connection zookeeper reports an error: Session 0x0 for server 192.168.220.128/192.168.220.128:2181, unexpected error, closing socket connection and attempting reconnect;

                                        First, see if the port can be telneted. If so, use ./zkServer.sh status to check whether zk is indeed started. If not, check the error in bin/zookeeper.out.

An error is reported in bin/zookeeper.out: "zookeeper address already in use"; obviously the port is occupied, either other processes occupy the configured port, or the clientPort configured above and the port in the server are duplicated.

An error is reported in bin/zookeeper.out: Cannot open channel to 2 at election address /192.168.220.130:3888; this should just be that the 130 nodes that make up the cluster have not started, and zk will be normal when it starts at 130.


Original text: https://www.cnblogs.com/lsdb/p/7297731.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324850739&siteId=291194637