背景:
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()
‘
一定要先啓動連接,不然不能使用其他方法。
以上借鑑了以下兩篇博客