How to install Zookeeper
Download Zookeeper
Go to http://www.apache.org/dyn/closer.cgi/zookeeper/ and select a mirror. Go to stable folder and download the tar.gz file.
Here I am using wget to download the tar.gz file
wget http://apache.cs.utah.edu/zookeeper/stable/zookeeper-3.4.8.tar.gz
tar -xvzf zookeeper-3.4.8.tar.gz
ln -s zookeeper-3.4.8 zk
export ZK_HOME=/scratch/softwares/zk
Create config file:
Zookeeper ships a sample config file. Make a copy of the file and edit dataDir parameters.
cd zk/confcp zoo_sample.cfg zoo.cfg
By default dataDir points to dataDir=/tmp/zookeeper, change it to something like /scratch/softwares/zookeeper
eg:
dataDir=/scratch/softwares/zookeeper
Install JDK
Make sure java is installed and JAVA_HOME env variable is set.
java -version
echo $JAVA_HOME
/scratch//softwares/jdk1.7.0_04
Add zookeeper bin folder to PATH, so that zookeeper commands can be executed without navigating to the zk/bin folder.
cd ../bin
export PATH=$PATH:/scratch/softwares/zk/bin
Start zookeeper
zkServer.sh startZooKeeper JMX enabled by default
Using config: /scratch//softwares/zk/conf/zoo.cfg
Starting zookeeper ... STARTED
Stop Zookeeper
zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /scratch//softwares/zk/conf/zoo.cfg
Stopping zookeeper ... STOPPED
zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /scratch//softwares/zk/conf/zoo.cfg
Mode: standalone
By default zookeeper is started in background. To start zookeeper in fore-ground use below command:
zkServer.sh start-foreground
This options helps to see what is going on with the server.
Start Zookeeper Client
export PATH=$PATH:/scratch/softwares/zk/bin
bash-3.2$ zkCli.sh
Connecting to localhost:2181
2016-06-18 23:06:25,928 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.8--1, built on 02/06/2016 03:18 GMT
2016-06-18 23:06:25,931
....
2016-06-18 23:06:25,935 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@291fffa9
2016-06-18 23:06:25,964 [myid:] - INFO [main-SendThread(localhost.localdomain:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost.localdomain/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
Welcome to ZooKeeper!
2016-06-18 23:06:25,969 [myid:] - INFO [main-SendThread(localhost.localdomain:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost.localdomain/127.0.0.1:2181, initiating session
JLine support is enabled
2016-06-18 23:06:26,012 [myid:] - INFO [main-SendThread(localhost.localdomain:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost.localdomain/127.0.0.1:2181, sessionid = 0x1556495578b0000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0]
create /testnode ""
Created /testnode
[zk: localhost:2181(CONNECTED) 5] ls /
[testnode, zookeeper]
[zk: localhost:2181(CONNECTED) 6] stat /testnode
cZxid = 0x2
ctime = Sat Jun 18 23:09:11 IST 2016
mZxid = 0x2
mtime = Sat Jun 18 23:09:11 IST 2016
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 0