Pergunta

I try to get zookeeper stat from shell by using nc,

call nc localhost 2181 first, then type in: stat works.

while echo "stat" | nc localhost 2181 returns nothing.

why?

Foi útil?

Solução

Asked the same question in Zookeeper mail list, and got this:

Most probably you are using the wrong "nc" command.

Not kidding :P there are two different "nc" packages, and the syntax is different betweem then. In debian-like distros they are netcat-openbsd and netcat-traditional, but I ran into the same problems with netcat in CentOS (I can't remember the name of the packages, sorry) until I realized I was using it wrong.

--Tomas Nunez

I found that the nc on my server is nc.openbsd, after install nc.traditional,

echo "stat" | nc.traditional 10.18.10.30 2181

returns the expected result.

Outras dicas

I found that adding a wait with the -q param to the nc command resulted in the expected output.

echo "ruok" | nc -q 2 localhost 2181 worked for me on Ubuntu systems. You may need to use -w instead of -q on OpenBSD systems.

By default the whitelist only contains "srvr" command which zkServer.sh uses.

Try echo "srvr" | nc localhost 2181

or

set 4lw.commands.whitelist=*

see zookeeper doc 4lw.commands.whitelist

  • 4lw.commands.whitelist : (Java system property: zookeeper.4lw.commands.whitelist) New in 3.5.3: 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. Here's an example of the configuration that enables stat, ruok, conf, and isro command while disabling the rest of Four Letter Words command:

4lw.commands.whitelist=stat, ruok, conf, isro

If you really need enable all four letter word commands by default, you can use the asterisk option so you don't have to include every command one by one in the list. As an example, this will enable all four letter word commands:

4lw.commands.whitelist=*

Three of the more interesting commands: "stat" gives some general information about the server and connected clients, while "srvr" and "cons" give extended details on server and connections respectively.

Moving forward, Four Letter Words will be deprecated, please use AdminServer instead.

The new method of AdminServer is setting 4lw.commands.whitelist=* and sending an HTTP request to http://localhost:8080/commands/stat using wget or curl.

root@zoo2:/apache-zookeeper-3.8.0-bin# wget --quiet --output-document=/dev/stdout http://localhost:8080/commands/stat
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top