Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Pre-requisites

  • OpenJDK8
  • Zookeeper

Install OpenJDK

$ sudo apt-get install openjdk-8-jdk 

...

Edit the /etc/hosts file across all the nodes and add the ipaddress and hostname (nodenames). If the hostnames are not right, change them in /etc/hosts file



192.168.1.102 node1
192.168.1.103 node2
192.168.1.105 node3

...

Edit zoo.cfg and the below


$ vim /home/zookeeper/zookeeper-3.4.13/conf/vi zoo.cfg


dataDir=/var/lib/zookeeper
server.1=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888


Now, do the below changes in log4.properties file as follows.

$ vim /home/zookeeper/zookeeper-3.4.13/conf/vi log4j.properties


zookeeper.log.dir=/var/log/zookeeper 
zookeeper.tracelog.dir=/var/log/zookeeper 
log4j.rootLogger=INFO, CONSOLE, ROLLINGFILE

...

$ /home/zookeeper/zookeeper-3.4.1312/bin/zkServer.sh start


Zookeeper Service Start on all the Nodes.

ZooKeeper JMX enabled by default
Using config: /home/ganesh/zookeeper-3.4.12/bin/../conf/zoo.

...

cfg
Starting zookeeper ... STARTED



The log file will be created in /var/log/zookeeper of zookeeper named zookeeper.log, tail the file to see logs for any errors.

$ tail -f /var/log/zookeeper/zookeeper.log


Verify the Zookeeper Cluster and Ensemble

...

$ /home/zookeeper/zookeeper-3.4.13/bin/zkServer.sh status


Zookeeper Service Status Check.Zookeeper Service Status Check.Image Removed

In Zookeeper ensemble If you have 3 nodes, out of them, one will be in leader mode and other two will be in follower mode. You can check the status by running the following commands. If you have just one then it will be standalone.

With three nodes:

node1

ZooKeeper JMX enabled by default
Using config: /home/zookeeper/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: leader

node2

ZooKeeper JMX enabled by default
Using config: /home/zookeeper/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: follower

node3

ZooKeeper JMX enabled by default
Using config: /home/zookeeper/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: follower


standalone

ZooKeeper JMX enabled by default
Using config: /home/zookeeper/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: standalone


$ echo stat | nc node1 2181

...

Lists brief details for the server and connected clients.

Lists brief details for the server and connected clientsImage Modified


$ echo mntr | nc node1 2181

...

Zookeeper list of variables for cluster health monitoring.

Zookeeper list of variables for cluster health monitoringImage Modified


$ echo srvr | nc localhost 2181

...

Lists full details for the Zookeeper server.

Lists full details for the Zookeeper server.Image Modified


If you need to check and see the znode, you can connect by using the below command on any of the zookeeper node:

$ /home/zookeeper/zookeeper-3.4.1312/bin/zkCli.sh -server `hostname -f`:2181

...

Connect to Zookeeper data node and lists the contents.

Connect to Zookeeper data node and lists the contents.Image Modified


ent:user.name=root
2019-02-18 02:26:36,822 [myid:] - INFO [main:Environment@100] - Client environm
ent:user.home=/root
2019-02-18 02:26:36,822 [myid:] - INFO [main:Environment@100] - Client environm
ent:user.dir=/home/ganesh
2019-02-18 02:26:36,823 [myid:] - INFO [main:ZooKeeper@441] - Initiating client
connection, connectString=:2181 sessionTimeout=30000 watcher=org.apache.zookeep
er.ZooKeeperMain$MyWatcher@4b9af9a9
Welcome to ZooKeeper!
2019-02-18 02:26:36,846 [myid:] - INFO [main-SendThread(localhost:2181):ClientC
nxn$SendThread@1028] - Opening socket connection to server localhost/127.0.0.1:2
181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2019-02-18 02:26:36,927 [myid:] - INFO [main-SendThread(localhost:2181):ClientC
nxn$SendThread@878] - Socket connection established to localhost/127.0.0.1:2181,
initiating session
2019-02-18 02:26:36,948 [myid:] - INFO [main-SendThread(localhost:2181):ClientC
nxn$SendThread@1302] - Session establishment complete on server localhost/127.0.
0.1:2181, sessionid = 0x1000001cfe00002, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: :2181(CONNECTED) 0]