安装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. codeforces.com/contest/251/problem/C

    C. Number Transformation time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. 执行composer install后报错:执行composer install后报错: d11wtq/boris v1.0.10 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system.

    执行composer install后报错: d11wtq/boris v1.0.10 requires ext-pcntl * -> the requested PHP extension p ...

  3. Redis 3.2.8集群+Sentinel部署

    Redis3.2.8集群搭建 采用官方推荐的三主三从分片方案,本例中所有节点部署在一台主机上. 软件安装: tar zxvf redis-3.2.8.tar.gz cd  redis-3.2.8 ma ...

  4. python 套接字之select poll epoll

    python下的select模块使用 以及epoll与select.poll的区别 先说epoll与select.poll的区别(总结) select, poll, epoll 都是I/O多路复用的具 ...

  5. SFTP上传下载文件、文件夹常用操作

    SFTP上传下载文件.文件夹常用操作 1.查看上传下载目录lpwd 2.改变上传和下载的目录(例如D盘):lcd  d:/ 3.查看当前路径pwd 4.下载文件(例如我要将服务器上tomcat的日志文 ...

  6. newcoder Wannafly挑战赛4 树的距离

    https://www.nowcoder.com/acm/contest/35/D 假设要查询x的子树中,与x的距离>=y的距离和 那么如果有这么一个 由x的子树中的点到x的距离构成的序列,且按 ...

  7. call 大佬 help7——kmp 补齐 循环节

    http://acm.hdu.edu.cn/showproblem.php?pid=3746 用kmp算法,那么 但是也等于上面的是正确的 也等于下面是错误的 why? #include<cst ...

  8. http协议POST请求头content-type主要的四种取值

    介绍: 在此之前对content-type理解很肤浅,因此必须记录下来现在的理解,以便回顾 Content-Type,从名字上可以理解为内容类型,但在互联网上专业术语叫“媒体类型”,即MediaTyp ...

  9. 为什么C++空类的实例大小为1

    [为什么C++空类的实例大小为1] 每个实例在内存中都有一个独一无二的地址,为了达到这个目的,编译器往往会给一个空类隐含的加一个字节,这样空类在实例化后在内存得到了独一无二的地址.所以大小为1. 参考 ...

  10. windebug分析高cpu问题

    分析高CPU的关键是找到哪个线程是持续运行,占用CPU时间. 可以隔上两分钟连续抓两个dump文件,使用 !runaway 查看线程运行的时间 通过对比两个dump文件的线程时间,看看哪个线程运行的时 ...