ambari安装集群下python链接hbase之安装thrift

简介:  

  python链接hbase是须要经过thrift连进行链接的,ambari安装的服务中貌似没有自带安装hbase的thrift,我是看配置hbase的配置名称里面没有thrift,cdh版本的就有,因此我就本身安装了thrift。java

1、thrift安装:

一、下载thrift依赖的东西 python

yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel openssl-devel

二、安装boost_1_53_0.tar.gzc++

[root@master ~]# wget http://sourceforge.net/projects/boost/files/boost/1.53.0/boost_1_53_0.tar.gz
[root@master ~]# tar xvf boost_1_53_0.tar.gz
[root@master ~]# cd boost_1_53_0
[root@master boost_1_53_0]# ./bootstrap.sh
[root@master boost_1_53_0]# ./b2 install
[root@master boost_1_53_0]# cp /usr/local/lib/libboost_unit_test_framework.a /usr/lib64/
[root@master boost_1_53_0]# make
[root@master boost_1_53_0]# make install

三、下载最新版本thrift,网址:http://thrift.apache.org
 
四、移动到默认安装目录,并解压apache

[root@master ~]# mv thrift-0.11.0.tar.gz /usr/local
[root@master ~]# cd /usr/local
[root@master local]# tar -zxvf thrift-0.11.0.tar.gz
[root@master local]# mv thrift-0.11.0 thrift
[root@master local]# cd thrift
[root@master local]# ./configure --libdir=/usr/lib --without-java --without-python --without-c_glib
[root@master local]# make
[root@master local]# make install

 2、启动thrift

一、找到hbase的bin执行文件夹,我执行的位置是ambari默认安装的文件夹下面/usr/hdp/2.6.3.0-235/hbase/binbootstrap

二、启动thrift,默认端口是9090ruby

[root@master ~]# cd /usr/hdp/2.6.3.0-235/hbase/bin
[root@master bin]# bin/hbase-daemon.sh start thrift

3、使用python链接hbase

一、安装python依赖包flex

pip install thrift
pip install hbase-thrift

二、demo程序spa

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('localhost', 9090)

transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)

client = Hbase.Client(protocol)
transport.open()

contents = ColumnDescriptor(name='cf:', maxVersions=1)
# client.deleteTable('test')
client.createTable('test', [contents])

print client.getTableNames()

# insert data
transport.open()

row = 'row-key1'

mutations = [Mutation(column="cf:a", value="1")]
client.mutateRow('test', row, mutations)

# get one row
tableName = 'test'
rowKey = 'row-key1'

result = client.getRow(tableName, rowKey)
print result
for r in result:
    print 'the row is ', r.row
    print 'the values is ', r.columns.get('cf:a').value
transport.close()
相关文章
相关标签/搜索