安装HBase

HBase是一个构建在HDFS上的分布式列存储系统,主要用于海量结构化数据存储。这里,我们的目标只是为Python访问HBase提供一个基本的环境,故直接下载二进制包,采用单机安装。下载后解压,修改配置文件,然后可以直接启动HBase了。所用系统版本为ubuntu14.04。

下载

  1. wget https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/1.2.4/hbase-1.2.4-bin.tar.gz
  2. tar zxvf hbase-1.2.4-bin.tar.gz

配置

修改hbase-env.sh,设置JAVA_HOME。

  1. export JAVA_HOME=/usr/lib/jvm/java-8-oracle

修改hbase-site.xml,设置存储数据的根目录。

  1. <configuration>
  2. <property>
  3. <name>hbase.rootdir</name>
  4. <value>file:///home/mi/work/hbase/data</value>
  5. </property>
  6. </configuration>

启动

  1. bin/start-hbase.sh # 启动
  2. bin/hbase shell # 进入hbase交互shell

安装Thrift

安装好HBase之后,还需安装Thrift,因为其他语言调用HBase时,需要通过Thrift进行连接。

安装Thrift依赖

  1. 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下载地址

  1. tar zxf thrift-0.10.0.tar.gz
  2. cd thrift-0.10.0/
  3. ./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
  4. make # 编译耗时较长
  5. sudo make install

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

启动HBase的Thrift服务

  1. bin/hbase-daemon.sh start thrift

检查系统进程

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

Python操作HBase

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

安装依赖包

  1. sudo pip install thrift
  2. sudo pip install hbase-thrift

Demo程序

  1. from thrift import Thrift
  2. from thrift.transport import TSocket
  3. from thrift.transport import TTransport
  4. from thrift.protocol import TBinaryProtocol
  5. from hbase import Hbase
  6. from hbase.ttypes import *
  7. transport = TSocket.TSocket('localhost', 9090)
  8. transport = TTransport.TBufferedTransport(transport)
  9. protocol = TBinaryProtocol.TBinaryProtocol(transport)
  10. client = Hbase.Client(protocol)
  11. transport.open()
  12. contents = ColumnDescriptor(name='cf:', maxVersions=1)
  13. # client.deleteTable('test')
  14. client.createTable('test', [contents])
  15. print client.getTableNames()
  16. # insert data
  17. transport.open()
  18. row = 'row-key1'
  19. mutations = [Mutation(column="cf:a", value="1")]
  20. client.mutateRow('test', row, mutations)
  21. # get one row
  22. tableName = 'test'
  23. rowKey = 'row-key1'
  24. result = client.getRow(tableName, rowKey)
  25. print result
  26. for r in result:
  27. print 'the row is ', r.row
  28. print 'the values is ', r.columns.get('cf:a').value

执行结果:

  1. ['test']
  2. [TRowResult(columns={'cf:a': TCell(timestamp=1488617173254, value='1')}, row='row-key1')]
  3. the row is row-key1
  4. 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. 十、Shell基础

    一.shell概述 1.Shell是什么 shell是一个命令行解释器,他为用户提供了一个向linux内核发送请求以便运行程序的界面系统级程序,用户可以用shell来启动.挂起.停止甚至编写一些程序 ...

  2. python3.5无法安装pip,报错ImportError: cannot import name 'HTTPSHandler'

    本人系统为:centos6 解决方法: 1  安装openssl yum install openssl 2  安装openssl-devel yum install openssl-devel 3  ...

  3. P2043 质因子分解

    P2043 质因子分解 题目描述 对N!进行质因子分解. 输入输出格式 输入格式: 输入数据仅有一行包含一个正整数N,N<=10000. 输出格式: 输出数据包含若干行,每行两个正整数p,a,中 ...

  4. java基础-数组的折半查找原理

    java基础-数组的折半查找原理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 如果让你写一个数组的查找功能,需求如下:在一个数组中,找一个元素,是否存在于数组中, 如果存在就返回 ...

  5. JavaScript中replace()方法的第二个参数解析

    语法 string.replace(searchvalue,newvalue) 参数值 searchvalue 必须.规定子字符串或要替换的模式的 RegExp 对象.请注意,如果该值是一个字符串,则 ...

  6. Chrome浏览器F12讲解

    Chrome浏览器相对于其他的浏览器而言,DevTools(开发者工具)非常强大.这节课将为大家介绍怎么利用Chrome浏览器的开发者工具进行HTTP请求分析 Chrome浏览器讲解 Chrome 开 ...

  7. [转载]教你如何塑造JavaScript牛逼形象

    http://www.html5cn.org/article-6571-1.html 如何写JavaScript才能逼格更高呢?怎样才能组织JavaScript才能让别人一眼看出你不简单呢?是否很期待 ...

  8. UVA1386 【Cellular Automaton】题解

    题面:UVA1386 Cellular Automaton 矩阵乘法+快速幂解法: 这是一个比较裸的有点复杂需要优化的矩乘快速幂,所以推荐大家先做一下下列洛谷题目练练手: (会了,差不多就是多倍经验题 ...

  9. 59、synchronized同步代码块

    synchronized同步方法的问题 有些情况下,在方法上面加synchronized同步,会有性能问题.请看下面代码,来计算下两个线程执行的耗时: package com.sutaoyu.Thre ...

  10. Python练习-装饰器版-为什么我的用户总被锁定

    参考代码如下: 1.用户登录程序流程控制代码: # 编辑者:闫龙 if __name__ == '__main__': import UserLoginFuncation LoclCount=[]; ...