如何从 bash 运行 zookeeper 的 zkCli.sh 命令?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34756953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run zookeeper's zkCli.sh commands from bash?
提问by rkrishnan
Is it possible to run a zkCli.sh command like ls /
or get /
from bash directly without going inside the zookeeper shell? I am using Zookeeper version 3.4.6-1569965.
是否有可能像运行zkCli.sh命令ls /
或get /
直接从bash中没有饲养员壳内回事?我使用的是 Zookeeper 版本 3.4.6-1569965。
For example, something like this:
例如,这样的事情:
$ ./zkCli.sh get /
I am able to do this only after connecting to the zookeeper shell and then running get /
from there, like below:
只有在连接到 zookeeper 外壳然后get /
从那里运行后,我才能执行此操作,如下所示:
$ ./zkCli.sh
Connecting to localhost:2181
Welcome to ZooKeeper!
WATCHER::
WatchedEvent state:AuthFailed type:None path:null
JLine support is enabled
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] get /
[]
回答by jolestar
zkCli.sh has been support process commands after 3.4.7. https://issues.apache.org/jira/browse/ZOOKEEPER-1897
zkCli.sh 从 3.4.7 开始支持进程命令。 https://issues.apache.org/jira/browse/ZOOKEEPER-1897
such as:
如:
./zkCli.sh -server xxxxx:2181 get /test
zkcli, a golang cli for zookeeper, https://github.com/go-zkcli/zkcli, also a simple solution.
zkcli,zookeeper 的 golang cli,https://github.com/go-zkcli/zkcli,也是一个简单的解决方案。
zkcli --servers srv-1,srv-2,srv-3 create /demo_only some_value
回答by Michelle Tan
you can use bash without going inside directly. However, the only disadvantage to this is that you have to make sure that your zk command/syntax is correct.
您可以使用 bash 而无需直接进入。但是,唯一的缺点是您必须确保您的 zk 命令/语法是正确的。
This would work:
这会起作用:
#! /bin/bash
zkCli.sh -server localhost:2181 <<EOF
get /testnode
quit
EOF
But this wont:
但这不会:
#! /bin/bash
zkCli.sh -server localhost:2181 <<EOF
gt /testnode
quit
EOF
回答by Giova
I can obtain HBase Master address, for example, with the following syntax:
例如,我可以使用以下语法获取 HBase 主地址:
zkCli.sh -server myserver get /hbase/master
If it does not work, this other will:
zkCli.sh -server myserver get /hbase/master
如果它不起作用,另一个将:
zkCli.sh -server myserver <<EOF
get /hbase/master
quit
quit
EOF
EOF