ZooKeeper stand-alone installation
The installation directory takes / opt/share/zk as an example
-
Create a new directory / opt/share/zk. The command is as follows:
mkdir -p /opt/share/zk
-
Enter / opt/share/zk directory and upload jdk-8u301-linux-x64 tar. GZ file
-
Unzip jdk-8u301-linux-x64.0 tar. GZ file, the command is as follows:
tar -zxvf jdk-8u301-linux-x64.tar.gz
-
Modify the java execution permission. The command is as follows:
chmod u+x jdk1.8.0_301/bin/java*
-
Upload apache-zookeeper-3.6.3-bin.com tar. GZ file
-
Unzip apache-zookeeper-3.6.3-bin tar. GZ file, the command is as follows:
tar -zxvf apache-zookeeper-3.6.3-bin.tar.gz
-
Create a new subdirectory snapshot and log under apache-zookeeper-3.6.3-bin/data /. The command is as follows:
mkdir -p /opt/share/zk/apache-zookeeper-3.6.3-bin/data/snapshot mkdir -p /opt/share/zk/apache-zookeeper-3.6.3-bin/data/log
-
Enter apache-zookeeper-3.6.3-bin/conf directory and create a new Java Env file, the command is as follows:
touch java.env vi java.env
java.env file contents are as follows:
#!/bin/sh #Configure JDK directory export JAVA_HOME=/opt/share/zk/jdk1.8.0_301 #Configure JVM parameters export JVMFLAGS="-Xms1024m -Xmx1024m $JVMFLAGS"
Modify Java Env file execution permission
chmod u+x java.env
-
Copy profile_ sample. CFG is zoo CFG, the command is as follows:
cd apache-zookeeper-3.6.3-bin/conf cp zoo_sample.cfg zoo.cfg
-
Modify zoo CFG configuration file, the command is as follows:
vi zoo.cfg
The following is the modified configuration
#Communication port with client (agent) clientPort=2181 #Snapshot storage directory. Modified position: line 12 dataDir=/opt/share/zk/apache-zookeeper-3.6.3-bin/data/snapshot # Open (remove the comments), keep the number of snapshots, and modify the position: line 25 autopurge.snapRetainCount=10 # Enable (remove the comments) to automatically clean up the transaction log and snapshot files. The unit is hour. The default is 0, which means that the automatic cleaning function is not enabled. Modified position: line 28 autopurge.purgeInterval=24
The following is the new configuration. Add the following configuration at the end of the file
#Transaction log storage directory dataLogDir=/opt/share/zk/apache-zookeeper-3.6.3-bin/data/log #View service information in HTTP mode admin.serverPort=8081 #Open audit log audit.enable=true
2181 open to agent
The open port command is as follows:
# Open 2181 port firewall-cmd --zone=public --add-port=2181/tcp --permanent # Reload firewall rules firewall-cmd --reload
-
Enter / opt/share/zk/apache-zookeeper-3.6.3-bin/bin directory and start ZooKeeper
cd ../bin ./zkServer.sh start
If the following information is printed, the startup is successful
ZooKeeper JMX enabled by default
Using config: /opt/share/zk/apache-zookeeper-3.6.3-bin/bin/.../conf/zoo.cfg
Starting zookeeper ... STARTED -
View the process according to the port. The command is as follows:
netstat -anp | grep 2181
Print the following information
tcp6 0 0 :::2181 ::😗 LISTEN 3538/java
-
If you need to shut down, you can use the following command:
./zkServer.sh stop
The normal printing information is as follows:
ZooKeeper JMX enabled by default
Using config: /opt/share/zk/apache-zookeeper-3.6.3-bin/bin/.../conf/zoo.cfg
Stopping zookeeper ... STOPPED
ZooKeeper cluster installation
The installation directory takes / opt/share/zk as an example
ZooKeeper cluster recommends installing an odd number of machines. Now take building three machines as an example.
The three machines are as follows:
- 192.168.64.136
- 192.168.64.137
- 192.168.64.138
Take 192.168.64.136 machine as an example, the installation steps are as follows:
-
Create a new directory / opt/share/zk. The command is as follows:
mkdir -p /opt/share/zk
-
Enter / opt/share/zk directory and upload jdk-8u301-linux-x64 tar. GZ file
-
Unzip jdk-8u301-linux-x64.0 tar. GZ file, the command is as follows:
tar -zxvf jdk-8u301-linux-x64.tar.gz
-
Modify the java execution permission. The command is as follows:
chmod u+x jdk1.8.0_301/bin/java*
-
Upload apache-zookeeper-3.6.3-bin.com tar. GZ file
-
Unzip apache-zookeeper-3.6.3-bin tar. GZ file, the command is as follows:
tar -zxvf apache-zookeeper-3.6.3-bin.tar.gz
-
/Create a new subdirectory snapshot and log under opt/share/zk/apache-zookeeper-3.6.3-bin/data /
mkdir -p /opt/share/zk/apache-zookeeper-3.6.3-bin/data/snapshot mkdir -p /opt/share/zk/apache-zookeeper-3.6.3-bin/data/log
-
Enter / opt/share/zk/apache-zookeeper-3.6.3-bin/data/snapshot directory and create myid file. The command is as follows:
cd /opt/share/zk/apache-zookeeper-3.6.3-bin/data/snapshot echo "1" > myid
Create myid files in / opt/share/zk/apache-zookeeper-3.6.3-bin/data/snapshot directory of each machine in turn:
192.168.64.137 the content of the machine myid file is 2, and the command is as follows:
echo "2" > myid
192.168.64.138 the content of the machine myid file is 3, and the command is as follows:
echo "3" > myid
-
Enter the / opt/share/zk/apache-zookeeper-3.6.3-bin/conf directory and create a new Java Env file, the command is as follows:
touch java.env vi java.env
java.env file contents are as follows:
#!/bin/sh #Configure JDK directory export JAVA_HOME=/opt/share/zk/jdk1.8.0_301 #Configure JVM parameters export JVMFLAGS="-Xms1024m -Xmx1024m $JVMFLAGS"
Modify Java Env file execution permission
chmod u+x java.env
-
Copy profile_ sample. CFG is zoo CFG, the command is as follows:
cd apache-zookeeper-3.6.3-bin/conf cp zoo_sample.cfg zoo.cfg
-
Modify zoo CFG configuration file, the command is as follows:
vi zoo.cfg
The following is the modified configuration
#Communication port with client (agent) clientPort=2181 #Snapshot storage directory. Modified position: line 12 dataDir=/opt/share/zk/apache-zookeeper-3.6.3-bin/data/snapshot # Open (remove the comments), keep the number of snapshots, and modify the position: line 25 autopurge.snapRetainCount=10 # Enable (remove the comments) to automatically clean up the transaction log and snapshot files. The unit is hour. The default is 0, which means that the automatic cleaning function is not enabled. Modified position: line 28 autopurge.purgeInterval=24
The following is the new configuration. Add the following configuration at the end of the file
#Transaction log storage directory dataLogDir=/opt/share/zk/apache-zookeeper-3.6.3-bin/data/log #View service information in HTTP mode admin.serverPort=8081 #Open audit log audit.enable=true #Cluster node configuration server.1=192.168.64.136:2888:3888 server.2=192.168.64.137:2888:3888 server.3=192.168.64.138:2888:3888
Note that ports 2888 and 3888 need to be interconnected between the three machines to ensure that port 2181 is open to AGENT
The open port command is as follows:
# Open 2181 port firewall-cmd --zone=public --add-port=2181/tcp --permanent firewall-cmd --zone=public --add-port=2888/tcp --permanent firewall-cmd --zone=public --add-port=3888/tcp --permanent # Reload firewall rules firewall-cmd --reload
Modify each machine zoo CFG configuration file, the content is the same.
The configuration format is described as follows:
server.A=B:C:D
A: The serial number of ZooKeeper server, which should be consistent with the myid content of ZooKeeper
B: IP address or domain name of the server
C: The communication port between the server Follower and the Leader server in the cluster
D: Leader election port.
-
Install and configure 192.168.64.137 and 192.168.64.138 machines according to steps 1-11 above. Note that in step 8, the myid value is modified
-
Enter the / opt/share/zk/apache-zookeeper-3.6.3-bin/bin directory of each machine in turn and start ZooKeeper
cd /opt/share/zk/apache-zookeeper-3.6.3-bin/bin ./zkServer.sh start
If the following information is printed, the startup is successful
ZooKeeper JMX enabled by default
Using config: /opt/share/zk/apache-zookeeper-3.6.3-bin/bin/.../conf/zoo.cfg
Starting zookeeper ... STARTED -
Verify the cluster status. The command is as follows:
./zkServer.sh status
If the following information is printed, it indicates that the node is a Leader
ZooKeeper JMX enabled by default
Using config: /opt/share/zk/apache-zookeeper-3.6.3-bin/bin/.../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leaderIf the following information is printed, it indicates that the node is a follower
ZooKeeper JMX enabled by default
Using config: /opt/share/zk/apache-zookeeper-3.6.3-bin/bin/.../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower -
View the process according to the port. The command is as follows:
netstat -anp | grep 2181
Print the following information
tcp6 0 0 :::2181 ::😗 LISTEN 3538/java
-
If you need to shut down, you can use the following command:
./zkServer.sh stop
The normal printing information is as follows:
ZooKeeper JMX enabled by default
Using config: /opt/share/zk/apache-zookeeper-3.6.3-bin/bin/.../conf/zoo.cfg
Stopping zookeeper ... STOPPED