Zookeeper [download and installation, basic use]

Table of contents

1. What is zookeeper

2. Download and install zookeeper

3. Zookeeper test


1. What is zookeeper

Zookeeper is actually developed by Yahoo, a framework for distributed consistency processing. It was originally developed as a by-product of Hadoop.
Due to the difficulty of consistency processing in distributed systems, other distributed systems do not need to work hard to reinvent the wheel, so zookeeper is widely used in subsequent distributed systems, so that zookeeper has become the basic component of various distributed systems. The importance of status can be imagined. The famous hadoop, kafka, and dubbo are all built based on zookeeper.

2. Download and install zookeeper

Download address: https://archive.apache.org/dist/zookeeper/ (the zookeeper in this case is 3.6.2)

 2.1 Upload zookeeper installation package to linux

rz apache-zookeeper-3.6.2-bin.tar.gz

 2.2 Unzip zookeeper to /usr/local

tar zxvf apache-zookeeper-3.6.2-bin.tar.gz -C /usr/local/

 2.3 copy zookeeper

mv /usr/local/apache-zookeeper-3.6.2-bin/ /usr/local/zookeeper

 2.4 Rename the zookeeper configuration file

cd /usr/local/zookeeper/
cd conf/
cp zoo_sample.cfg zoo.cfg

 2.5 Return to parent directory

cd ..

 2.6 Create logs and data directories

mkdir logs data

 2.7 Enter the conf/ directory

cd conf/

 2.8 Modify zoo.cfg configuration

vim zoo.cfg

 Add the following two lines of code to zoo.cfg:

#注释之前的dataDir即可复制
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/logs

  2.9 zookeeper self-start configuration

cd /usr/lib/systemd/system

  3.0 Write zookeeper.service file

  • Note! You need to modify the java environment variable address of the virtual machine (JAVA_HOME)
[Unit]
Description=zookeeper.service
After=network.target

[Service]
Type=forking
Environment=ZOO_LOG_DIR=/usr/local/zookeeper/logs/
Environment=JAVA_HOME=/usr/local/jdk1.8.0_151
#Environment=PATH=/usr/local/jdk/bin:/usr/local/jdk/jre/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin
ExecStart=/usr/local/zookeeper/bin/zkServer.sh start
ExecStop=/usr/local/zookeeper/bin/zkServer.sh stop
ExecReload=/usr/local/zookeeper/bin/zkServer.sh restart
PIDFile=/usr/local/zookeeper/data/zookeeper_server.pid
User=root

[Install]
WantedBy=multi-user.target

 3.1 upload zookeeper.service file

rz zookeeper.service
  •   Note: Upload the zookeeper.service in the data to the /usr/lib/systemd/system directory 

 3.2 Set the boot to start automatically

 systemctl daemon-reload
 systemctl enable zookeeper
 systemctl start zookeeper

 3.3 Open the port 

firewall-cmd --zone=public --add-port=2181/tcp --permanent

 3.4 Restart the firewall

firewall-cmd --reload

  3.5 View all open ports

firewall-cmd --list-port

3. Zookeeper test

 3.1 Enter the startup directory 

cd /usr/local/zookeeper/bin/

 3.2 start

./zkCli.sh

  • Add
create /jmh ok

  • Inquire 
get /jmh

  •  Revise
set /jmh no 

  • delete
delete /jmh

Guess you like

Origin blog.csdn.net/m0_63300795/article/details/128732031