1. Environment Description

JDK     		1.8+ [do not install OpenJdk] ZooKeeper3.4.14
zkUI  			2.0.+
maven      	    3.5. +Copy the code

2. Source code installation

1.1. Obtain the tar package
http:/ / apache.spinellicreations.com/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
Copy the code
1.2. Upload the tar package, decompress it, and rename it
Gz name changed to mv zookeeper-3.4.14 Zookeeper # Delete the useless tar package rm -f zookeeper-3.4.14.tar.gzCopy the code
1.3. Modify ZooKeeper configurations
CFG/zookeeper/conf/CD zookeeper/conf/zoo_sample. CFG CFG Zookeeper configuration file cp zoo_sample. CFG zoo. CFG # Edit the configuration file vim zoo.cfgCopy the code

The default configuration is as follows:

Modify the configuration as follows:

# The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, / TMP here is just # example sakes. # dataDir=/data/zookeeper/ dataLogDir=/data/log/zookeeper/logs # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator  guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to Disable Auto Purge feature #autopurge.purgeInterval=1 # Purge server.0=172.31.3.86:2888:3888 Server. 1 = 172.31.3.87:2888-3888 for server 2 = 172.31.3.26:2888-3888Copy the code

Finally, use wq! Save the changes, stating:

DataDir and dataLogDir need to be created before startup

ClientPort Specifies the zooKeeper service port

0, server.1, and server.2 are the information of the three nodes in the ZK cluster, defined in the hostname:port1:port2 format, where port1 is the port used for communication between nodes and port2 is the port used for node election. Ensure that the two ports on the three hosts can communicate with each other.

1.4. Change the log configuration
By default, Zookeeper outputs console information to zookeeper.out in the boot path. You can perform the following operations to enable Zookeeper to output log files divided by size: Modify the conf/log4j.properties file, Logger =INFO, CONSOLE = zookeeper.root.logger=INFO, ROLLINGFILE: change the bin/ zkenv. sh file to ZOO_LOG4J_PROP="INFO,CONSOLE"Instead of ZOO_LOG4J_PROP ="INFO,ROLLINGFILE"

Copy the code

1.5. Do the same as above, and do the same on other machines
1.6. Create myID file
Mkdir -p /data/zookeeper/data CD /data/zookeeper/data touch myid The zoo. CFG configuration file server.x corresponds to the number of the cluster node configured above, for example, write the number 0 on the first node: Echo "0" > myid create a file named myid in the dataDir directory of the three hosts. The file contains the zK node numberCopy the code
1.7. Start the service in the background by default
Run the following commands to start the ZooKeeper service: CD /data/zookeeper/bin./zkServer.sh startCopy the code

Return message:

1.8. View the cluster status

After the node is started, run the following commands to check the cluster status:

 ./zkServer.sh status
Copy the code

You can see that three stations have been elected:

ZkUI deployment documentation

1.The source code to install

1.1. Download the source code
# ZKUI2.0 making address: https://github.com/DeemOpen/zkuiCopy the code
1.2. Maven packaging
Skip =true MVN install-dmaven.test.skip =trueCopy the code

Zkui-2.0-snapshot-jar-with-dependencies. Jar = zkui-2.0-snapshot-jar-with-dependencies. Jar = zkui-2.0-snapshot-jar-with-dependencies

**1.3. ** Upload the JAR package and configuration file CFG to the server

The configuration file is located in the root directory of the project file, as shown below:

Put the jar package above with CFG file in /data/zkui directory mkdir /data/zkuiCopy the code

2.Modify the configuration

Modify the conf. CFG configuration file to separate zooKeeper addresses and multiple ZK instances with commas. Such as:172.313.86:2181.172.313.87:2181.172.313.26:2181

Copy the code

3.Start the service

Insert the zkui_start.sh startup script:

#! /etc/profile ROOT_PATH=$(dirname $(readlink -f $0)) function getJar() {for item in $(ls) $ROOT_PATH); do fileName=$item if [ ! -d $fileName ]; then if [ ${fileName##*.} = jar ]; Then APP_NAME=$fileName return fi fi done echo "Exit 1} getJar JAVA_OPTS="-server \ -xMS1024m \ -Xmx1024m \ -Xmn512m \ -Xss512m \ -XX:MaxMetaspaceSize=512m \ -XX:MaxNewSize=512m \ -XX:MetaspaceSize=512m \ -XX:SurvivorRatio=9 \ -XX:+UseConcMarkSweepGC \ -XX:ParallelCMSThreads=4 \ -XX:MaxTenuringThreshold=4 \ -XX:+UseCMSCompactAtFullCollection \ -XX:CMSFullGCsBeforeCompaction=4 \ -XX:+CMSParallelRemarkEnabled \ -XX:+CMSScavengeBeforeRemark \ -XX:+CMSClassUnloadingEnabled \ -XX:+UseCMSInitiatingOccupancyOnly \ -XX:CMSInitiatingOccupancyFraction=80 \ -XX:CMSInitiatingPermOccupancyFraction=92 \ -XX:SoftRefLRUPolicyMSPerMB=0 \ -xx :+UseFastAccessorMethods \ -xx :+AggressiveOpts \ -xx: -usebiasedLocking \ -xx :+DisableExplicitGC" # Usage () {echo "usage: Sh script execution. Sh [start | stop | restart | status] "exit 1} # to check whether the program is running is_exist () {pid = $(ps - ef | grep $APP_NAME | grep -v grep | Awk '{print $2}') # if [-z "${pid}"]; Then return 1 else return 0 start() {is_exist if [$? -eq "0"]; then echo "${APP_NAME} is already running. pid=${pid} ." else nohup java ${JAVA_OPTS} -jar ${ROOT_PATH}/${APP_NAME} >/dev/null 2>&1 & #nohup Java $JAVA_OPTS -jar $APP_NAME >/ WWW /log.txt 2>&1 & fi} # stop() {is_exist if [$? -eq "0"]; Then kill -9 $PID else echo "${APP_NAME} is not running" fi} # is_exist if [$? -eq "0"]; Then echo "${APP_NAME} is running. Pid is ${Pid}" else echo "${APP_NAME} is NOT running." fi} # restart restart() {stop Case "$1" in "start") start;; "stop") stop ;; "status") status ;; "restart") restart ;; *) usage ;; esacCopy the code

Start with a script:

sh zkui_start.sh start
Copy the code

Stop command Reference:

sh zkui_start.sh stop
Copy the code

Check whether the startup is successful:

netstat -antp |grep 9090
Copy the code

4.Interface related

Access after startup:

http://192.168.2.128:9090/

Enter the account secret in our configuration. The default is:

admin | manager
Copy the code

View node information:

View cluster status:

5.Configure automatic startup upon startup

1.1. Create the zookeeper.service configuration file in the /lib/systemd/system/ directory
vim zookeeper.service 
Copy the code

Zookeeper. service add:

[Unit]

Description=Zookeeper service

After=network.target



[Service]

Type=simple

Environment="PATH = / usr/local/sbin, / usr/local/bin: / usr/sbin, / usr/bin, / sbin, / bin: / opt/Java/JDK - 11.0.1 / bin"User = root Group = root ExecStart = / opt/kafka kafka_2. 11 -2.1. 0 / bin/zookeeper - server - start. Sh/opt/kafka kafka_2. 11 -2.1. 0 / config/zookeeper. Properties ExecStop = / opt/kafka kafka_2. 11 -2.1.0/bin/zookeeper-server-stop.sh

Restart=on-failure



[Install]

WantedBy=multi-user.target

Copy the code

Note: The above files are modified according to your JDK and kafka installation directory.

1.2. Refresh the configuration
 systemctl daemon-reload
Copy the code
1.3 Adding the ZooKeeper service to the system
systemctl enable zookeeper
Copy the code
1.4. Run the systemctl command to start, stop, and restart the ZooKeeper service
systemctl start/stop/restart  zookeeper 
Copy the code
1.5. View the status
systemctl status zookeeper
Copy the code