安装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
  • 1

PS: libboost1.55-all-dev,在我的ubuntu14.04上安装有点问题,所以装的是libboost1.55。

编译安装

下载源码,解压后进行编译安装。Thrift下载地址

tar zxf thrift-0.10.0.tar.gz
cd 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-go
make # 编译耗时较长
sudo make install

参考文档: 
https://thrift.apache.org/docs/install/debianhttps://thrift.apache.org/docs/BuildingFromSource

启动HBase的Thrift服务

bin/hbase-daemon.sh start thrift

检查系统进程

~/work/hbase/hbase-1.2.4/conf$ jps
3009 ThriftServer
4184 HMaster
5932 Jps
733 Main
可以看到ThriftServer已成功启动,然后我们就可以使用多种语言,通过Thrift来访问HBase了。

Python操作HBase

下面以Python为例来演示如何访问HBase。

安装依赖包

sudo pip install thrift
sudo pip install hbase-thrift

Demo程序

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

执行结果:

['test']
[TRowResult(columns={'cf:a': TCell(timestamp=1488617173254, value='1')}, row='row-key1')]
the row is row-key1
the values is 1
 

python连接hbase的更多相关文章

  1. ambari安装集群下python连接hbase之安装thrift

    简介: python连接hbase是需要通过thrift连进行连接的,ambari安装的服务中貌似没有自带安装hbase的thrift,我是看配置hbase的配置名称里面没有thrift,cdh版本的 ...

  2. 【hbase】使用thrift with python 访问HBase

    HBase 版本: 0.98.6 thrift   版本: 0.9.0 使用 thrift client with python 连接 HBase 报错: Traceback (most recent ...

  3. python实现Hbase

    1. 下载thrift 作用:翻译python语言为hbase语言的工具 2. 运行时先启动hbase 再启动thrift,最后在pycharm中通过happybase包连接hbase 在hbase目 ...

  4. Hbase理论&&hbase shell&&python操作hbase&&python通过mapreduce操作hbase

    一.Hbase搭建: 二.理论知识介绍: 1Hbase介绍: Hbase是分布式.面向列的开源数据库(其实准确的说是面向列族).HDFS为Hbase提供可靠的底层数据存储服务,MapReduce为Hb ...

  5. 全网最详细的hive-site.xml配置文件里如何添加达到Hive与HBase的集成,即Hive通过这些参数去连接HBase(图文详解)

    不多说,直接上干货! 一般,普通的情况是 全网最详细的hive-site.xml配置文件里添加<name>hive.cli.print.header</name>和<na ...

  6. python 操作 hbase

    python 是万能的,当然也可以通过api去操作big database 的hbase了,python是通过thrift去访问操作hbase 以下是在centos7 上安装操作,前提是hbase已经 ...

  7. 【初学python】使用python连接mysql数据查询结果并显示

    因为测试工作经常需要与后台数据库进行数据比较和统计,所以采用python编写连接数据库脚本方便测试,提高工作效率,脚本如下(python连接mysql需要引入第三方库MySQLdb,百度下载安装) # ...

  8. python连接mysql的驱动

    对于py2.7的朋友,直接可以用MySQLdb去连接,但是MySQLdb不支持python3.x.这是需要注意的~ 那应该用什么python连接mysql的驱动呢,在stackoverflow上有人解 ...

  9. paip. 解决php 以及 python 连接access无效的参数量。参数不足,期待是 1”的错误

    paip. 解决php 以及 python 连接access无效的参数量.参数不足,期待是 1"的错误 作者Attilax  艾龙,  EMAIL:1466519819@qq.com  来源 ...

随机推荐

  1. Docker Swarm 服务编排之命令

    一.简介 Docker有个编排工具docker-compose,可以将组成某个应该的多个docker容器编排在一起,同时管理.同样在Swarm集群中,可以使用docker stack 将一组相关联的服 ...

  2. GO_10:GO语言基础之error

    Go错误处理 Go 语言通过内置的错误接口提供了非常简单的错误处理机制. error类型是一个接口类型,这是它的定义: type error interface { Error() string } ...

  3. 洛谷 p2530 化工场装箱员(资源型)

    化工场装箱员 https://www.luogu.org/problem/show?pid=2530 118号工厂是世界唯一秘密提炼锎的化工厂,由于提炼锎的难度非常高,技术不是十分完善,所以工厂生产的 ...

  4. JavaScript 延时与定时

    一.定时(setInterval) var i = 0; function hello(){ console.log(i++); } setInterval(hello,1000); // 每一秒执行 ...

  5. git提示error setting certificate verify locations解决办法

    先打开git bash窗口 执行命令: git config --system http.sslcainfo "C:\Program Files (x86)\git\bin\curl-ca- ...

  6. SpringCloud (十) Hystrix Dashboard单体监控、集群监控、与消息代理结合

    一.前言 Dashboard又称为仪表盘,是用来监控项目的执行情况的,本文旨在Dashboard的使用 分别为单体监控.集群监控.与消息代理结合. 代码请戳我的github 二.快速入门 新建一个Sp ...

  7. soj2013.Pay Back

    2013. Pay Back Constraints Time Limit: 1 secs, Memory Limit: 256 MB Description "Never a borrow ...

  8. windows 下 react-native(v0.56) Android 环境搭建踩坑记录

    debugservicereact-native 安装官网 https://reactnative.cn/docs/getting-started.html 根据官网步骤一步步执行下去.还能碰到一些问 ...

  9. 守卫者的挑战(guard)

    problem Pro 打开了黑魔法师Vani的大门,队员们在迷宫般的路上漫无目的地搜寻着关押applepi的监狱的所在地.突然,眼前一道亮光闪过.“我,Nizem,是黑魔法圣殿的守卫者.如果你能通过 ...

  10. redis安装(linux)

    一.redis安装步骤 1.yum install gcc  如果你机器已经安装了编译环境请忽略,否则在使用make编译源码时会报错. 报错信息:make: *** [adlist.o]  2.使用w ...