如何检查是否 ZooKeeper 正在运行或从命令提示符?

我探索了一些设置卡夫卡的选项,我知道动物园管理员必须启动并运行卡夫卡。

我想知道如何才能找到以下内容。

1)我的 zookeep 实例的主机名和端口——-我检查了 zoo.cfg,我只能找到 ClientPort 而不是主机名,主机名会是我的机器的主机名吗?

2)为了检查 ZooKeeper 是否已经启动并运行——-我试图做一个 ps -ef | grep "zoo",但是我什么也找不到。也许我用错了关键字来搜索? ? ?

有什么需要帮忙的吗?

211649 次浏览

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.

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.

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.

I use:

  jps

Depending on your installation a running Zookeeper would look like

  HQuorumPeer

or sth. with zookeeper in it's name.

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

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.
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

enter the below command to verify if zookeeper is running :

echo "ruok" | nc localhost 2181 ; echo

expected response: imok

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

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.

For Window, users Install mobaxterm https://mobaxterm.mobatek.net/download.html

The mobaxterm terminal allows you to run all Linux commands

enter image description here