通过thrift访问
thrift配置见http://blog.csdn.net/moxpeter/article/details/7403074
确认hbase已经启动thrift服务,如果未启动,报错打印 thrift.transport.TTransport.TTransportException: TSocket read 0 bytes
cd 到$HBASE/bin执行
hbase thrift start
启动后会打印出一些环境变量以及hbase和zookeeper的配置信息
其中这句打印出了thrift的服务端口9090(猜的)
INFO ThriftServer: starting HBase ThreadPool Thrift server on /0.0.0.0:9090
python2.7测试代码
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('localhost', 9090))
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = Hbase.Client(protocol)
transport.open()
tables=client.getTableNames()
print(tables)
['bonc_test']
print(client.getRow('bonc_test','row111'))
[TRowResult(columns={'data:': TCell(timestamp=1333007757459L, value='line3')}, row='row111')]