How To Install Apache ZooKeeper on CentOS 7

Zookeeper is brief is a distributed state manager that may be employed by many clusters to keep state across its clusters. Like HBase can utilize Zookeeper to keep state across its own set of clusters without having to have cluster country within it.

Table of Contents

Step 1. First let’s start by ensuring your system is up-to-date.

Step 2. Installing Java.

Step 3. Install Apache ZooKeeper.

 

 

Prerequisites

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step install Apache ZooKeeper on CentOS 7 server.
Install Apache ZooKeeper

Step 1. First let’s start by ensuring your system is up-to-date.

yum clean all
yum -y update

Step 2. Installing Java.

At the time of writing this tutorial, the latest Java JDK version was JDK 8u45. First, let us download the latest Java SE Development Kit 8 release from its official download page or use following commands to download from shell:

cd /opt/
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45-linux-x64.tar.gz"
tar xzf jdk-8u45-linux-x64.tar.gz

After extracting archive file use alternatives command to install it. alternatives command is available in chkconfig package:

cd /opt/jdk1.8.0_45/
alternatives --install /usr/bin/java java /opt/jdk1.8.0_45/bin/java 2
alternatives --config java
There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /opt/jdk1.7.0_71/bin/java
 + 2           /opt/jdk1.8.0_25/bin/java
   3           /opt/jdk1.8.0_45/bin/java

Enter to keep the current selection[+], or type selection number: 3

At this point JAVA 8 (JDK 8u45) has been successfully installed on your system. We also recommend to setup javac and jar commands path using alternatives:

alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_45/bin/jar 2
alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_45/bin/javac 2
alternatives --set jar /opt/jdk1.8.0_45/bin/jar
alternatives --set javac /opt/jdk1.8.0_45/bin/javac

Checking Installed java version:

[email protected] ~# java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

We can easily set the environment variables using the export command as shown below:

Setup JAVA_HOME Variable:

export JAVA_HOME=/opt/jdk1.8.0_45

Setup JRE_HOME Variable:

export JRE_HOME=/opt/jdk1.8.0_45/jre

Setup PATH Variable:

export PATH=$PATH:/opt/jdk1.8.0_45/bin:/opt/jdk1.8.0_45/jre/bin

Step 3. Install Apache ZooKeeper.

First, install ZooKeeper framework on your machine, visit the following link and download the latest version of ZooKeeper:

cd opt/
tar -zxf zookeeper-3.4.11.tar.gz
cd zookeeper-3.4.6
mkdir data

Next, Open the configuration file named conf/zoo.cfg and all the following parameters to set as starting point:

### nano conf/zoo.cfg

tickTime = 2000
dataDir = /path/to/zookeeper/data
clientPort = 2181
initLimit = 5
syncLimit = 2

Then, start ZooKeeper server:

bin/zkServer.sh start

After executing this command, you will get a response as follows:

JMX enabled by default
Using config: /Users/../zookeeper-3.4.11/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

Next step, Start CLI type the following command:

bin/zkCli.sh

After typing the above command, you will be connected to the ZooKeeper server and you should get the following response:

Connecting to localhost:2181
................
................
................
Welcome to ZooKeeper!
................
................
WATCHER::
WatchedEvent state:SyncConnected type: None path:null
[zk: localhost:2181(CONNECTED) 0]

After connecting the server and performing all the operations, you can stop the zookeeper server by using the following command:

bin/zkServer.sh stop

Congratulation’s! You have successfully installed Apache ZooKeeper on CentOS 7. Thanks for using this tutorial for installing Apache ZooKeeper on CentOS 7 systems. For additional help or useful information, we recommend you to check the official Apache ZooKeeper web site.

Leave a Reply