قالب وردپرس درنا توس
Home / How To / How to install Apache ZooKeeper on Debian 10

How to install Apache ZooKeeper on Debian 10



Apache Zookeeper is a free and open source service for distributed systems that helps you manage a large set of hosts. It is a centralized service used to maintain configuration information, naming and group services. It is written in Java and allows developers to focus on building software features without worrying about the distributed nature of the application. Apache ZooKeeper is most often used in "reading-dominant" workloads where readings are much more common than writing. It comes with a rich set of features including, synchronization, ordered messages, serialization, reliability, atomicity, fast processing and many more. It has a lock and sync mechanism to help you automatically fail recovery while connecting other distributed applications. The Zookeeper project is one of the most successful projects of the Apache Foundation. Many companies have adopted Zookeeper to create highly accessible distributed systems on a large scale.

In this tutorial, we will show you how to set up a single node Apache Zookeeper cluster on Debian 1

0 server.

Prerequisites

  • A server runs Debian 10 with 2 GB of RAM.
  • A root password is configured on your server.

Getting Started

Before you begin, it is recommended that you update your server with the latest version. You can update it with the following command:

  apt-get update -y 
apt-get upgrade -y

Once your server is updated, restart it to implement the changes.

Installing Java [19659007] Apache Zookeeper is written in the Java language. So you need to install Java in your system. By default, the latest version of Java is available in the standard Debian 10 repository. You can install it by running the following command:

  apt-get install default-jdk -y 

After installing Java, verify the installed version of Java with the following command:

  java - version 

You should get the following output:

  openjdk 11.0.5 2019-10-15
OpenJDK Runtime Environment (build 11.0.5 + 10-post-Debian-1deb10u1)
OpenJDK 64-bit server VM (build 11.0.5 + 10-post-Debian-1deb10u1, mixed mode, sharing)

When you're done, you can continue to create a Zookeeper system user.

Creating a Zookeeper System User

It is a good idea to create a dedicated user to run the Zookeeper service. This will improve your safety and manageability.

First, run the following command to create a zookeeper user with the home directory:

  useradd zookeeper -m 

Then set the default zookeeper user shell with the following command:

  usermod - shell / bin / bash zookeeper 

Then set a zookeeper user password with the following command:

  passwd zookeeper 

Then add the zookeeper user to the sudo group: [19659008] usermod -aG sudo zookeeper

At this point, you created and configured the Zookeeper user. You can now continue to download Zookeeper.

Download Zookeeper

First you need to download the latest version of Apache Zookeeper from its official website. At the time of writing this article, the latest version of Apache Zookeeper is 3.5.6.

To download it, change directory to / opt and run following command:

  cd / opt 
wget https: //archive.apache.org/dist/zookeeper/stable/apache-zookeeper-3.5 .6-bin.tar.gz

When the download is complete, extract the downloaded file with the following command:

  tar -xvzf apache-zookeeper-3.5.6-bin.tar.gz 

Then rename on the zookeeper extracted directory and give the correct permissions:

  etc. apache-zookeeper-3.5.6-bin zookeeper 
chown - R zookeeper: zookeeper / opt / zookeeper

Then you need to create a Zookeeper data directory for to store all configuration and state data. You can create the local file system or remote file system you need.

You can create a data directory with the following command:

  mkdir -p / data / zookeeper 

Then you change the ownership of the data directory to zookeeper users:

  chown -R zookeeper: zookeeper / data / zookeeper [19659009] At this point you have downloaded the Zookeeper and created a data directory for it. You can now continue to configure Zookeeper. 

Configure Zookeeper

Zookeeper all configuration files are in the / opt / zookeeper / conf / directory. You can create a Zookeeper configuration file inside / opt / zookeeper / conf / directory with the following command:

  nano /opt/zookeeper/conf/zoo.cfgebrit19659009??Add the following lines: 

  tickTime = 2500
DATADIR = / data / zookeeper
Client = 2181
maxClientCnxns = 80

Save and close the file when you are done.

Where:

  • tickTime : This option specifies the length of a tick in milliseconds.
  • dataDir : Enter the data directory to store Zookeeper data.
  • clientPort : Specify the port used to listen for client connections.
  • maxClientCnxns : Used to limit the maximum number of client connections.

Note : The above parameters are for development and testing. You can change them according to your needs.

At this point, you have configured Zookeeper. You may now be ready to start the Zookeeper server.

Starting and Testing Zookeeper Server

You can start the Zookeeper server with the following command:

  /opt/zookeeper/bin/zkServer.sh start 

You should get the following output:

  / usr / bin / java
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... START

Then you can connect to the Zookeeper server on port 2181 using the following command:

  /opt/zookeeper/bin/zkCli.sh server 127.0.0.1:2181 Chapter19659009 ?? When connected you should see the following output : 

  [zk: 127.0.0.1:2181(CONNECTED) 0]

Then run the help command to get a list of commands that you can execute from the client.

  [zk: 127.0.0.1:2181(CONNECTED) 0] help 

You should see the following output:

  ZooKeeper server host: port cmd args
addauth schema authorization
close
config [-c] [-w] [-s]
	  connect host: port
create [-s] [-e] [-c] [-t ttl]   path [data] [acl]
	  delete [-v version] path
part road all the way
delquota [-n|-b] road
get [-s] [-w]   way
getAcl [-s] path
history
list quota path
ls [-s] [-w]   [-R] road
ls2 road [watch]
push clock on | of
stop
reconfig [-s] [-v version] [[-file path]   | [-members serverID=host:port1:port2;port3[,...] *]] | [-add serverId=host:port1:port2;port3[,...]] * [-remove serverId[,...] *]
redo cmdno
removewatches path [-c|-d|-a] [-l]
	  rmr path
set [-s] [-v version]   path data
setAcl [-s] [-v version]   [-R] path acl
setquota -n | -b election route
state [-w] road
synkroniseringsväg

After testing, exit from the client session with the end command:

  [zk: 127.0.0.1:2181(CONNECTED) 0] end 

You can now stop the Zookeeper service with the following command:

  / opt / zookeeper / bin / zkServer. sh stop 

You should see the following command:

  / usr / bin / java
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Stops the keeper ... STOPPED

At this point, you have successfully started and tested the Zookeeper server.

Creating a Systemd Service File for Zookeeper

Next, you must create a Systemd service file to manage the Zookeeper service using systemd. [19659002] You can create it with the following command:

  nano /etc/systemd/system/zookeeper.service tu 19199009009 Add the following lines: 

  [Unit]
Description = Zookeeper Daemon
Documentation = http: //zookeeper.apache.org
Requires = network.target
After = network.target

[Service]
Type = forking
WorkingDirectory = / opt / zookeeper
User = zookeeper
Groups = zookeeper
ExecStart = / opt / zookeeper / bin / zkServer.sh start /opt/zookeeper/conf/zoo.cfg
ExecStop = / opt / zookeeper / bin / zkServer.sh stop /opt/zookeeper/conf/zoo.cfg
ExecReload = / opt / zookeeper / bin / zkServer.sh restart /opt/zookeeper/conf/zoo.cfg
TimeoutSec = 30
Restart = on-error

[Install]
WantedBy = default.target

Save and close the file when you are done. Then reload the system daemon with the following command:

  systemctl daemon-reload 

Then start the Zookeeper service and enable it after system startup with the following command:

  systemctl start zookeeper 
systemctl enable zookeeper

now verify Zookeeper status with the following command:

  systemctl status zookeeper 

You should see the following output:

? zookeeper.service - Zookeeper Daemon
Loaded: loaded (/etc/systemd/system/zookeeper.service; disabled; vendor setting: enabled)
Active: active (running) since Sun 2019-12-29 15:12:39 UTC; 8 minutes ago
Document: http://zookeeper.apache.org
Process: 9229 ExecStart = / opt / zookeeper / bin / zkServer.sh start /opt/zookeeper/conf/zoo.cfg (code = terminated, status = 0 / SUCCESS)
Main PID: 9245 (java)
Details: 29 (limit: 2359)
Memory: 49.7M
CGroup: /system.slice/zookeeper.service
?? 9245 java -Dzookeeper.log.dir = / opt / zookeeper / bin /../ loggar -Dzookeeper.log.file = zookeeper-zookeeper-server-debian10.log -Dzookeeper.

Dec 29 15:12:38 debian10 systemd [1]: Start Zookeeper Daemon ...
Dec 29 15:12:38 debian10 zkServer.sh [9229]: / usr / bin / java
Dec 29 15:12:38 debian10 zkServer.sh [9229]: ZooKeeper JMX enabled by default
Dec 29 15:12:38 debian10 zkServer.sh [9229]: Using config: /opt/zookeeper/conf/zoo.cfg
Dec 29 15:12:39 debian10 zkServer.sh [9229]: Start zookeeper ... START
Dec 29 15:12:39 debian10 systemd [1]: Started Zookeeper Daemon.

Now you can easily manage the Zookeeper service with systemd.

Conclusion

Congratulations! you have installed and configured a single node Zookeeper cluster on the Debian 10 server. This setting is very useful for development and testing environments. I hope you now have enough knowledge to set up a single node Zookeeper cluster. Feel free to ask me if you have any questions.


Source link