Showing posts with label zookeeperkafka. Show all posts
Showing posts with label zookeeperkafka. Show all posts

Friday, July 9, 2021

Enable Admin Server in Zookeeper

Admin Server


Zookeeper is proving embedded jetty container to provide HTTP interface to execute commands. From Zookeeper 3.5.0 onwards HTTP interface is available. We need to enabled the Admin server from zookeeper configuration.

 

Zookeeper is providing set of 4 letters commands to manage and see the information of the servers and these commands can be executed from telenet. The same commands we can also execute via HTTP interface when we enabled Admin server in Zookeeper.

 

Zookeeper Commands


 

conf

 

New in 3.3.0: Print details about serving configuration.

 

cons

 

New in 3.3.0: List full connection/session details for all clients connected to this server. Includes information on numbers of packets received/sent, session id, operation latencies, last operation performed, etc…

 

crst

 

New in 3.3.0: Reset connection/session statistics for all connections.

 

dump

 

Lists the outstanding sessions and ephemeral nodes. This only works on the leader.

 

envi

 

Print details about serving environment

 

ruok

 

Tests if server is running in a non-error state. The server will respond with imok if it is running. Otherwise, it will not respond at all.

 

A response of "imok" does not necessarily indicate that the server has joined the quorum, just that the server process is active and bound to the specified client port. Use "stat" for details on state wrt quorum and client connection information.

 

srst

 

Reset server statistics.

 

srvr

 

New in 3.3.0: Lists full details for the server.

 

stat

 

Lists brief details for the server and connected clients.

 

wchs

 

New in 3.3.0: Lists brief information on watches for the server.

 

wchc

 

New in 3.3.0: Lists detailed information on watches for the server, by session. This outputs a list of sessions(connections) with associated watches (paths). Note, depending on the number of watches this operation may be expensive (ie impact server performance), use it carefully.

 

wchp

 

New in 3.3.0: Lists detailed information on watches for the server, by path. This outputs a list of paths (znodes) with associated sessions. Note, depending on the number of watches this operation may be expensive (ie impact server performance), use it carefully.

 

mntr

 

New in 3.4.0: Outputs a list of variables that could be used for monitoring the health of the cluster.

 

 

Prerequisite


Setup a Zookeeper cluster

 

http://www.liferaysavvy.com/2021/07/setup-zookeeper-cluster.html

 

Configure Admin Server


We need to update following properties in “zoo.cfg” for each node in the cluster.


Zookeeper Node 1


 

admin.enableServer=true

admin.serverPort=9191

 

 

Zookeeper Node 2


 

admin.enableServer=true

admin.serverPort=9292

 

 

Zookeeper Node 3


 

admin.enableServer=true

admin.serverPort=9393

 

 

Restart All zookeeper nodes in the cluster and access following URLs to see the commands interface.

 

Zookeeper Node 1

 

 

http://localhost:9191/commands

 

 



Click on each hyper link to execute command and we can see JSON response.


Examples


To see the leader in the cluster


http://localhost:9191/commands/leader




 

Stats of the server


http://localhost:9191/commands/stats




Similarly, you can access server HTTP interface for other nodes from following URL’s

 

Zookeeper Node2




http://localhost:9292/commands


 

 

 

Zookeeper Node3


 

http://localhost:9393/commands

 

 


References


https://zookeeper.apache.org/doc/r3.5.1-alpha/zookeeperAdmin.html

 

 

Author

 

Thursday, July 8, 2021

Setup a Zookeeper Cluster

Apache Zookeeper is distributed coordination service to build distributed applications. Kafka uses the Zookeeper to manage cluster.


Kafka is included with Zookeeper and we can start as service however we can also install standalone zookeeper. This article demonstrates the setting up zookeeper cluster.

 

Prerequisite


Latest Zookeeper is required minimum JAVA version 1.8 and above (JAVA_HOME environment variable need setup in the system)

 

Need 7zip software to extract .tgz files in windows.

 

Software's and Tools


 

Windows 10

Java 1.8 or higher

Zookeeper 3.7.0

 

 

 

Download and Extract



Download latest zookeeper binary tar.gz from following apache zookeeper download page.

 

https://zookeeper.apache.org/releases.html

 

Direct link as follow

 

https://www.apache.org/dyn/closer.lua/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz

 

Extract downloaded “apache-zookeeper-3.7.0-bin.tar.gz” using 7z software in local drive. We are going to setup 3 node cluster so clone extracted directory 2 more times.

 



Name the directories as follows


 

zookeeper-node1

zookeeper-node2

zookeeper-node3

 

 

 



Configure Cluster


Zookeeper Node1


Step:1


Data Directory


Create data directory in “zookeeper-node1” and we will use this directory path in zookeeper configuration.


Example:


C:\\kafka-workspace\\zookeeper-node1\\data

 





 

 

Step:2


Create “myid” file


We need to create “myid” file in data directory and update file name with node number that is “1”.





Step:3


Zookeeper Configuration


Now have to update few zookeeper configuration properties. Go to zookeeper-node1 directory and rename “zoo_sample.cfg” to “zoo.cfg

 



 

 

Add/Update “zoo.cfg” file with following properties.

 

 

clientPort=2181

dataDir=C:\\kafka-workspace\\zookeeper-node1\\data

 

autopurge.snapRetainCount=3

autopurge.purgeInterval=24

 

server.1=localhost:2666:3666

server.2=localhost:2667:3667

server.3=localhost:2668:3668

 

tickTime=2000

initLimit=10

syncLimit=5

 

 

 

 

server.<myid>=<hostname>:<leaderport>:<electionport>

 

 

We are setting up 3 node cluster so we have to configure server.[myid] property which have host name, leader and elector ports. Zookeeper use this information to form cluster.


Note:

we are using same machine to setup cluster so we have to make sure there is no port conflicts.

 

Zookeeper Node2 & Zookeeper Node2


Repeat Zookeeper Node1 Steps 1,2 and 3 for Zookeeper Node2 and Node3 and maintain unique port numbers.

 

Zookeeper Node2


myid file content is “2

 

Add/Update “zoo.cfg” file with following properties.

 

 

clientPort=2182

dataDir=C:\\kafka-workspace\\zookeeper-node1\\data

 

autopurge.snapRetainCount=3

autopurge.purgeInterval=24

 

server.1=localhost:2666:3666

server.2=localhost:2667:3667

server.3=localhost:2668:3668

 

tickTime=2000

initLimit=10

syncLimit=5

 

 

Zookeeper Node3


myid file content is “3

 

Add/Update “zoo.cfg” file with following properties.

 

 

clientPort=2183

dataDir=C:\\kafka-workspace\\zookeeper-node1\\data

 

autopurge.snapRetainCount=3

autopurge.purgeInterval=24

 

server.1=localhost:2666:3666

server.2=localhost:2667:3667

server.3=localhost:2668:3668

 

tickTime=2000

initLimit=10

syncLimit=5

 

 

Start Zookeeper Node 1,2 and 3


Zookeeper Node1


Open command prompt and locate to “zookeeper-node1” bin directory and use following command to start zookeeper server.

 

 

zkServer.cmd

 

 



 

Zookeeper console logs will give us the more details on server startup.

 




Note:


You may see “java.net.ConnectException: Connection refused: connect” warning and its due to other nodes are not yet started.


Zookeeper Node2


Open command prompt and locate to “zookeeper-node2” bin directory and use following command to start zookeeper server.

 

 

zkServer.cmd

 

 

Zookeeper Node3

 

Open command prompt and locate to “zookeeper-node3” bin directory and use following command to start zookeeper server.

 

 

zkServer.cmd

 

 

In the cluster only one node will be leader and other all nodes are followers. Leader and follower’s information can be view in the logs.

 

Node1( Leader)






Node2 (Follower)






Node3 (Follower)




 

Now successfully configured zookeeper cluster on windows.


References


https://zookeeper.apache.org/doc/current/index.html



Author





Recent Posts

Recent Posts Widget

Popular Posts