博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ambari安装集群下python连接hbase之安装thrift
阅读量:2239 次
发布时间:2019-05-09

本文共 2361 字,大约阅读时间需要 7 分钟。

简介:  

  python连接hbase是需要通过thrift连进行连接的,ambari安装的服务中貌似没有自带安装hbase的thrift,我是看配置hbase的配置名称里面没有thrift,cdh版本的就有,所以我就自己安装了thrift。

一、thrift安装:

1、下载thrift依赖的东西 

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

2、安装boost_1_53_0.tar.gz

[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

3、下载最新版本thrift,网址:

 
4、移动到默认安装目录,并解压

[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

 二、启动thrift

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

2、启动thrift,默认端口是9090

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

三、使用python连接hbase

1、安装python依赖包

pip install thriftpip install hbase-thrift

2、demo程序

from thrift import Thriftfrom thrift.transport import TSocketfrom thrift.transport import TTransportfrom thrift.protocol import TBinaryProtocolfrom hbase import Hbasefrom 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 datatransport.open()row = 'row-key1'mutations = [Mutation(column="cf:a", value="1")]client.mutateRow('test', row, mutations)# get one rowtableName = 'test'rowKey = 'row-key1'result = client.getRow(tableName, rowKey)print resultfor r in result:    print 'the row is ', r.row    print 'the values is ', r.columns.get('cf:a').valuetransport.close()

 

转载于:https://www.cnblogs.com/zhang-ke/p/9008228.html

你可能感兴趣的文章
常用正则匹配符号
查看>>
建议42: 让工具类不可实例化
查看>>
Java 异步机制与同步机制的区别
查看>>
hibernate的对象三种状态说明
查看>>
什么是N+1查询?
查看>>
Spring 接管 Hibernate 配置 延迟加载
查看>>
找出不在预定数组中的自然数
查看>>
String常见面试题
查看>>
直插,快排,堆排,归并排序的分析
查看>>
二叉树的各种操作(面试必备)
查看>>
oracle
查看>>
泛型与通配符详解
查看>>
BaseServiceImpl中的实现关键点
查看>>
Struts2中的session、request、respsonse获取方法
查看>>
如何理解MVC模型
查看>>
SpringMVC中乱码解决方案
查看>>
SpringMVC中时间格式转换的解决方案
查看>>
post和get请求相关知识点
查看>>
关于try finally 中的return语句的问题
查看>>
RequestBody/ResponseBody处理Json数据
查看>>