简介
HBase Thrift Server是hbase基于Apache Thrift开发用来提供对多语言支持的服务。同时保留了thrift和thrift2两个版本,thrift2适应了新的java api,cdh默认采用thrift。
启动HBase Thrift2
执行命令,启动thrift2
/opt/cloudera/parcels/CDH/lib/hbase/bin/hbase-daemon.sh --config /opt/cloudera/parcels/CDH/lib/hbase/conf foreground_start thrift2 --infoport 9096 -p 9091
python connect thrift2
1、pip install thrift==0.9.0
from thrift.transport import TSocket
from hbase import THBaseService
from hbase.ttypes import *
print "Thrift2 Demo"
print "This demo assumes you have a table called \"example\" with a column family called \"family1\""
host = "200.200.200.65"
port = 9091
framed = False
socket = TSocket.TSocket(host, port)
if framed:
transport = TTransport.TFramedTransport(socket)
else:
transport = TTransport.TBufferedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = THBaseService.Client(protocol)
transport.open()
table = "bigdata:tb_sleep_feedback_data"
scan = TScan()
result = client.openScanner(table, scan)
s = client.getScannerRows(result, 1)
print "Result:", s
transport.close()