Zookeeper 为什么将内容传送到命令nc不起作用?

qcbq4gxm  于 2022-12-09  发布在  Apache
关注(0)|答案(3)|浏览(124)

我尝试通过使用nc从shell中获取Zookeeper状态,
首先调用nc localhost 2181,然后键入:统计有效。
echo "stat" | nc localhost 2181不返回任何内容。
为甚么?

yqkkidmi

yqkkidmi1#

在Zookeeper邮件列表中问了同样的问题,得到了这个:
很可能您使用了错误的“nc”命令。
不是开玩笑:P有两个不同的“nc”包,语法也不同。在类似debian的发行版中,它们是netcat-openbsd和netcat-traditional,但是我在CentOS中遇到了同样的问题(我记不起包的名字了,抱歉),直到我意识到我用错了。
--托马斯·努涅斯
我发现我的服务器上的nc是nc.openbsd,安装nc.traditional后,
echo "stat" | nc.traditional 10.18.10.30 2181
会传回预期的结果。

5sxhfpxr

5sxhfpxr2#

我发现向nc命令添加带有-q参数的wait会产生预期的输出。
echo "ruok" | nc -q 2 localhost 2181在Ubuntu系统上为我工作。您可能需要在OpenBSD系统上使用-w而不是-q

xxslljrj

xxslljrj3#

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

相关问题