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:
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
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:
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
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:
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
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:
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
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:
echo '1' > data/myid
129 data/myid is modified as follows:
echo '2' > data/myid
130 data/myid is modified as follows:
echo '3' > data/myid
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:
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
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:
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
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:
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
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:
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
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:
echo '1' > data/myid
129 data/myid is modified as follows:
echo '2' > data/myid
130 data/myid is modified as follows:
echo '3' > data/myid