How to check if ZooKeeper is running or up from command prompt?
Asked Answered
W

12

95

I exploring a few options to how Zookeeper is up and running

I would like to know how can I find the below.

  1. hostname and port for my zookeeper instance---I checked the zoo.cfg and I could only find the ClientPort not the hostname, will hostname be the hostname of my box??

  2. To check if ZooKeeper is up and running---I tried to do a ps -ef | grep "zoo" I could not find anything. May be I am using a wrong key word to search??

Any help would be really appreciated?

Wombat answered 17/3, 2015 at 18:4 Comment(1)
Do you mean from the command prompt on zookeeper's node? or from the client node's command prompt?Sicken
L
104

To check if Zookeeper is accessible. One method is to simply telnet to the proper port and execute the stats command.

root@host:~# telnet localhost 2181
Trying 127.0.0.1...
Connected to myhost.
Escape character is '^]'.
stats
Zookeeper version: 3.4.3-cdh4.0.1--1, built on 06/28/2012 23:59 GMT
Clients:

Latency min/avg/max: 0/0/677
Received: 4684478
Sent: 4687034
Outstanding: 0
Zxid: 0xb00187dd0
Mode: leader
Node count: 127182
Connection closed by foreign host.
Lindsey answered 19/9, 2016 at 3:47 Comment(3)
telnet is often not available/installed on the serversMassy
'stats' is not working on my Windows. Try 'srvr' instead.Raft
The list of available "Four Letter Words" are listed here. According to this stat is the correct word. But - I think - it has to be whitelisted. In my case only srvr was whitelisted by default (windows).Standby
G
100

One other way would be to use 4 letter commands to validate if zookeeper service is healthy or not

echo stat | nc <zookeeper ip> 2181
echo mntr | nc <zookeeper ip> 2181
echo isro  | nc <zookeeper ip> 2181

More details on the documentation link below https://zookeeper.apache.org/doc/r3.1.2/zookeeperAdmin.html#sc_zkCommands

Groundnut answered 14/2, 2016 at 11:12 Comment(4)
echo ruok | nc <zookeeper ip> 2181 just returns "imok" if it is OK, so that is probably the easiest to parse.Lozoya
nc might not be available in all environments.Sicken
Don't forget to allow ZOO_4LW_COMMANDS_WHITELIST="*" or lesser e.g. "stat", if you're running Zk in a Container. Otherwise you'll get a stat is not executed because it is not in the whitelist. ReferenceGuv
@JesseChisholm That goes without saying. There's a lot of popular commands that "might not be available in all environments," wget probably being the most common one despite often being used as the example by a huge amount of people to do web requests. Run a stripped down Docker image and even something as basic as the ip command might not be available. I've seen Ubuntu-based containers where sudo does not exist. It's really a moot point.Ectoenzyme
M
60

Go to bin directory of Zookeeper and type

./zkServer.sh status

For More info go through below link:

http://www.ibm.com/developerworks/library/bd-zookeeper/

Hope this could help you.

Micturition answered 21/3, 2015 at 23:59 Comment(3)
see: zookeeper.apache.org/doc/r3.4.8/zookeeperStarted.html and change "r3.4.8" to your zookeeper versionVaudevillian
zkServer status ZooKeeper JMX enabled by default Using config: /usr/local/etc/zookeeper/zoo.cfg Mode: standaloneRelativistic
Link is no longer alive. Can't edit because the queue is full.Underworld
I
28
echo stat | nc localhost 2181 | grep Mode
echo srvr | nc localhost 2181 | grep Mode #(From 3.3.0 onwards)

Above will work in whichever modes Zookeeper is running (standalone or embedded).

Another way

If zookeeper is running in standalone mode, its a JVM process. so -

jps | grep Quorum

will display list of jvm processes; something like this for zookeeper with process ID

HQuorumPeer
Isogamy answered 19/12, 2016 at 11:46 Comment(1)
echo srvr | nc localhost 2181 | grep Mode worked for meCuffs
F
16

I did some test:

When it's running:

$ /usr/lib/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /usr/lib/zookeeper/bin/../conf/zoo.cfg
Mode: follower

When it's stopped:

$ zkServer status                                                                                                                                
JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Error contacting service. It is probably not running.

I'm not running on the same machine, but you get the idea.

Faria answered 7/8, 2015 at 7:29 Comment(0)
O
10

enter the below command to verify if zookeeper is running :

echo "ruok" | nc localhost 2181 ; echo 

expected response: imok

Orlop answered 10/4, 2019 at 10:10 Comment(1)
An instance may respond with "This ZooKeeper instance is not currently serving requests" to srvr command but still respond with "imok" to ruok command.Hallett
M
9

Zookeeper is just a Java process and when you start a Zookeeper instance it runs a org.apache.zookeeper.server.quorum.QuorumPeerMain class. So you can check for a running Zookeeper like this:

jps -l | grep zookeeper

or even like this:

jps | grep Quorum

upd:

regarding this: will hostname be the hostname of my box?? - the answer is yes.

Millisent answered 17/3, 2015 at 20:3 Comment(0)
S
4

From a Windows 10

  • Open Command Promt then type telnet localhost 2181and then you type srvr OR
  • From inside bin folder, open a PowerShell window and type zkServer.sh status
Stratus answered 27/2, 2020 at 8:30 Comment(0)
Q
3

I use:

  jps

Depending on your installation a running Zookeeper would look like

  HQuorumPeer

or sth. with zookeeper in it's name.

Quinquennial answered 10/8, 2015 at 12:53 Comment(0)
J
2

For people who uses the official docker image:

https://hub.docker.com/_/zookeeper

in the whitelist is only enabled srvr

See below the example:

telnet hostname 2181                                                                                                                                
Trying ::1...
Connected to localhost.
Escape character is '^]'.
srvr
Zookeeper version: 3.7.0-e3704b390a6697bfdf4b0bef79e3da7a4f6bac4b, built on 2021-03-17 09:46 UTC
Latency min/avg/max: 0/0.0/0
Received: 3
Sent: 2
Connections: 1
Outstanding: 0
Zxid: 0x0
Mode: standalone
Node count: 5
Connection closed by foreign host.

Doc:

ZOO_4LW_COMMANDS_WHITELIST

Defaults to srvr. Zookeeper's 4lw.commands.whitelist

A list of comma separated Four Letter Words commands that user wants to use. A valid Four Letter Words command must be put in this list else ZooKeeper server will not enable the command. By default the whitelist only contains "srvr" command which zkServer.sh uses. The rest of four letter word commands are disabled by default.

Javier answered 20/3, 2022 at 22:15 Comment(0)
L
0

For those of you who used homebrew, use this command - /opt/homebrew/Cellar/zookeeper/3.8.1/bin/zkServer status

Lotze answered 10/2, 2023 at 17:48 Comment(0)
S
0

echo srvr|nc localhost 2181

It works when telnet is not installed and stat, mntr, ruok are not whitelisted.

Slipper answered 2/5 at 20:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.