python 访问 zookeeper
生活随笔
收集整理的這篇文章主要介紹了
python 访问 zookeeper
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
python 訪問 zookeeper
1.安裝:
zookeeper python客戶端依賴c客戶端,所以要先安裝c版本客戶端
安裝支持包: pip install zkpython
2.測試
[root@otter c]# pythonPython 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import zookeeperTraceback (most recent call last):File "<stdin>", line 1, in <module>File "build/bdist.linux-x86_64/egg/zookeeper.py", line 7, in <module>File "build/bdist.linux-x86_64/egg/zookeeper.py", line 6, in __bootstrap__ImportError: libzookeeper_mt.so.2: cannot open shared object file: No such file or directory>>>解決方法:
將下面這句加入到 /etc/profile 最后一行(libzookeeper_mt.so在/usr/local/lib下面):
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib(在crontab 中添加 自動作業,也需要在sh 文件中添加此行腳本,不然不會執行)
然后執行:
$ . /etc/profile import zookeeperhader=zookeeper.init("localhost:2181") #登錄到客戶端 channels=zookeeper.get_children(hader,'/otter/channel') #獲取目錄 stat=zookeeper.get(hader,'/otter/channel/1') #獲取節點信息python3 安裝zookeeper
>>> import zookeeper Traceback (most recent call last):File "<stdin>", line 1, in <module> ImportError: /usr/local/lib/python3.6/site-packages/zkpython-0.4.2-py3.6-linux-x86_64.egg/zookeeper.cpython-36m-x86_64-linux-gnu.so: undefined symbol: PyInt_AsLong >>> quit()解決方法:
用 zookeeper安裝包 的 zookeeper.c 文件替換掉 zkpython 的包文件 zookeeper.c
[root@otter c]# cp /opt/download/zookeeper-3.4.12/src/contrib/zkpython/src/c/zookeeper.c /opt/download/zkpython-0.4.2/zookeeper.c
然后進入zkpythton目錄
python setup.py install 進行安裝
之后import zookeeper測試通過
[root@otter zookeeper-3.4.12]# python3 Python 3.6.0a1 (default, Apr 15 2019, 14:50:24) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import zookeeper >>>示例代碼:(列出 /otter/channel ,并查詢其狀態)
hader=zookeeper.init("localhost:2181") channels=zookeeper.get_children(hader,'/otter/channel') for temp in channels:stat=zookeeper.get(hader,'/otter/channel/'+temp)zookeeper 命令不多,也比較簡單,這里不一一測試。
總結
以上是生活随笔為你收集整理的python 访问 zookeeper的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 5.7主从延迟 相关参数配置
- 下一篇: 10-穿墙代理的设置 | 01.数据抓取