Apache ZooKeeper Cluster & (Reverse Engineer source code) on Ubuntu 18.04 LTS

Apache ZooKeeper Cluster & (Reverse Engineer source code) on Ubuntu 18.04 LTS

October 28, 2019 ( last updated : October 27, 2019 )
ZooKeeper ZooKeeper Cluster in-memory

https://github.com/gridgentoo/zookeeper-release


Abstract

Youtube channel (Reverse Engineer source code) ZooKeeper :: for Enterprise Architect's powerful code engineering features is the ability to Reverse Engineer source code into a UML model.(Reverse Engineer source code) ZooKeeper :

код hortonworks : : zookeeper-release-HDP-3.1.4.2-2-tag zookeeper-release-HDP-3.1.4.2-2-tag

(Reverse Engineer source code) ZooKeeper :: for Architect: (Reverse Engineer source code)zookeeper-release-HDP-3.1.4.2-2-tag

Requirements

Getting Started

First, you will need to update your system with the latest version. You can do this by running the following command:

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

Install Java

Zookeeper is written in Java. So, you will need to install Java to your system. By default, the latest version of Java is not available in the Ubuntu 18.04 default repository. So, add the Java repository with the following command:

add-apt-repository ppa:linuxuprising/java

Next, update the repository and install Java with the following command:

apt-get update -y
apt-get install oracle-java11-set-default

Once the Java has been installed, you can check the Java version with the following command:

java --version

You should see the following output:

java 11.0.2 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+7-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+7-LTS, mixed mode)

Once you have finished, you can proceed to the next step.

Create a ZooKeeper User

Next, you will need to create a zookeeper user to run zookeeper service.

First, create a zookeeper user with the following command:

useradd zookeeper -m
usermod --shell /bin/bash zookeeper

Next, set a password with the following command:

passwd zookeeper

Next, add the zookeeper user to the sudo group so it can run commands in a privileged mode:

usermod -aG sudo zookeeper

After creating user, you can procced to install ZooKeeper.

Install ZooKeeper

ZooKeeper stores all configuration and state data to disk. So, you will need to create a directory structure for ZooKeeper with the following command:

mkdir -p /data/zookeeper

Next, give proper ownership to the /data directory with the following command:

chown -R zookeeper:zookeeper /data/zookeeper

Next, change the directory to the /opt and download the latest version of ZooKeeper with the following command:

cd /opt
wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz

Next, extract the downloaded file with the following command:

tar -xvzf zookeeper-3.4.9.tar.gz

Next, rename the extracted binary with the following command:

mv zookeeper-3.4.9 zookeeper

Next, give ownership to the ZooKeeper user with the following command:

chown -R zookeeper:zookeeper /opt/zookeeper

Configure ZooKeeper

Next, you will need to create a configuration file for ZooKeeper. You can do it with the following command:

nano /opt/zookeeper/conf/zoo.cfg

Add the following lines:

tickTime=2500
dataDir=/data/zookeeper
clientPort=2181
maxClientCnxns=80

Save and close the file, when you are finished.

Next, start the ZooKeeper service with the following command:

cd /opt/zookeeper
bin/zkServer.sh start

You should see the following output:

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

You can connect to the local ZooKeeper server with the following command:

bin/zkCli.sh -server 127.0.0.1:2181

Once you have connected successfully, you should see the following output:

[zk: 127.0.0.1:2181(CONNECTED) 1] 

Now, type help on the prompt, you should see the a list of commands that you can execute from the client.

help
ZooKeeper -server host:port cmd args
	stat path [watch]
	set path data [version]
	ls path [watch]
	delquota [-n|-b] path
	ls2 path [watch]
	setAcl path acl
	setquota -n|-b val path
	history 
	redo cmdno
	printwatches on|off
	delete path [version]
	sync path
	listquota path
	rmr path
	get path [watch]
	create [-s] [-e] path data acl
	addauth scheme auth
	quit 
	getAcl path
	close 
	connect host:port

Now, type quit to exit from the connected session.

You can stop the ZooKeeper with the following command:

bin/zkServer.sh stop

You should see the following output:

ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED

Create a Systemd Service file for ZooKeeper

Next, you will need to create a systemd service file to manage ZooKeeper service. You can do it with the following command:

nano /etc/systemd/system/zookeeper.service

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
Group=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-failure

[Install]
WantedBy=default.target

Save and close the file, when you are finished.

Next, reload the systemd daemon, start the ZooKeeper service and enable it to start on boot time with the following command:

systemctl daemon-reload
systemctl start zookeeper
systemctl enable zookeeper

You can check the status of ZooKeeper service 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 preset: enabled)
   Active: active (running) since Wed 2019-03-06 15:03:01 UTC; 5s ago
     Docs: http://zookeeper.apache.org
  Process: 3909 ExecStart=/opt/zookeeper/bin/zkServer.sh start /opt/zookeeper/conf/zoo.cfg (code=exited, status=0/SUCCESS)
 Main PID: 3926 (java)
    Tasks: 17 (limit: 1113)
   CGroup: /system.slice/zookeeper.service
           ??3926 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /opt/zookeeper/bin/../build/classes:/opt/zookeeper/bin/..

Mar 06 15:03:00 ubuntu1804 systemd[1]: Starting Zookeeper Daemon...
Mar 06 15:03:00 ubuntu1804 zkServer.sh[3909]: ZooKeeper JMX enabled by default
Mar 06 15:03:00 ubuntu1804 zkServer.sh[3909]: Using config: /opt/zookeeper/conf/zoo.cfg
Mar 06 15:03:01 ubuntu1804 zkServer.sh[3909]: Starting zookeeper ... STARTED
Mar 06 15:03:01 ubuntu1804 systemd[1]: Started Zookeeper Daemon.

Congratulations! you have successfully installed and configured ZooKeeper single node cluster on Ubuntu 18.04 server. You can now deploy multi-node ZooKeeper cluster for production. Feel free to ask me if you have any questions.

Thanks for reading

Other resources

Originally published October 28, 2019
Latest update October 27, 2019

Related posts :