环境:CentOS6.5 HBase0.98.11 thrift0.9.2
1.下载解压
[[email protected] ~]$ wget http://mirrors.cnnic.cn/apache/thrift/0.9.2/thrift-0.9.2.tar.gz [[email protected] ~]$ tar -zxf thrift-0.9.2.tar.gz
2.安装依赖环境
yum -y install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel openssl-devel
3.升级bison版本到2.5
[[email protected] ~]$ http://ftp.gnu.org/gnu/bison/bison-2.5.tar.gz [[email protected] ~]$ tar -zxf bison-2.5.tar.gz [[email protected] bison-2.5]# ./configure && make && make install
4.安装
[[email protected] thrift-0.9.2]# ./configure --with-lua=no && make && make install
5.验证安装是否成功
[[email protected] thrift-0.9.2]# thrift -version Thrift version 0.9.2
6.下载HBase源码包
[[email protected] grid]# wget http://mirrors.cnnic.cn/apache/hbase/hbase-0.98.11/hbase-0.98.11-src.tar.gz [[email protected] grid]# tar -zxf hbase-0.98.11-src.tar.gz
7.创建python的hbase thrift接口文件
[[email protected] grid]# cd hbase-0.98.11/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift [[email protected] thrift]# thrift -gen py ./Hbase.thrift [[email protected] thrift]# ls gen-py Hbase.thrift [[email protected] thrift]# cp -r gen-py/hbase/ /usr/lib64/python2.6/site-packages/
8.依次启动hadoop、hbase、thrift
[[email protected] bin]$ sh start-all.sh [[email protected] ~]$ sh start-hbase.sh [[email protected] ~]$ hbase thrift -p 9090 start [[email protected] ~]$ jps 21095 NameNode 21334 JobTracker 21250 SecondaryNameNode 21746 HQuorumPeer 22362 Jps 22220 ThriftServer 21966 HRegionServer 21809 HMaster
9.创建测试脚本
[[email protected] 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.测试
[[email protected] test]$ python test.py [‘member‘]
时间: 2024-08-08 06:53:42