python連接zookeeper、hbase

背景:

os:centos 7.6

zookeeper:3.4.14

hbase:1.4.13

python:anaconda3-python3.6.8

準備工作:

先啓動集羣,包括zookeeper,hbase,和ThriftServer,ThriftServer是hbsse用於對外提供api的組件

啓動ThriftServer的命令是:

hbase thrift start -p 9090

啓動後如下

然後可以使用happybase連接了

# _*_ coding:utf-8 _*_
import happybase
connection = happybase.Connection('localhost', autoconnect=False)
connection.open()
print(connection.tables())#查看hbase現有的所有表名
connection.close()

當然以上只是簡單示例,更深使用後續貼出。

連接zookeeper

使用kazoo模塊

from kazoo.client import KazooClient
 
zk = KazooClient(hosts='127.0.0.1:2181')
 
# 啓動連接
zk.start() 
 
# 停止連接
zk.stop()

一定要先啓動連接,不然不能使用其他方法。

以上借鑑了以下兩篇博客

https://blog.csdn.net/xiaoweite1/article/details/104879453

https://blog.csdn.net/manduner/article/details/95465606

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章