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

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