python - 如何让 python Zookeeper api 工作?

标签 python apache-zookeeper

我正在尝试让 Zookeeper 在独立模式下工作以进行 python api 测试,但我遇到了 python api 的问题。

1)这是我在 ubuntu 11.04 上安装的方式

sudo apt-get install zookeeper
sudo easy_install zc-zookeeper-static
from source install python zc.zk
http://pypi.python.org/packages/source/z/zc.zk/zc.zk-0.9.1.tar.gz

2)这是我启动动物园管理员的方式:

sudo /usr/share/zookeeper/bin/zkCli.sh -server 127.0.0.1:2181
Connecting to 127.0.0.1:2181
Welcome to ZooKeeper!
JLine support is enabled
[zk: 127.0.0.1:2181(CONNECTING) 0] 

3)以下是我尝试根据文档使用 python api 的方法。

import zc.zk
zk = zc.zk.ZooKeeper('localhost:2181')
zk.register_server('/fooservice/providers', ('192.168.0.42', 8080))

4)这是我得到的 python 错误。

No handlers could be found for logger "ZooKeeper"
Traceback (most recent call last):
  File "/home/ubuntu/workspace/rtbopsConfig/zookeeper/test.py", line 2, in <module>
    zk = zc.zk.ZooKeeper('localhost:2181')
  File "/usr/local/lib/python2.7/dist-packages/zc.zk-0.9.1-py2.7.egg/zc/zk/__init__.py", line 211, in __init__
    raise FailedConnect(connection_string)
zc.zk.FailedConnect: localhost:2181

5)这是日志文件:

2012-07-15 14:23:51,666 - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1000] - Opening socket connection to server localhost/127.0.0.1:2181
2012-07-15 14:23:51,667 - WARN  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1120] - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
        at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
        at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:592)
        at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1078)
2012-07-15 14:23:53,076 - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1000] - Opening socket connection to server localhost/127.0.0.1:2181
2012-07-15 14:23:53,077 - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@908] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2012-07-15 14:23:53,165 - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1114] - Unable to reconnect to ZooKeeper service, session 0x0 has expired, closing socket connection

所以......我是动物园管理员的新手。我想使用 python api 在独立模式下启动并运行。另外,似乎有很多 python Zookeeper api。哪一个最常用?

谢谢

最佳答案

您的 ubuntu 上使用 IPv6 吗?将 localhost 替换为 127.0.0.1,与 zkCli.sh 命令中使用的相同。您可以运行sudo netstat -lnp|grep 2181来检查zookeeper监听的地址。

关于python - 如何让 python Zookeeper api 工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11489893/

相关文章:

python - 在 wxPython 中使用多线程

python - meshgrid numpy的功能

python - 在 linux 上修改传出 UDP 数据包中的数据

docker - 如何恢复kafka数据

java - 如何使用 Curator for Zookeeper 有效地使用 LeaderElection 配方?

c++ - ZooKeeper 中的持久节点和临时节点

python - 着色问题 - open cv 与 matplotlib legend 的结合

python - 基于 tensorflow 中的连续掩码值将张量分割为动态长度张量?

docker - 设置太阳鸟遥测Kafka DRUID和超集

apache-zookeeper - Storm UI 获取内部服务器错误 :org. apache.thrift7.transport.TTransportException : java.net.ConnectException:连接被拒绝