簡介
HBase Thrift Server是hbase基于Apache Thrift開發(fā)用來提供對多語言支持的服務檐束。同時保留了thrift和thrift2兩個版本戴已,thrift2適應了新的java api,cdh默認采用thrift澈侠。
啟動HBase Thrift2
執(zhí)行命令,啟動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()