博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
RHadoop实践系列之四 rhbase安装与使用
阅读量:2720 次
发布时间:2019-05-13

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

,包含了R语言与Hadoop结合进行海量数据分析。Hadoop主要用来存储海量数据,R语言完成MapReduce 算法,用来替代Java的MapReduce实现。有了RHadoop可以让广大的R语言爱好者,有更强大的工具处理大数据1G, 10G, 100G, TB, PB。 由于大数据所带来的单机性能问题,可能会一去不复返了。

RHadoop实践是一套系列文章,主要包括””,””,”,””。对于单独的R语言爱好者,Java爱好者,或者Hadoop爱好者来说,同时具备三种语言知识并不容 易。此文虽为入门文章,但R,Java,Hadoop基础知识还是需要大家提前掌握。

关于作者:

  • 张丹(Conan), 程序员Java,R,PHP,Javascript
  • weibo:@Conan_Z
  • blog: 
  • email: bsspirit@gmail.com

转载请注明出处:

第四篇 HBase和rhbase的安装与使用,分为3个章节。

1. 环境准备及HBase安装2. rhbase安装3. rhbase程序用例

每一章节,都会分为”文字说明部分”和”代码部分”,保持文字说明与代码的连贯性。

注:Hadoop环境及RHadoop的环境,请查看同系列前二篇文章,此文将不再介绍。

1. 环境准备及HBase安装

文字说明部分:

首先环境准备,这里我选择了Linux Ubuntu操作系统12.04的64位版本,大家可以根据自己的使用习惯选择顺手的Linux。

但JDK一定要用Oracle SUN官方的版本,请从官网下载,操作系统的自带的OpenJDK会有各种不兼容。JDK请选择1.6.x的版本,JDK1.7版本也会有各种的不兼容情况。

Hadoop的环境安装,请参考RHadoop实践系统”Hadoop环境搭建”的一文。

Hadoop和HBase版本:hadoop-1.0.3,hbase-0.94.2

配置HBase的启动命令的环境变量,使用HBase自带的ZooKeeper

export HBASE_MANAGES_ZK=true

配置hbase-site.xml,设置访问目录,数据副本数,ZooKeeper的访问端口。

复制Hadoop环境的类库,覆盖HBase中的类库。

配置完成,启动HBase服务。

代码部分:

hbase安装

1) 下载安装hbase

~ http://www.fayea.com/apache-mirror/hbase/hbase-0.94.2/hbase-0.94.2.tar.gz~ tar xvf hbase-0.94.2.tar.gz

2) 修改配置文件

~ cd hbase-0.94.2/~ vi conf/hbase-env.sh     export JAVA_HOME=/root/toolkit/jdk1.6.0_29    export HBASE_HOME=/root/hbase-0.94.2    export HADOOP_INSTALL=/root/hadoop-1.0.3    export HBASE_CLASSPATH=/root/hadoop-1.0.3/conf    export HBASE_MANAGES_ZK=true~ vi conf/hbase-site.xml    
hbase.rootdir
hdfs://master:9000/hbase
hbase.cluster.distributed
true
dfs.replication
1
hbase.zookeeper.quorum
master
hbase.zookeeper.property.clientPort
2181
hbase.zookeeper.property.dataDir
/root/hadoop/hdata

3) 复制hadoop环境的配置文件和类库

~ cp ~/hadoop-1.0.3/conf/hdfs-site.xml ~/hbase-0.94.2/conf  ~ cp ~/hadoop-1.0.3/hadoop-core-1.0.3.jar ~/hbase-0.94.2/lib  ~ cp ~/hadoop-1.0.3/lib/commons-configuration-1.6.jar ~/hbase-0.94.2/lib  ~ cp ~/hadoop-1.0.3/lib/commons-collections-3.2.1.jar ~/hbase-0.94.2/lib

4) 启动hadoop和hbase

~/hadoop-1.0.3/bin/start-all.sh  ~/hbase-0.94.2/bin/start-hbase.sh

5) 查看hbase进行

~ jps    12041 HMaster    12209 HRegionServer    31734 TaskTracker    31343 DataNode    31499 SecondaryNameNode    13328 Jps    31596 JobTracker    11916 HQuorumPeer    31216 NameNode

6) 打开hbase命令行客户端

~/hbase-0.94.2/bin/hbase shellHBase Shell; enter 'help
' for list of supported commands.Type "exit
" to leave the HBase ShellVersion 0.94.2, r1395367, Sun Oct 7 19:11:01 UTC 2012hbase(main):001:0> list TABLE 0 row(s) in 0.0150 seconds

HBase安装完成。

2. rhbase安装

文字说明部分:

安装完成HBase后,我们还需要安装Thrift,因为rhbase是通过Thrift调用HBase的。

Thrift是需要本地编译的,官方没有提供二进制安装包,首先下载thrift-0.8.0。

在thrift解压目录输入./configure,会列Thrift在当前机器所支持的语言环境,如果只是为了rhbase默认配置就可以了。

在我的配置中除了希望支持rhbase访问,还支持PHP,Python,C++。因此需要在系统中,装一些额外的类库。大家可以根据自己的要求,设置Thrift的编译参数。

编译并安装Thrift,然后启动HBase的ThriftServer服务。

最后,安装rhbase。

代码部分:

  1. 下载thrift
    ~ wget http://archive.apache.org/dist/thrift/0.8.0/thrift-0.8.0.tar.gz~ tar xvf thrift-0.8.0.tar.gz~ cd thrift-0.8.0/
  2. 下载PHP支持类库(可选)
    ~ sudo apt-get install php-cli
  3. 下载C++支持类库(可选)
    ~ sudo apt-get install libboost-dev libboost-test-dev libboost-program-options-dev libevent-dev automake libtool flex bison pkg-config g++ libssl-dev
  4. 生成编译的配置参数
    ~ ./configure  thrift 0.8.0  Building code generators ..... :  Building C++ Library ......... : yes  Building C (GLib) Library .... : no  Building Java Library ........ : no  Building C# Library .......... : no  Building Python Library ...... : yes  Building Ruby Library ........ : no  Building Haskell Library ..... : no  Building Perl Library ........ : no  Building PHP Library ......... : yes  Building Erlang Library ...... : no  Building Go Library .......... : no  Building TZlibTransport ...... : yes  Building TNonblockingServer .. : yes  Using Python ................. : /usr/bin/python  Using php-config ............. : /usr/bin/php-config
  5. 编译和安装
    ~ make~ make install
  6. 查看thrift版本
    ~ thrift -version  Thrift version 0.8.0
  7. 启动HBase的Thrift Server
    ~ /hbase-0.94.2/bin/hbase-daemon.sh start thrift  ~ jps       12041 HMaster      12209 HRegionServer      13222 ThriftServer      31734 TaskTracker      31343 DataNode      31499 SecondaryNameNode      13328 Jps      31596 JobTracker      11916 HQuorumPeer      31216 NameNode
  8. 安装rhbase
    ~ R CMD INSTALL rhbase_1.1.1.tar.gz

很顺利的安装完成。

3. rhbase程序用例

文字说明部分:

rhbase的相关函数:

hb.compact.table      hb.describe.table     hb.insert             hb.regions.tablehb.defaults           hb.get                hb.insert.data.frame  hb.scanhb.delete             hb.get.data.frame     hb.list.tables        hb.scan.exhb.delete.table       hb.init               hb.new.table          hb.set.table.mode

hbase和rhbase的基本操作对比:

建表HBASE:     create 'student_shell','info'RHBASE:    hb.new.table("student_rhbase","info")列出所有表HBASE:     listRHBASE:    hb.list.tables()显示表结构HBASE:     describe 'student_shell'RHBASE:    hb.describe.table("student_rhbase")插入一条数据HBASE:     put 'student_shell','mary','info:age','19'RHBASE:    hb.insert("student_rhbase",list(list("mary","info:age", "24")))读取数据HBASE:     get 'student_shell','mary'RHBASE:    hb.get('student_rhbase','mary')删除表(HBASE需要两条命令,rhbase仅是一个操作)HBASE:     disable 'student_shell'HBASE:     drop 'student_shell'RHBASE:    hb.delete.table('student_rhbase')

代码部分:

Hbase Shell

> create 'student_shell','info'> list    TABLE    student_shell> describe 'student_shell'   DESCRIPTION                                                          ENABLED   {NAME => 'student_shell', FAMILIES => [{NAME => 'info', DATA_BLOCK_ true   ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0'   , VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL   => '2147483647', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536   ', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', BLOCKCACHE => 't   rue'}]}>  put 'student_shell','mary','info:age','19'>  get 'student_shell','mary'  COLUMN                      CELL  info:age                   timestamp=1365414964962, value=19> disable 'student_shell'> drop 'student_shell'

rhbase script

~ R> library(rhbase)> hb.init()    
attr(,"class") [1] "hb.client.connection" >hb.new.table("student_rhbase","info",opts=list(maxversions=5,x=list(maxversions=1L,compression='GZ',inmemory=TRUE))) [1] TRUE> hb.list.tables() $student_rhbase maxversions compression inmemory bloomfiltertype bloomfiltervecsize info: 5 NONE FALSE NONE 0 bloomfilternbhashes blockcache timetolive info: 0 FALSE -1 > hb.describe.table("student_rhbase") maxversions compression inmemory bloomfiltertype bloomfiltervecsize info: 5 NONE FALSE NONE 0 bloomfilternbhashes blockcache timetolive info: 0 FALSE -1> hb.insert("student_rhbase",list(list("mary","info:age", "24"))) [1] TRUE> hb.get('student_rhbase','mary') [[1]] [[1]][[1]] [1] "mary" [[1]][[2]] [1] "info:age" [[1]][[3]] [[1]][[3]][[1]] [1] "24"> hb.delete.table('student_rhbase') [1] TRUE

RHadoop实践系列文章的第四篇完成!希望这个四篇文章对大家有所帮助。

稍后我可能还会写一些,关于rmr算法实践,rhadoop架构方面和hive的使用的相关文章。
欢迎大家多提问题,多交流。

转载请注明出处:

打赏作者

This entry was posted in ,

你可能感兴趣的文章
敏捷开发之Scrum扫盲篇
查看>>
遇到Nand Flash坏块怎么处理?
查看>>
mount ,mkfs 工具详细说明(ext4,xfs)
查看>>
oracle 把一张表中的某字段的多条记录用逗号连接
查看>>
oracle按每天,每周,每月,每季度,每年查询统计数据
查看>>
TCP/IP概述
查看>>
ARP和RARP
查看>>
IP协议家族
查看>>
Linux设备驱动编程之阻塞与非阻塞
查看>>
Linux常用命令(一)
查看>>
Linux常用命令(二)
查看>>
Linux用户和文件权限管理
查看>>
Ionic3学习笔记(一)安装、项目结构与常用命令
查看>>
Ionic3学习笔记(二)主题化
查看>>
Ionic3学习笔记(三)禁止横屏
查看>>
Linux查找和筛选工具
查看>>
Angular学习笔记(一)
查看>>
Ionic3学习笔记(五)动画之使用 animate.css
查看>>
Ionic3学习笔记(六)存储之使用 SQLite
查看>>
CGRectGet方法解释
查看>>