发布时间:2019-07-22 17:39:06编辑:auto阅读(1811)
zookeeper 分布式服务框架是 Apache Hadoop 的一个子项目,它主要是用来解决分布式应用中经常遇到的一些数据管理问题,如:统一命名服务、状态同步服务、集群管理、分布式应用配置项的管理等。zookeeper提供可靠的存储,利用它可以保存当前工作的状态。当使用python在某个客户端服务器访问zookeeper集群,需要在客户端服务器上安装zookeeper(不是集群的zookeeper)c开发环境,不需要配置。
$ wget http://archive.apache.org/dist/zookeeper/zookeeper-3.4.5/zookeeper-3.4.5.tar.gz
$ cd zookeeper-3.4.5/src/c
$ ./configure
$ make
$ sudo make install
测试c客户端命令行与zk集群(hacl-node3.pepstack.com:2181是zk集群的其中一台服务)联通情况:
[root@vm-repo c]# ./cli_mt hacl-node3.pepstack.com:2181
Watcher SESSION_EVENT state = CONNECTED_STATE
Got a new session id: 0x153eaa3fe840011
ls /
time = 5 msec
/: rc = 0
hadoop-ha
hbase
reg
admin
zookeeper
consumers
config
storm
yarn-leader-election
brokers
controller_epoch
time = 6 msec
OK!$ wget https://pypi.python.org/packages/source/z/zkpython/zkpython-0.4.2.tar.gz
解压安装:$ tar -zxf zkpython-0.4.2.tar.gzcd zkpython-0.4.2
$ python2.7 setup.py build
$ python2.7 setup.py install
$ python2.7
>>> import zookeeper
报错:Traceback (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
然后执行:
$ . /etc/profile
或者(二):# echo "/usr/local/lib" >> /etc/ld.so.conf
# /sbin/ldconfig
再测试:
$ python2.7
>>> import zookeeper as zoo
# 初始化连接到集群
zk = zoo.init("hacl-node3.pepstack.com:2181,hacl-node4.pepstack.com:2181,hacl-node5.pepstack.com:2181")
# 获取所有节点
zoo.get_children(zk, "/", None)
http://www.cnblogs.com/lexus/archive/2012/03/11/2390203.html
上一篇: python 字符串比较忽略大小写的方法
下一篇: Python获取控制台输入
47485
45787
36785
34318
28956
25590
24437
19607
19103
17628
5459°
6042°
5565°
5633°
6567°
5371°
5371°
5879°
5852°
7164°