Python Zkpython Installation

Source: Internet
Author: User

Requirements: Using Python to manipulate zookeeper


1. Because the Python client relies on the C client, install the C version of the client first
CD zookeeper-3.4.5/src/c
./configure
Make
Make install


2. Test the C version of the client, GCC and python-devel required
./CLI_MT localhost:2181
Watcher Session_event state = Connected_state
Got a new session id:0x23f9d77d3fe0001


LS/
Time = 0 msec
/: rc = 0
Consumers
Storm
Brokers
Zookeeper
Jobkeeper
Time = 0 msec


So the installation is successful.


3. Download the Python extension package and unzip it:
Address: https://pypi.python.org/pypi/zkpython/0.4.2




4. If Pyhon.h cannot be found, there may be no python26-devel installed
32-Bit direct operation
Yum Install python26-devel.i386




5. Whether the test was successful


Import Zookeeper


If error:
>>> Import Zookeeper
Traceback (most recent):
File "<stdin>", line 1, in <module>
Importerror:libzookeeper_mt.so.2:cannot open Shared object file:no such file or directory


Configure in the shell or if the/etc/profile file:
Export ld_library_path=/usr/local/lib/


6. Use
>>> Import Zookeeper
>>> hander = Zookeeper.init ("dc002.tj:2181")
>>> dir (zookeeper) #方法列表
[' Apierror ', ' associating_state ', ' authfailed ', ' auth_failed_state ', ' apierrorexception ', ' authfailedexception ', ' Badarguments ', ' badversion ', ' badargumentsexception ', ' badversionexception ', ' changed_event ', ' CHILD_EVENT ', ' CLOSING ', ' connected_state ', ' connecting_state ', ' connectionloss ', ' created_event ', ' closingexcehelp on built-in function get in module zookeeper:
Ption ', ' connectionlossexception ', ' datainconsistency ', ' deleted_event ', ' datainconsistencyexception ', ' EPHEMERAL ', ' Expired_session_state ', ' invalidacl ', ' invalidcallback ', ' invalidstate ', ' invalidaclexception ', ' Invalidcallbackexception ', ' invalidstateexception ', ' log_level_debug ', ' log_level_error ', ' LOG_LEVEL_INFO ', ' LOG_ Level_warn ', ' marshallingerror ', ' marshallingerrorexception ', ' noauth ', ' nochildrenforephemerals ', ' NODEEXISTS ', ' Nonode ', ' notempty ', ' nothing ', ' notwatching_event ', ' noauthexception ', ' nochildrenforephemeralsexception ', ' Nonodeexception ', ' nodeexistsexception ', ' notemptyexception ', ' nothingexception ', ' OK ', ' operationtimeout ', ' Operationtimeoutexception ', ' perm_admin ', ' perm_all ', ' perm_create ', ' perm_delete ', ' perm_read ', ' perm_write ', ' Runtimeinconsistency ', ' runtimeinconsistencyexception ', ' SEQUENCE ', ' sessionexpired ', ' sessionmoved ', ' SESSION_ EVENT ', ' systemerror ', ' sessionexpiredexception ', ' sessionmovedexception ', ' systemerrorexception ', ' UNIMPLEMENTED ', ' UNimplementedexception ', ' zookeeperexception ', ' __doc__ ', ' __file__ ', ' __name__ ', ' __package__ ', ' __version__ ', ' Acreate ', ' Add_auth ', ' adelete ', ' aexists ', ' aget ', ' aget_acl ', ' aget_children ', ' aset ', ' aset_acl ', ' async ', ' client_id ', ' close ', ' create ', ' delete ', ' deterministic_conn_order ', ' exists ', ' get ', ' get_acl ', ' get_children ', ' init ', ' Is_ Unrecoverable ', ' recv_timeout ', ' Set ', ' Set2 ', ' set_acl ', ' set_debug_level ', ' set_log_stream ', ' set_watcher ', ' state ', ' Zerror ']


#测试get命令
>>> Zookeeper.get (hander, "/jobkeeper/gamedc/job/kpi-day-pay_day")
(' {' "dependency": [{"Name": "Etl-day-pay_log", "type": "Day"}], "name": "Kpi-day-pay_day", "owner": "DC", "path": "${ Scripts_home}/kpi/pay/pay_day.sh "," type ":" Day "," Hour ":" The "} ', {' Pzxid ': 4298844949L, ' CTime ': 1411896174285L, ' Aversion ': 0, ' Mzxid ': 4299652800L, ' Numchildren ': 0, ' Ephemeralowner ': 0L, ' Version ': 2, ' datalength ': 163, ' mtime ': 1412 055214425L, ' cversion ': 0, ' Czxid ': 4298844949L})




#其他的delete, set can be tested by itself, it's all APIs.

Python Zkpython Installation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.