1、 下载thrift-0.8.0.tar.gz
2、./configure --prefix=/usr
make
makeinstall
3、cd $HBASE_HOME
thrift --gen py /src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift
这样在当前目录就生成了gen-py目录
Hbase.py 中定义了一些HbaseClient可以使用的方法
ttypes.py中定义了HbaseClient传输的数据类型
将生成的hbase目录copy到python的包下
cp -r gen-py/hbase /usr/lib/python2.7/site-packages/
4 、启动hbase和thrift服务
start-hbase.sh
/hbase-daemon.sh start thrift
5、测试
#!/usr/bin/python
import sys
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
from hbase.ttypes import *
transport = TTransport.TBufferedTransport(TSocket.TSocket('web194', 9090))
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = Hbase.Client(protocol)
transport.open()
tables=client.getTableNames()
print(tables)