Python操作HBase
来源:互联网 发布:淘宝能买汽车吗 编辑:程序博客网 时间:2024/05/15 20:37
安装HBase
HBase是一个构建在HDFS上的分布式列存储系统,主要用于海量结构化数据存储。这里,我们的目标只是为Python访问HBase提供一个基本的环境,故直接下载二进制包,采用单机安装。下载后解压,修改配置文件,然后可以直接启动HBase了。所用系统版本为ubuntu14.04。
下载
wget https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/1.2.4/hbase-1.2.4-bin.tar.gz tar zxvf hbase-1.2.4-bin.tar.gz
配置
修改hbase-env.sh,设置JAVA_HOME。
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
修改hbase-site.xml,设置存储数据的根目录。
<configuration> <property> <name>hbase.rootdir</name> <value>file:///home/mi/work/hbase/data</value> </property></configuration>
启动
bin/start-hbase.sh # 启动bin/hbase shell # 进入hbase交互shell
安装Thrift
安装好HBase之后,还需安装Thrift,因为其他语言调用HBase时,需要通过Thrift进行连接。
安装Thrift依赖
sudo apt-get install automake bison flex g++ git libboost1.55 libevent-dev libssl-dev libtool make pkg-config
PS: libboost1.55-all-dev,在我的ubuntu14.04上安装有点问题,所以装的是libboost1.55。
编译安装
下载源码,解压后进行编译安装。Thrift下载地址
tar zxf thrift-0.10.0.tar.gzcd thrift-0.10.0/./configure --with-cpp --with-boost --with-python --without-csharp --with-java --without-erlang --without-perl --with-php --without-php_extension --without-ruby --without-haskell --without-gomake # 编译耗时较长sudo make install
参考文档:
https://thrift.apache.org/docs/install/debian, https://thrift.apache.org/docs/BuildingFromSource
启动HBase的Thrift服务
bin/hbase-daemon.sh start thrift
检查系统进程
~/work/hbase/hbase-1.2.4/conf$ jps3009 ThriftServer4184 HMaster5932 Jps733 Main
可以看到ThriftServer已成功启动,然后我们就可以使用多种语言,通过Thrift来访问HBase了。
Python操作HBase
下面以Python为例来演示如何访问HBase。
安装依赖包
sudo pip install thriftsudo pip install hbase-thrift
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').value
执行结果:
['test'][TRowResult(columns={'cf:a': TCell(timestamp=1488617173254, value='1')}, row='row-key1')]the row is row-key1the values is 1
0 0
- 使用python操作HBase
- python操作 hbase 数据
- Python操作HBase
- Hbase Python 操作准备
- python访问、操作hbase
- Python操作HBase
- python通过thrift操作hbase
- HappyBase安装&Python操作HBase
- python操作hbase 远程连接
- python 通过thrift 简单操作hbase
- python 通过thrift 简单操作hbase
- [bigdata-016] python happybase 操作hbase
- 【问题汇总】python操作hbase脚本
- hbase+python安装部署及操作
- hbase 操作
- python hbase
- 使用Python语言通过Thrift 网关操作HBase
- python模块系列 (二)之操作NoSQL数据库hbase
- [51NOD]1283 最小周长[数学]
- UI设计学习路线图
- 这是一个简单的小东西——用html做Diy书签
- 402. Remove K Digits
- SEO唯有勤奋优化,新手必读!
- Python操作HBase
- Activity生命周期
- 乐观锁和悲观锁的区别
- iOS学习笔记-038.UITableView示例二——九宫格
- [JNI]开发实例(1)封装libjpeg库 保证图片质量压缩图片
- 论文Convolutional Naural Networks for Sentence Classification--模型介绍篇
- 非微信官方网页,继续访问将转换成手机预览模式
- 蛇行矩阵
- 区间更新POJ3468 HDU1698