标签:
环境:CentOS6.5 HBase0.98.11 thrift0.9.2[grid@hadoop1 ~]$ wget http://mirrors.cnnic.cn/apache/thrift/0.9.2/thrift-0.9.2.tar.gz [grid@hadoop1 ~]$ tar -zxf thrift-0.9.2.tar.gz2.安装依赖环境
yum -y install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel openssl-devel3.升级bison版本到2.5
[grid@hadoop1 ~]$ http://ftp.gnu.org/gnu/bison/bison-2.5.tar.gz [grid@hadoop1 ~]$ tar -zxf bison-2.5.tar.gz [root@hadoop1 bison-2.5]# ./configure && make && make install4.安装
[root@hadoop1 thrift-0.9.2]# ./configure --with-lua=no && make && make install5.验证安装是否成功
[root@hadoop1 thrift-0.9.2]# thrift -version Thrift version 0.9.26.下载HBase源码包
[root@hadoop1 grid]# wget http://mirrors.cnnic.cn/apache/hbase/hbase-0.98.11/hbase-0.98.11-src.tar.gz [root@hadoop1 grid]# tar -zxf hbase-0.98.11-src.tar.gz7.创建python的hbase thrift接口文件
[root@hadoop1 grid]# cd hbase-0.98.11/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift [root@hadoop1 thrift]# thrift -gen py ./Hbase.thrift [root@hadoop1 thrift]# ls gen-py Hbase.thrift [root@hadoop1 thrift]# cp -r gen-py/hbase/ /usr/lib64/python2.6/site-packages/8.依次启动hadoop、hbase、thrift
[grid@hadoop1 bin]$ sh start-all.sh [grid@hadoop1 ~]$ sh start-hbase.sh [grid@hadoop1 ~]$ hbase thrift -p 9090 start [grid@hadoop1 ~]$ jps 21095 NameNode 21334 JobTracker 21250 SecondaryNameNode 21746 HQuorumPeer 22362 Jps 22220 ThriftServer 21966 HRegionServer 21809 HMaster9.创建测试脚本
[grid@hadoop1 test]$ vim test.py #! /usr/bin/python #coding=utf-8 import sys sys.path.append(‘/usr/lib64/python2.6/site-packages/‘) 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 = TSocket.TSocket(‘192.168.0.104‘, 9090) transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = Hbase.Client(protocol) transport.open() print(client.getTableNames())10.测试
[grid@hadoop1 test]$ python test.py [‘member‘]
标签:
原文地址:http://my.oschina.net/zc741520/blog/399049