Zookeeper - Installation



Before installing ZooKeeper, make sure your system is running on any of the following operating systems −

  • Any of Linux OS − Supports development and deployment. It is preferred for demo applications.

  • Windows OS − Supports only development.

  • Mac OS − Supports only development.

ZooKeeper server is created in Java and it runs on JVM. You need to use JDK 6 or greater.

Now, follow the steps given below to install ZooKeeper framework on your machine.

Step 1: Verifying Java Installation

We believe you already have a Java environment installed on your system. Just verify it using the following command.

$ java -version

If you have Java installed on your machine, then you could see the version of installed Java. Otherwise, follow the simple steps given below to install the latest version of Java.

Step 1.1: Download JDK

Download the latest version of JDK by visiting the following link and download the latest version. Java

The latest version (while writing this tutorial) is JDK 8u 60 and the file is “jdk-8u60-linuxx64.tar.gz”. Please download the file on your machine.

Step 1.2: Extract the files

Generally, files are downloaded to the downloads folder. Verify it and extract the tar setup using the following commands.

$ cd /go/to/download/path
$ tar -zxf jdk-8u60-linux-x64.gz

Step 1.3: Move to opt directory

To make Java available to all users, move the extracted java content to “/usr/local/java” folder.

$ su 
password: (type password of root user)
$ mkdir /opt/jdk
$ mv jdk-1.8.0_60 /opt/jdk/

Step 1.4: Set path

To set path and JAVA_HOME variables, add the following commands to ~/.bashrc file.

export JAVA_HOME = /usr/jdk/jdk-1.8.0_60
export PATH=$PATH:$JAVA_HOME/bin

Now, apply all the changes into the current running system.

$ source ~/.bashrc

Step 1.5: Java alternatives

Use the following command to change Java alternatives.

update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_60/bin/java 100

Step 1.6

Verify the Java installation using the verification command (java -version) explained in Step 1.

Step 2: ZooKeeper Framework Installation

Step 2.1: Download ZooKeeper

To install ZooKeeper framework on your machine, visit the following link and download the latest version of ZooKeeper. http://zookeeper.apache.org/releases.html

As of now, the latest version of ZooKeeper is 3.4.6 (ZooKeeper-3.4.6.tar.gz).

Step 2.2: Extract the tar file

Extract the tar file using the following commands −

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

Step 2.3: Create configuration file

Open the configuration file named conf/zoo.cfg using the command vi conf/zoo.cfg and all the following parameters to set as starting point.

$ vi conf/zoo.cfg

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

Once the configuration file has been saved successfully, return to the terminal again. You can now start the zookeeper server.

Step 2.4: Start ZooKeeper server

Execute the following command −

$ 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.6/bin/../conf/zoo.cfg
$ Starting zookeeper ... STARTED

Step 2.5: 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]

Stop ZooKeeper Server

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

$ bin/zkServer.sh stop
Advertisements