阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

HBase入门基础教程

132次阅读
没有评论

共计 58805 个字符,预计需要花费 148 分钟才能阅读完成。

在本篇文章中,我们将介绍 Hbase 的单机模式安装与伪分布式的安装方式,以及通过浏览器查看 Hbase 的用户界面。搭建 HBase 伪分布式环境的前提是我们已经搭建好了 Hadoop 完全分布式环境,搭建 Hadoop 环境请参考:【Hadoop 入门基础教程】4、Hadoop 之完全分布式环境搭建

开发环境


硬件环境:CentOS 6.5 服务器 4 台(一台为 Master 节点,三台为 Slave 节点)
软件环境:Java 1.7.0_45、Eclipse Juno Service Release 2、hadoop-1.2.1、hbase-0.94.20。

1、HBase 安装


1)下载安装包

hbase-090.3.tar.gz 版本与 hadoop-1.2.1 良好兼容,从官网下载 hbase-090.3.tar.gz 安装包,并将下载的 hbase-090.3.tar.gz 拷贝到 /home/hadoop 目录下。hbase 官网下载地址:http://archive.apache.org/dist/hbase/
选择 HBase-0.94.20 版本,下载 HBase Releases.

2)解压安装包

[hadoop@K-Master ~]$ cd /usr
[hadoop@K-Master usr]$ sudo tar -xvf /home/hadoop/hbase-090.3.tar.gz   #解压安装源码包
[hadoop@K-Master usr]$ mv hbase-090.3 hbase    #重命名
[hadoop@K-Master usr]$ cd hbase
[hadoop@K-Master hbase]$ sudo chown -R hadoop:hadoop hbase #赋予 hbase 安装目录下所有文件 hadoop 权限

3)配置安装路径

# 将 hbase 下的 bin 目录添加到系统的 path 中,在 /etc/profile 文件尾行添加如下的内容
[hadoop@K-Master usr]$ sudo vim /etc/profile
export  PATH=$PATH:/usr/hbase/bin
#执行 source 命令使上述配置在当前终端立即生效
[hadoop@K-Master usr]$ source /etc/profile

4)验证是否安装成功

[hadoop@K-Master usr]$ hbase version
14/07/21 18:01:57 INFO util.VersionInfo: HBase 0.94.20
14/07/21 18:01:57 INFO util.VersionInfo: Subversion git://newbunny/home/lars/dev/hbase-0.94 -r 09c60d770f2869ca315910ba0f9a5ee9797b1edc
14/07/21 18:01:57 INFO util.VersionInfo: Compiled by lars on Fri May 23 22:00:41 PDT 2014

看到以上打印消息表示 Hbase 已经安装成功,接下来将分别进行 Hbase 单机模式和伪分布式模式的配置。

2、HBase 单机模式


1)配置 /conf/hbase-env.sh

将 JAVA_HOME 变量设置为 Java 安装的根目录,配置如下所示:

[hadoop@K-Master hbase]$ vim conf/hbase-env.sh
#对 hbase-env.sh 文件做如下修改:export JAVA_HOME=/usr/java/jdk1.7.0_65  #配置本机的 java 安装根目录
export HBASE_MANAGES_ZK=true        #配置由 hbase 自己管理 zookeeper,不需要单独的 zookeeper。

2)配置 /conf/hbase-site.xml

在启动 Hbase 前需要设置属性 hbase.rootdir,用于指定 Hbase 数据的存储位置,此处设置为 HBase 安装目录下的 hbase-tmp 文件夹即(file:///usr/hbase/hbase-tmp),配置如下:

[hadoop@K-Master hbase]$ vim conf/hbase-site.sh
<configuration>
    <property>
        <name>hbase.rootdir</name>
        <value>file:///usr/hbase/hbase-tmp</value>
    </property>
</configuration>

特别注意:hbase.rootdir 默认为 /tmp/hbase-${user.name}, 这意味着每次重启系统都会丢失数据。

3)启动 Hbase

 [hadoop@K-Master hbase]$ start-hbase.sh 
starting master, logging to /usr/hbase/bin/../logs/hbase-hadoop-master-K-Master.localdomain.out

4)进入 shell 模式

进入 shell 模式之后,通过 status 命令查看 Hbase 的运行状态,通过 exit 命令退出 shell。

[hadoop@K-Master hbase]$ hbase shell

HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.94.20, r09c60d770f2869ca315910ba0f9a5ee9797b1edc, Fri May 23 22:00:41 PDT 2014

hbase(main):001:0> status
1 servers, 0 dead, 2.0000 average load
hbase(main):002:0> exit

5)停止 HBase

[hadoop@K-Master hbase]$ stop-hbase.sh 
stopping hbase.....................

特别注意:如果在操作 Hbase 的过程中发生错误,可以通过 {HBASE_HOME} 目录(/usr/hbase)下的 logs 子目录中的日志文件查看错误原因。

3、HBase 伪分布式模式


1)配置 /conf/hbase-env.sh

添加变量 HBASE_CLASSPATH,并将路径设置为本机 Hadoop 安装目录下的 conf 目录(即{HADOOP_HOME}/conf)。修改完成后,hbase-env.sh 的配置如下:

[hadoop@K-Master hbase]$ vim conf/hbase-env.sh
export JAVA_HOME=/usr/java/jdk1.7.0_65
export HBASE_CLASSPATH=/usr/hadoop/conf 
export HBASE_MANAGES_ZK=true

2)配置 /conf/hbase-site.xml

修改 hbase.rootdir,将其指向 K -Master(与 hdfs 的端口保持一致),并指定 HBase 在 HDFS 上的存储路径。将属性 hbase.cluter.distributed 设置为 true。假设当前 Hadoop 集群运行在伪分布式模式下,且 NameNode 运行在 9000 端口;

[hadoop@K-Master hbase]$ vim hbase-site.xml 
<configuration>
    <property>
        <name>hbase.rootdir</name>
        <value>hdfs://K-Master:9000/hbase</value>
    </property>
    <property>
        <name>hbase.cluster.distributed</name>
        <value>true</value>
    </property>
</configuration>

3)启动 HBase

完成以上操作后启动 HBase,启动顺序:先启动 Hadoop–> 再启动 HBase,关闭顺序:先关闭 HBase–> 再关闭 Hadoop。

第一步:启动 hadoop 集群

[hadoop@K-Master hbase]$ start-all.sh          #启动 hadoop
[hadoop@K-Master hbase]$ jps               #查看进程
9040 DataNode
18205 Jps
9196 SecondaryNameNode
10485 JobTracker
10620 TaskTracker
8902 NameNode

特别注意:读者可先通过 jps 命令查看 Hadoop 集群是否启动,如果 Hadoop 集群已经启动,则不需要执行 Hadoop 集群启动操作。

第二步:启动 HBase

[hadoop@K-Master lib]$ start-hbase.sh          #启动 Hbase
K-Master: starting zookeeper, logging to /usr/hbase/bin/../logs/hbase-hadoop-zookeeper-K-Master.localdomain.out
starting master, logging to /usr/hbase/bin/../logs/hbase-hadoop-master-K-Master.localdomain.out
K-Master: starting regionserver, logging to /usr/hbase/bin/../logs/hbase-hadoop-regionserver-K-Master.localdomain.out
[hadoop@K-Master lib]$ jps                 #查看进程
9040 DataNode
18889 HMaster
19201 Jps
9196 SecondaryNameNode
19073 HRegionServer
10485 JobTracker
10620 TaskTracker
18818 HQuorumPeer
8902 NameNode

4)进入 shell 模式

进入 shell 模式之后,通过 list 命令查看当前数据库所有表信息,通过 create 命令创建一个 member 表,其拥有 member_id,address,info 三个列族,通过 describe 命令查看 member 表结构,通过 exit 命令退出 HBase shell 模式。

[hadoop@K-Master hadoop]$ hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.94.20, r09c60d770f2869ca315910ba0f9a5ee9797b1edc, Fri May 23 22:00:41 PDT 2014

hbase(main):001:0> create 'member','member_id','address','info'
0 row(s) in 2.7170 seconds

hbase(main):002:0> list
TABLE   
member  
1 row(s) in 0.0550 seconds

hbase(main):003:0> describe 'member'
DESCRIPTION  ENABLED
 'member', {NAME => 'address', DATA_BLOCK_ENCODING = true   
 > '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 =>
  'true'}, {NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => 
 '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VE
 RSIONS => '0', TTL => '2147483647', KEEP_DELETED_CE
 LLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 
 'false', ENCODE_ON_DISK => 'true', BLOCKCACHE => 't
 rue'}, {NAME =>'member_id', DATA_BLOCK_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 => 
 'true'}
1 row(s) in 0.1040 seconds

hbase(main):004:0> exit

5)查看 HDFS 的 HBase 数据库文件

通过 hadoop fs –ls /hbase 命令查看 HBase 分布式数据库在 HDFS 上是否成功创建,/hbase/member 文件夹即为上一步我们所建立的 member 数据库在 HDFS 上的存储位置。

[hadoop@K-Master conf]$ hadoop fs -ls /hbase
Found 8 items
drwxr-xr-x   - hadoop supergroup  0 2014-07-21 19:46 /hbase/-ROOT-
drwxr-xr-x   - hadoop supergroup  0 2014-07-21 19:46 /hbase/.META.
drwxr-xr-x   - hadoop supergroup  0 2014-07-22 11:38 /hbase/.logs
drwxr-xr-x   - hadoop supergroup  0 2014-07-22 11:39 /hbase/.oldlogs
drwxr-xr-x   - hadoop supergroup  0 2014-07-22 11:40 /hbase/.tmp
-rw-r--r--   1 hadoop supergroup 38 2014-07-21 19:46 /hbase/hbase.id
-rw-r--r--   1 hadoop supergroup  3 2014-07-21 19:46 /hbase/hbase.version
drwxr-xr-x   - hadoop supergroup  0 2014-07-22 11:40 /hbase/member

6)HBase 用户界面:
通过下面的链接可以访问 Hbase 的一些相关信息,链接说明如下表格所示:

HBase 入门基础教程

7)停止 HBase

完成上述操作后,执行关闭 HBase 操作,关闭顺序:先关闭 HBase —> 再关闭 Hadoop。

[hadoop@K-Master hadoop]$ stop-hbase.sh    #停止 Hbase
stopping hbase..................
K-Master: stopping zookeeper.

[hadoop@K-Master hadoop]$ stop-all.sh  #停止 Hadoop
stopping jobtracker
K-Master: stopping tasktracker
stopping namenode
K-Master: stopping datanode
K-Master: stopping secondarynamenode

4、HBase 的用户界面


1)HDFS 主页

输入 http://{主机名}:50070/dfshealth.jsp 进入 HDFS 主页,在该主页点击“Browse the filesystem”超链接,选择 hbase 目录,可以查看 HBase 在 HDFS 上生成的 /hbase 目录结构,该目录用于存放 Hbase 数据,如下图所示;

HBase 入门基础教程

2)Master 页面

通过地址 http://{主机名}:60010/master.jsp 可以查看 HBase 的相关信���,如下图所示。

HBase 入门基础教程

主要包含的信息如下:

  • Attributes 信息

Master 属性信息包含了当前集群的详细信息,从上往下依次为 HBase 的版本及编译信息、Hadoop 的版本及编译信息、HBase 根目录的路径、Region 服务器的平均负载以及 ZooKeeper Quorums 的地址。

HBase 入门基础教程

  • Tables 信息

用户表信息给出了 HBase 中的表信息及相关属性,目录表信息包含两个目录表:-ROOT- 和.META.;

HBase 入门基础教程

点击上图 [Details] 链接,跳转到 Tables Details 界面,如下图所示:

HBase 入门基础教程

  • Region Servers 信息

Region 服务器信息给出了所有 Region 服务器的地址,如下图所示;

HBase 入门基础教程

3)ZooKeeper 页面

通过 Master 页面中 Master 属性提供的链接,可以进入 ZooKeeper 页面,该页面显示了 HBase 的根目录、省前的主 Master 地址、保存 -ROOT- 表的 Region 服务器的地址、其他 Region 服务器的地址及 ZooKeeper 的一些内部信息,如下图所示。

HBase 入门基础教程

4)用户表页面

通过 Master 页面中用户表信息提供的链接 http://{主机名}:60010/table.jsp?name=user,可以进入用户表页面,如下图所示。该页面给出了表当前是否可用以及表在 Region 服务器上的信息。同时提供了根据行键合并及拆分表的操作。

HBase 入门基础教程

5)Region 服务器页面

通过 Master 页面中 Region 服务器信息提供的链接,可以进入 Region 服务器页面,该页面显示了 Region 服务器的基本属性和其上所有 Regions 的信息,如下图所示。

HBase 入门基础教程

参考

http://hbase.apache.org/book.html#_getting_started

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2015-03/114670p2.htm

————————————– 分割线 ————————————–

Hadoop+HBase 搭建云存储总结 PDF http://www.linuxidc.com/Linux/2013-05/83844.htm

HBase 结点之间时间不一致造成 regionserver 启动失败 http://www.linuxidc.com/Linux/2013-06/86655.htm

Hadoop+ZooKeeper+HBase 集群配置 http://www.linuxidc.com/Linux/2013-06/86347.htm

Hadoop 集群安装 &HBase 实验环境搭建 http://www.linuxidc.com/Linux/2013-04/83560.htm

基于 Hadoop 集群的 HBase 集群的配置 http://www.linuxidc.com/Linux/2013-03/80815.htm‘

Hadoop 安装部署笔记之 -HBase 完全分布模式安装 http://www.linuxidc.com/Linux/2012-12/76947.htm

单机版搭建 HBase 环境图文教程详解 http://www.linuxidc.com/Linux/2012-10/72959.htm

上一篇我们介绍了 Hbase 的单机模式安装与伪分布式的安装方式,本篇我们将详细介绍如何搭建 hbase 完全分布式环境,搭建 hbase 完全分布式环境的前提是我们已经搭建好了 Hadoop 完全分布式环境,搭建 hadoop 完全分布式环境请参考:【Hadoop 入门基础教程】4、Hadoop 之完全分布式环境搭建

开发环境


硬件环境:CentOS 6.5 服务器 4 台(一台为 Master 节点,三台为 Slave 节点)
软件环境:Java 1.7.0_45、Eclipse Juno Service Release 2、hadoop-1.2.1、hbase-0.94.20。

1、HBase 集群分布表


Hadoop 完全分布式环境和 HBase 完全分布式集群分别搭建成功后,Hadoop 集群中每个节点的角色如下表所示:

HBase 入门基础教程

2、HBase 集群安装


参照”【HBase 基础教程】1、HBase 之单机模式与伪分布式模式安装 1、HBase 安装”完成集群中所有机器 HBase 的安装。

3、配置 hbase-env.sh


编辑集群中所有机器的 conf/hbase-env.sh,命令如下:

[hadoop@K-Master hbase]$ vi /home/hbase/conf/hbase-env.sh

export JAVA_HOME=/usr/java/jdk1.7.0_65
export HBASE_CLASSPATH=/usr/hadoop/conf 
export HBASE_MANAGES_ZK=true        #此配置信息,设置由 hbase 自己管理 zookeeper,不需要单独的 zookeeper。export HBASE_HOME=/home/hbase
export HADOOP_HOME=/home/hadoop 
export HBASE_LOG_DIR=/home/hbase/logs    #Hbase 日志目录

4、配置 hbase-site.xml


编辑所有机器上的 hbase-site.xml 文件,命令如下:

[hadoop@K-Master hbase]$ vi /home/hbase/conf/hbase-site.sh
<configuration>
    <property>
     <name>hbase.rootdir</name>
     <value>hdfs://K-Master:9000/hbase</value>
    </property>
    <property>
     <name>hbase.cluster.distributed</name>
     <value>true</value>
    </property>
    <property>
    <name>hbase.master</name>
    <value>K-Master:60000</value>
    </property>
    <property>
     <name>hbase.zookeeper.quorum</name>
     <value>KVMSlave1,KVMSlave2,KVMSlave3</value>
    </property>
</configuration>

hbase-site.xml 配置文件中属性详细说明如下表所示:

HBase 入门基础教程

特别注意:
1)hbase.rootdir 属性值 HDFS 路径必须与你的 Hadoop 集群的 core-site.xml 文件配置保持完全一致;
2)hbase.zookeeper.quorum 的个数必须是奇数。
3)hbase.rootdir 默认为 /tmp/hbase-${user.name}, 这意味着每次重启系统都会丢失数据。

3、配置 regionservers


编辑所有 HRegionServers 节点的 regionservers 文件。修改 /home/hbase/conf 文件夹下的 regionservers 文件,添加 DataNode 节点的 hostname,命令如下:

[hadoop@K-Master hbase]$ vi /home/hbase/conf/regionservers
KVMSlave1
KVMSlave2
KVMSlave3

4、启动 HBase


集群中所有节点完成上述 HBase 部署之后,即可启动 HBase 集群。启动顺序:hadoop-> hbase,如果使用自己安装的 zookeeper 启动顺序是:hadoop-> zookeeper-> hbase
停止顺序:hbase-> zookeeper-> hadoop。

[hadoop@K-Master lib]$ start-hbase.sh          #启动 Hbase
#查看 K -Master 机器运行进程
[hadoop@K-Master ~]$ jps
24330 HMaster
4726 NameNode
4880 SecondaryNameNode
4998 JobTracker
9628 RunJar
24476 Jps
#查看 KVMSlave1 机器运行进程
[hadoop@KVMSlave1 usr]$ jps
10712 Jps
1429 DataNode
1506 TaskTracker
10573 HQuorumPeer
10642 HRegionServer
#查看 KVMSlave2 机器运行进程
[hadoop@KVMSlave2 usr]$ jps
9955 HRegionServer
1409 DataNode
9888 HQuorumPeer
1484 TaskTracker
10018 Jps
#查看 KVMSlave3 机器运行进程
[hadoop@KVMSlave3 usr]$ jps
11790 HRegionServer
1411 DataNode
1487 TaskTracker
11873 Jps
11723 HQuorumPeer

参考

http://hbase.apache.org/book.html#_getting_started

在本篇文章中,我们将介绍 Hbase 的单机模式安装与伪分布式的安装方式,以及通过浏览器查看 Hbase 的用户界面。搭建 HBase 伪分布式环境的前提是我们已经搭建好了 Hadoop 完全分布式环境,搭建 Hadoop 环境请参考:【Hadoop 入门基础教程】4、Hadoop 之完全分布式环境搭建

开发环境


硬件环境:CentOS 6.5 服务器 4 台(一台为 Master 节点,三台为 Slave 节点)
软件环境:Java 1.7.0_45、Eclipse Juno Service Release 2、hadoop-1.2.1、hbase-0.94.20。

1、HBase 安装


1)下载安装包

hbase-090.3.tar.gz 版本与 hadoop-1.2.1 良好兼容,从官网下载 hbase-090.3.tar.gz 安装包,并将下载的 hbase-090.3.tar.gz 拷贝到 /home/hadoop 目录下。hbase 官网下载地址:http://archive.apache.org/dist/hbase/
选择 HBase-0.94.20 版本,下载 HBase Releases.

2)解压安装包

[hadoop@K-Master ~]$ cd /usr
[hadoop@K-Master usr]$ sudo tar -xvf /home/hadoop/hbase-090.3.tar.gz   #解压安装源码包
[hadoop@K-Master usr]$ mv hbase-090.3 hbase    #重命名
[hadoop@K-Master usr]$ cd hbase
[hadoop@K-Master hbase]$ sudo chown -R hadoop:hadoop hbase #赋予 hbase 安装目录下所有文件 hadoop 权限

3)配置安装路径

# 将 hbase 下的 bin 目录添加到系统的 path 中,在 /etc/profile 文件尾行添加如下的内容
[hadoop@K-Master usr]$ sudo vim /etc/profile
export  PATH=$PATH:/usr/hbase/bin
#执行 source 命令使上述配置在当前终端立即生效
[hadoop@K-Master usr]$ source /etc/profile

4)验证是否安装成功

[hadoop@K-Master usr]$ hbase version
14/07/21 18:01:57 INFO util.VersionInfo: HBase 0.94.20
14/07/21 18:01:57 INFO util.VersionInfo: Subversion git://newbunny/home/lars/dev/hbase-0.94 -r 09c60d770f2869ca315910ba0f9a5ee9797b1edc
14/07/21 18:01:57 INFO util.VersionInfo: Compiled by lars on Fri May 23 22:00:41 PDT 2014

看到以上打印消息表示 Hbase 已经安装成功,接下来将分别进行 Hbase 单机模式和伪分布式模式的配置。

2、HBase 单机模式


1)配置 /conf/hbase-env.sh

将 JAVA_HOME 变量设置为 Java 安装的根目录,配置如下所示:

[hadoop@K-Master hbase]$ vim conf/hbase-env.sh
#对 hbase-env.sh 文件做如下修改:export JAVA_HOME=/usr/java/jdk1.7.0_65  #配置本机的 java 安装根目录
export HBASE_MANAGES_ZK=true        #配置由 hbase 自己管理 zookeeper,不需要单独的 zookeeper。

2)配置 /conf/hbase-site.xml

在启动 Hbase 前需要设置属性 hbase.rootdir,用于指定 Hbase 数据的存储位置,此处设置为 HBase 安装目录下的 hbase-tmp 文件夹即(file:///usr/hbase/hbase-tmp),配置如下:

[hadoop@K-Master hbase]$ vim conf/hbase-site.sh
<configuration>
    <property>
        <name>hbase.rootdir</name>
        <value>file:///usr/hbase/hbase-tmp</value>
    </property>
</configuration>

特别注意:hbase.rootdir 默认为 /tmp/hbase-${user.name}, 这意味着每次重启系统都会丢失数据。

3)启动 Hbase

 [hadoop@K-Master hbase]$ start-hbase.sh 
starting master, logging to /usr/hbase/bin/../logs/hbase-hadoop-master-K-Master.localdomain.out

4)进入 shell 模式

进入 shell 模式之后,通过 status 命令查看 Hbase 的运行状态,通过 exit 命令退出 shell。

[hadoop@K-Master hbase]$ hbase shell

HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.94.20, r09c60d770f2869ca315910ba0f9a5ee9797b1edc, Fri May 23 22:00:41 PDT 2014

hbase(main):001:0> status
1 servers, 0 dead, 2.0000 average load
hbase(main):002:0> exit

5)停止 HBase

[hadoop@K-Master hbase]$ stop-hbase.sh 
stopping hbase.....................

特别注意:如果在操作 Hbase 的过程中发生错误,可以通过 {HBASE_HOME} 目录(/usr/hbase)下的 logs 子目录中的日志文件查看错误原因。

3、HBase 伪分布式模式


1)配置 /conf/hbase-env.sh

添加变量 HBASE_CLASSPATH,并将路径设置为本机 Hadoop 安装目录下的 conf 目录(即{HADOOP_HOME}/conf)。修改完成后,hbase-env.sh 的配置如下:

[hadoop@K-Master hbase]$ vim conf/hbase-env.sh
export JAVA_HOME=/usr/java/jdk1.7.0_65
export HBASE_CLASSPATH=/usr/hadoop/conf 
export HBASE_MANAGES_ZK=true

2)配置 /conf/hbase-site.xml

修改 hbase.rootdir,将其指向 K -Master(与 hdfs 的端口保持一致),并指定 HBase 在 HDFS 上的存储路径。将属性 hbase.cluter.distributed 设置为 true。假设当前 Hadoop 集群运行在伪分布式模式下,且 NameNode 运行在 9000 端口;

[hadoop@K-Master hbase]$ vim hbase-site.xml 
<configuration>
    <property>
        <name>hbase.rootdir</name>
        <value>hdfs://K-Master:9000/hbase</value>
    </property>
    <property>
        <name>hbase.cluster.distributed</name>
        <value>true</value>
    </property>
</configuration>

3)启动 HBase

完成以上操作后启动 HBase,启动顺序:先启动 Hadoop–> 再启动 HBase,关闭顺序:先关闭 HBase–> 再关闭 Hadoop。

第一步:启动 hadoop 集群

[hadoop@K-Master hbase]$ start-all.sh          #启动 hadoop
[hadoop@K-Master hbase]$ jps               #查看进程
9040 DataNode
18205 Jps
9196 SecondaryNameNode
10485 JobTracker
10620 TaskTracker
8902 NameNode

特别注意:读者可先通过 jps 命令查看 Hadoop 集群是否启动,如果 Hadoop 集群已经启动,则不需要执行 Hadoop 集群启动操作。

第二步:启动 HBase

[hadoop@K-Master lib]$ start-hbase.sh          #启动 Hbase
K-Master: starting zookeeper, logging to /usr/hbase/bin/../logs/hbase-hadoop-zookeeper-K-Master.localdomain.out
starting master, logging to /usr/hbase/bin/../logs/hbase-hadoop-master-K-Master.localdomain.out
K-Master: starting regionserver, logging to /usr/hbase/bin/../logs/hbase-hadoop-regionserver-K-Master.localdomain.out
[hadoop@K-Master lib]$ jps                 #查看进程
9040 DataNode
18889 HMaster
19201 Jps
9196 SecondaryNameNode
19073 HRegionServer
10485 JobTracker
10620 TaskTracker
18818 HQuorumPeer
8902 NameNode

4)进入 shell 模式

进入 shell 模式之后,通过 list 命令查看当前数据库所有表信息,通过 create 命令创建一个 member 表,其拥有 member_id,address,info 三个列族,通过 describe 命令查看 member 表结构,通过 exit 命令退出 HBase shell 模式。

[hadoop@K-Master hadoop]$ hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.94.20, r09c60d770f2869ca315910ba0f9a5ee9797b1edc, Fri May 23 22:00:41 PDT 2014

hbase(main):001:0> create 'member','member_id','address','info'
0 row(s) in 2.7170 seconds

hbase(main):002:0> list
TABLE   
member  
1 row(s) in 0.0550 seconds

hbase(main):003:0> describe 'member'
DESCRIPTION  ENABLED
 'member', {NAME => 'address', DATA_BLOCK_ENCODING = true   
 > '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 =>
  'true'}, {NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => 
 '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VE
 RSIONS => '0', TTL => '2147483647', KEEP_DELETED_CE
 LLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 
 'false', ENCODE_ON_DISK => 'true', BLOCKCACHE => 't
 rue'}, {NAME =>'member_id', DATA_BLOCK_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 => 
 'true'}
1 row(s) in 0.1040 seconds

hbase(main):004:0> exit

5)查看 HDFS 的 HBase 数据库文件

通过 hadoop fs –ls /hbase 命令查看 HBase 分布式数据库在 HDFS 上是否成功创建,/hbase/member 文件夹即为上一步我们所建立的 member 数据库在 HDFS 上的存储位置。

[hadoop@K-Master conf]$ hadoop fs -ls /hbase
Found 8 items
drwxr-xr-x   - hadoop supergroup  0 2014-07-21 19:46 /hbase/-ROOT-
drwxr-xr-x   - hadoop supergroup  0 2014-07-21 19:46 /hbase/.META.
drwxr-xr-x   - hadoop supergroup  0 2014-07-22 11:38 /hbase/.logs
drwxr-xr-x   - hadoop supergroup  0 2014-07-22 11:39 /hbase/.oldlogs
drwxr-xr-x   - hadoop supergroup  0 2014-07-22 11:40 /hbase/.tmp
-rw-r--r--   1 hadoop supergroup 38 2014-07-21 19:46 /hbase/hbase.id
-rw-r--r--   1 hadoop supergroup  3 2014-07-21 19:46 /hbase/hbase.version
drwxr-xr-x   - hadoop supergroup  0 2014-07-22 11:40 /hbase/member

6)HBase 用户界面:
通过下面的链接可以访问 Hbase 的一些相关信息,链接说明如下表格所示:

HBase 入门基础教程

7)停止 HBase

完成上述操作后,执行关闭 HBase 操作,关闭顺序:先关闭 HBase —> 再关闭 Hadoop。

[hadoop@K-Master hadoop]$ stop-hbase.sh    #停止 Hbase
stopping hbase..................
K-Master: stopping zookeeper.

[hadoop@K-Master hadoop]$ stop-all.sh  #停止 Hadoop
stopping jobtracker
K-Master: stopping tasktracker
stopping namenode
K-Master: stopping datanode
K-Master: stopping secondarynamenode

4、HBase 的用户界面


1)HDFS 主页

输入 http://{主机名}:50070/dfshealth.jsp 进入 HDFS 主页,在该主页点击“Browse the filesystem”超链接,选择 hbase 目录,可以查看 HBase 在 HDFS 上生成的 /hbase 目录结构,该目录用于存放 Hbase 数据,如下图所示;

HBase 入门基础教程

2)Master 页面

通过地址 http://{主机名}:60010/master.jsp 可以查看 HBase 的相关信���,如下图所示。

HBase 入门基础教程

主要包含的信息如下:

  • Attributes 信息

Master 属性信息包含了当前集群的详细信息,从上往下依次为 HBase 的版本及编译信息、Hadoop 的版本及编译信息、HBase 根目录的路径、Region 服务器的平均负载以及 ZooKeeper Quorums 的地址。

HBase 入门基础教程

  • Tables 信息

用户表信息给出了 HBase 中的表信息及相关属性,目录表信息包含两个目录表:-ROOT- 和.META.;

HBase 入门基础教程

点击上图 [Details] 链接,跳转到 Tables Details 界面,如下图所示:

HBase 入门基础教程

  • Region Servers 信息

Region 服务器信息给出了所有 Region 服务器的地址,如下图所示;

HBase 入门基础教程

3)ZooKeeper 页面

通过 Master 页面中 Master 属性提供的链接,可以进入 ZooKeeper 页面,该页面显示了 HBase 的根目录、省前的主 Master 地址、保存 -ROOT- 表的 Region 服务器的地址、其他 Region 服务器的地址及 ZooKeeper 的一些内部信息,如下图所示。

HBase 入门基础教程

4)用户表页面

通过 Master 页面中用户表信息提供的链接 http://{主机名}:60010/table.jsp?name=user,可以进入用户表页面,如下图所示。该页面给出了表当前是否可用以及表在 Region 服务器上的信息。同时提供了根据行键合并及拆分表的操作。

HBase 入门基础教程

5)Region 服务器页面

通过 Master 页面中 Region 服务器信息提供的链接,可以进入 Region 服务器页面,该页面显示了 Region 服务器的基本属性和其上所有 Regions 的信息,如下图所示。

HBase 入门基础教程

参考

http://hbase.apache.org/book.html#_getting_started

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2015-03/114670p2.htm

————————————– 分割线 ————————————–

Hadoop+HBase 搭建云存储总结 PDF http://www.linuxidc.com/Linux/2013-05/83844.htm

HBase 结点之间时间不一致造成 regionserver 启动失败 http://www.linuxidc.com/Linux/2013-06/86655.htm

Hadoop+ZooKeeper+HBase 集群配置 http://www.linuxidc.com/Linux/2013-06/86347.htm

Hadoop 集群安装 &HBase 实验环境搭建 http://www.linuxidc.com/Linux/2013-04/83560.htm

基于 Hadoop 集群的 HBase 集群的配置 http://www.linuxidc.com/Linux/2013-03/80815.htm‘

Hadoop 安装部署笔记之 -HBase 完全分布模式安装 http://www.linuxidc.com/Linux/2012-12/76947.htm

单机版搭建 HBase 环境图文教程详解 http://www.linuxidc.com/Linux/2012-10/72959.htm

DDL(Data Definition Language)是数据库模式定义语言,是用于描述数据库中要存储的现实世界实体的语言,本节内容将执行关于 Hbase 的 DDL 操作,包括:数据库表的建立、查看所有表、查表结构、删除列族、删除表等操作。

开发环境


硬件环境:CentOS 6.5 服务器 4 台(一台为 Master 节点,三台为 Slave 节点)
软件环境:Java 1.7.0_45、Eclipse Juno Service Release 2、Hadoop-1.2.1、hbase-0.94.20。

1、一般操作


本小节的所有操作均是在 HBase 伪分布式配置模式下运行的,故需先运行 Hadoop 集群(如果已启动则不需再启动),再运行 HBase,最后进入 Hbase Shell 模式。

1)准备工作

# 启动 Hadoop 集群
[hadoop@K-Master hbase]$start-all.sh       #启动 hadoop
[hadoop@K-Master hbase]$jps                #查看进程
#启动 Hbase
[hadoop@K-Master hbase]$ start-hbase.sh        #启动 Hbase
[hadoop@K-Master hbase]$jps                #查看进程
#进入 shell 模式
[hadoop@K-Master hbase]$ hbase shell

2)查看 HBase 服务器状态信息

hbase(main):002:0> status
1 servers, 0 dead, 3.0000 average load

3)查看 HBase 版本信息

hbase(main):002:0> version
0.94.20, r09c60d770f2869ca315910ba0f9a5ee9797b1edc, Fri May 23 22:00:41 PDT 2014

2、DDL 操作


使用个人信息为列演示 HBase 的用法。创建一个 user 表,其结构如表所示。

HBase 入门基础教程

这里 address 和 info 对于表来说是一个有三个列的列族:address 列族由三个列 contry、province 和 city 组成;info 列族由三个列 age、birthday 和 company 组成。当然可以根据需要在 address 和 info 中建立更多的列族,如 name、telephone 等相应的列族加入 info 列族。

1)创建一个表 member

user 是表的名字,’user_id’,’address’,’info’分别为 user 表的三个列族。

hbase(main):002:0> create 'user','user_id','address','info'
0 row(s) in 1.4270 seconds

2)查看所有表

hbase(main):002:0> list
TABLE   
test
user
wordcount   
3 row(s) in 0.0950 seconds

3)查看表结构

hbase(main):002:0> describe 'user'
DESCRIPTION  ENABLED
 'user', {NAME => 'address', DATA_BLOCK_ENCODING =>  true   
 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE =>
  '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_V
 ERSIONS => '0', TTL => '2147483647', KEEP_DELETED_C
 ELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY =>
  'false', ENCODE_ON_DISK => 'true', BLOCKCACHE => 'true'}, {NAME => 'info', DATA_BLOCK_ENCODING => 'NO
 NE', BLOOMFILTER =>'NONE', REPLICATION_SCOPE =>'0
 ', VERSIONS =>'3', COMPRESSION =>'NONE', MIN_VERS
 IONS => '0', TTL => '2147483647', KEEP_DELETED_CELL
 S => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'f
 alse', ENCODE_ON_DISK =>'true', BLOCKCACHE =>'tru
 e'}, {NAME =>'user_id', DATA_BLOCK_ENCODING =>'NO
 NE', BLOOMFILTER =>'NONE', REPLICATION_SCOPE =>'0
 ', VERSIONS =>'3', COMPRESSION =>'NONE', MIN_VERS
 IONS => '0', TTL => '2147483647', KEEP_DELETED_CELL
 S => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'f
 alse', ENCODE_ON_DISK =>'true', BLOCKCACHE =>'tru
 e'}
1 row(s) in 0.0950 seconds

4)删除一个列族。

删除一个列族分为三步,第一步 disable 表,第二步 alter 表,第三步 enable 表;
在第一步创建 user 表时创建了三个列族,但是发现 user_id 这个列族是多余的,现在需要将其删除,操作如下:

第一步:disable 表

hbase(main):008:0> disable 'user'
row(s) in 1.3790 seconds

第二步:alter 表

hbase(main):010:0> alter 'user',{NAME=>'user_id',METHOD=>'delete'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 1.3660 seconds
hbase(main):010:0> describe 'user'
DESCRIPTION  ENABLED
 'user', {NAME => 'address', DATA_BLOCK_ENCODING =>  false  
 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE =>
  '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_V
 ERSIONS => '0', TTL => '2147483647', KEEP_DELETED_C
 ELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY =>
  'false', ENCODE_ON_DISK => 'true', BLOCKCACHE => 'true'}, {NAME => 'info', DATA_BLOCK_ENCODING => 'NO
 NE', BLOOMFILTER =>'NONE', REPLICATION_SCOPE =>'0
 ', VERSIONS =>'3', COMPRESSION =>'NONE', MIN_VERS
 IONS => '0', TTL => '2147483647', KEEP_DELETED_CELL
 S => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'f
 alse', ENCODE_ON_DISK =>'true', BLOCKCACHE =>'tru
 e'}
1 row(s) in 0.1050 seconds

第二步:enable 表

hbase(main):010:0> enable 'user'
0 row(s) in 1.3040 seconds

5)删除表

删除一个列族分为两步,第一步 disable 表,第二步 drop 表;

第一步:disable 表

hbase(main):010:0> list
TABLE   
test
user
wordcount   
hbase(main):015:0> disable 'test'
0 row(s) in 1.3530 seconds

第二步:drop 表

hbase(main):016:0> drop 'test'
0 row(s) in 1.5380 seconds

6)查询表是否存在

hbase(main):017:0> exists 'user'
Table user does exist   
0 row(s) in 0.3530 seconds

7)判断表是否 enable

hbase(main):018:0> is_enabled 'user'
true
0 row(s) in 0.0750 seconds

8)判断表是否 disable

hbase(main):019:0> is_disabled 'user'
false   
0 row(s) in 0.0600 seconds

DML(Data Manipulation Language)是数据操纵语言,用户通过它可以实现对数据库的基本操作。例如,对表中数据的查询、插入、删除和修改。在 DML 中,应用程序可以对数据库作插,删,改,排,检等五种操作。本节将针对 Hbase 数据库执行如下 DML 操作,包括:添加记录、查看记录、查看表中的记录总数,删除记录、删除一张表、查看某个列族的所有记录等。
HBase Shell 基本操作命令如表所示:

HBase 入门基础教程

开发环境


硬件环境:CentOS 6.5 服务器 4 台(一台为 Master 节点,三台为 Slave 节点)
软件环境:Java 1.7.0_45、Eclipse Juno Service Release 2、Hadoop-1.2.1、hbase-0.94.20。

1、向表 user 插入记录


1) 向 user 表的行键 andieguo 的 info 列族成员:age、birthday、compay 分别添加数据

# 语法:put <table>,<rowkey>,<family:column>,<value>,<timestamp>
# 例如:给表 user 的添加一行记录:<rowkey> 是 'andieguo',<family:column> 是 'info:age',value 是 '27',timestamp:系统默认
hbase(main):021:0> put 'user','andieguo','info:age','27'
hbase(main):022:0> put 'user','andieguo','info:birthday','1989-09-01'
hbase(main):026:0> put 'user','andieguo','info:company','zonesion'

2) 向 user 表的行键 andieguo 的 address 列族成员:contry、province、city 分别添加数据

# 语法:put <table>,<rowkey>,<family:column>,<value>,<timestamp>
# 例如:给表 user 的添加一行记录:<rowkey> 是 'andieguo',<family:column> 是 'address:contry',value 是 'china',timestamp:系统默认
hbase(main):028:0> put 'user','andieguo','address:contry','china'
hbase(main):029:0> put 'user','andieguo','address:province','wuhan'
hbase(main):030:0> put 'user','andieguo','address:city','wuhan'

2、获取一条记录


1) 获取一个 ID 的所有记录

# 语法:get <table>,<rowkey>,[<family:column>,....]
# 例如:查询 <table> 为 'user',<rowkey> 为 'andieguo' 下的所有记录
hbase(main):031:0> get 'user','andieguo'
COLUMNCELL  
 address:city timestamp=1409303693005, value=wuhan  
 address:contry   timestamp=1409303656326, value=china  
 address:province timestamp=1409303678219, value=wuhan  
 info:age timestamp=1409303518077, value=27 
 info:birthdaytimestamp=1409303557859, value=1989-09-01 
 info:company timestamp=1409303628168, value=zonesion   
6 row(s) in 0.0350 seconds

2) 获取一个 ID 的一个列族的所有数据

# 语法:get <table>,<rowkey>,[<family:column>,....]
# 例如:查询 <table> 为 'user',<rowkey> 为 'andieguo', <family> 为 'info' 下的所有记录
hbase(main):032:0> get 'user','andieguo','info'
COLUMNCELL  
 info:age timestamp=1409303518077, value=27 
 info:birthdaytimestamp=1409303557859, value=1989-09-01 
 info:company timestamp=1409303628168, value=zonesion   
3 row(s) in 0.0200 seconds

3) 获取一个 ID 的一个列族中的一个列的所有数据

# 语法:get <table>,<rowkey>,[<family:column>,....]
# 例如:查询 <table> 为 'user',<rowkey> 为 'andieguo', <family:column > 为 'info:age' 下的所有记录
hbase(main):034:0> get 'user','andieguo','info:age'
COLUMNCELL  
 info:age timestamp=1409303518077, value=27 
1 row(s) in 0.0240 seconds

3、更新一条记录


将 andieguo 的年龄修改为 28,命令如下:

hbase(main):035:0> put 'user','andieguo','info:age','28'
0 row(s) in 0.0090 seconds

hbase(main):036:0> get 'user','andieguo','info:age'
COLUMNCELL  
 info:age timestamp=1409304167955, value=28 
1 row(s) in 0.0160 seconds

4、获取指定版本的数据


hbase(main)::037:0> get 'user','andieguo',{COLUMN=>'info:age',TIMESTAMP=>1409304}
COLUMNCELL  
 info:age timestamp=1409304167955, value=28 
1 row(s) in 0.0090 seconds

5、全表扫描


hbase(main):042:0> scan 'user'
ROWCOLUMN+CELL
 andieguo  column=address:city, timestamp=1409303693005,value=wuhan
 andieguo  column=address:contry, timestamp=1409303656326,value=china   
 andieguo  column=address:province, timestamp=1409303678219,value=wuhan   
 andieguo  column=info:age, timestamp=1409304167955,value=28   
 andieguo  column=info:birthday, timestamp=1409303557859,value=1989-09-01
 andieguo  column=info:company, timestamp=1409303628168,value=zonesion   
1 row(s) in 0.0340 seconds

6、删除 ID 为”andieguo”的列为’info:age’字段


hbase(main):043:0> delete 'user','andieguo','info:age'
0 row(s) in 0.0200 seconds

hbase(main):044:0> get 'user','andieguo'
COLUMN CELL   
 address:city  timestamp=1409303693005,value=wuhan 
 address:contrytimestamp=1409303656326,value=china  
 address:province  timestamp=1409303678219,value=wuhan 
 info:birthday timestamp=1409303557859,value=1989-09-01  
 info:company  timestamp=1409303628168,value=zonesion
5 row(s) in 0.0180 seconds

7、查询表中有多少行


hbase(main):045:0> count 'user'
1 row(s) in 0.0770 seconds

8、向 ID 为”andieguo”添加’info:age’字段


1) 第一次添加(默认使用 counter 实现递增)

hbase(main):048:0> incr 'user','andieguo','info:age'
COUNTER VALUE = 1

hbase(main):052:0> get 'user','andieguo','info:age'
COLUMN CELL   
 info:age  timestamp=1409304832249, value=\x00\x00\x00\x00\x00\x00\x00\x01   
1 row(s) in 0.0150 seconds

2) 第二次添加(默认使用 counter 实现递增)

hbase(main):050:0> incr 'user','andieguo','info:age'
COUNTER VALUE = 2

hbase(main):052:0> get 'user','andieguo','info:age'
COLUMN CELL   
 info:age  timestamp=1409304832249, value=\x00\x00\x00\x00\x00\x00\x00\x02
1 row(s) in 0.0150 seconds

3) 获取当前的 COUNTER 值

hbase(main):053:0> get_counter 'user','andieguo','info:age'
COUNTER VALUE = 2

9、将表数据清空


hbase(main):054:0> truncate 'user'
Truncating 'user' table (it may take a while):
 - Disabling table...
 - Dropping table...
 - Creating table...
0 row(s) in 3.5320 seconds

可以看出,HBase 在执行 truncate 命令时,通过先对表执行 disable,再执行 drop 操作,最后执行重新建表来实现数据清空。

开发环境


硬件环境:CentOS 6.5 服务器 4 台(一台为 Master 节点,三台为 Slave 节点)
软件环境:Java 1.7.0_45、Eclipse Juno Service Release 2、Hadoop-1.2.1、hbase-0.94.20。

1、Hbase API 介绍


1)几个相关类与 HBase 数据模型之间的对应关系

HbaseAdmin 用于数据库的创建与删除,HbaseConfiguration 用于数据库的配置,Htable 用数据库表的相关操作,HtableDescriptor 用于数据库表列族的相关操作,Put 用于数据库表记录的添加,Get 用户数据库表记录的获取,Scanner 用于数据库表全表查询

HBase 入门基础教程

2)HBaseConfiguration

类名:org.apache.hadoop.hbase.HBaseConfiguration
作用:对 HBase 进行配置
常用方法:void set(String name, String value),通过属性名来设置值。
用法示例:

Configuration conf = HBaseConfiguration.create();  
conf.set("hbase.zookeeper.quorum", "Master");  

3)HBaseAdmin

类名:org.apache.hadoop.hbase.client.HBaseAdmin
作用:提供了一个接口来管理 HBase 数据库的表信息。它提供的方法包括:创建表,删除表,列出表项,使表有效或无效,以及添加或删除表列族成员等。

HBase 入门基础教程

4)HTableDescriptor

类名:org.apache.hadoop.hbase.HTableDescriptor
作用:包含了表的名字极其对应表的列族。
常用方法:void addFamily(HcolumnDescriptor family) 添加一个列族。其详细用法如下所示,向 tb_user 表中添加了一个 content 列族。

HTableDescriptor tableDescriptor = new HTableDescriptor("tb_user");  
HColumnDescriptor col = new HColumnDescriptor("content:");  
tableDescriptor.addFamily(col);  

5)HColumnDescriptor

类名:org.apache.hadoop.hbase.HColumnDescriptor
作用:维护着关于列族的信息,例如版本号,压缩设置等。它通常在创建表或者为表添加列族的时候使用。列族被创建后不能直接修改,只能通过删除然后重新创建的方式。列族被删除的时候,列族里面的数据也会同时被删除。

6)HTable

类名:org.apache.hadoop.hbase.client.HTable
作用:可以用来和 HBase 表直接通信。此方法对于更新操作来说是非线程安全的。
用法示例:

HTable table = null;
ResultScanner rs = null;
try {Scan scan = new Scan(); 
    table = new HTable(conf, tableName);
    rs = table.getScanner(scan);
} catch (IOException e) {e.printStackTrace();
}

HBase 入门基础教程

7)Put

类名:org.apache.hadoop.hbase.client.Put
作用:用来对单个行执行添加操作
用法示例:

HTable table = null;
try {table = new HTable(conf, tabelName);
    Put putRow1 = new Put(rowKey.getBytes());
    putRow1.add(family.getBytes(), qualifier.getBytes(),value.getBytes());
    table.put(putRow1);
    table.close();} catch (IOException e) {e.printStackTrace();
}

HBase 入门基础教程

8)Get

类名:org.apache.hadoop.hbase.client.Get
作用:用来获取单个行的相关信息
用法示例:

Get query = new Get(rowKey.getBytes());
query.addColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier));
if(table.exists(query)){Result result = table.get(query);
    System.out.format("ROW\t%s\n",new String(result.getRow()));
    for(KeyValue kv : result.raw()){System.out.format("COLUMN\t %S:%s\t%s\n",new String(kv.getFamily()),new String(kv.getQualifier()),new String(kv.getValue()));
    }
}

HBase 入门基础教程

2、HBase API 实战


1)创建表

create(String tableName,String… families)实现了创建名为 tablename 的表,同时添加若干 families 列族,列族个数不定,详细源码请参考:HBaseAPI/src/com/zonesion/hbase/CreateTable.java。

public static void create(String tableName,String... families) {Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.zookeeper.quorum", "Master");
    HBaseAdmin admin = null;
    try {admin = new HBaseAdmin(conf);
        HTableDescriptor tableDescriptor = new HTableDescriptor(tableName.getBytes());
        if (admin.tableExists(tableName)) {// 表存在
            System.out.println(tableName + "已经存在!");
        } else {for(String family :families){tableDescriptor.addFamily(new HColumnDescriptor(family));
            }
            admin.createTable(tableDescriptor);
        }
    } catch (MasterNotRunningException e) {e.printStackTrace();
    } 
}

2)添加记录

put(String tabelName,String rowKey,String family,String qualifier,String value)实现了向 tablename 表主键为 rowkey、列族为 family、列为 qualifier 添加值为 value 的记录,详细源码请参考:HBaseAPI/src/com/zonesion/hbase/PutRow.java。

public static void put(String tabelName,String rowKey,String family,String qualifier,String value) {Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.zookeeper.quorum", "Master");
    HTable table = null;
    try {table = new HTable(conf, tabelName);
        Put putRow1 = new Put(rowKey.getBytes());
        putRow1.add(family.getBytes(), qualifier.getBytes(),value.getBytes());
        table.put(putRow1);
        table.close();} catch (IOException e) {e.printStackTrace();
    }
}

3)获取记录

getRow(String tableName,String rowKey) 实现了获取 tablename 表主键为 rowkey 的所有记录,详细源码请参考:HBaseAPI/src/com/zonesion/hbase/GetRow.java。

public static void getRow(String tableName,String rowKey) {Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.zookeeper.quorum", "Master");
    HTable table = null;
    try {table = new HTable(conf, tableName);
        Get query = new Get(rowKey.getBytes());
        if(table.exists(query)){Result result = table.get(query);
            System.out.format("ROW\t%s\n",new String(result.getRow()));
            for(KeyValue kv : result.raw()){System.out.format("COLUMN\t %S:%s\t%s\n",new String(kv.getFamily()),new String(kv.getQualifier()),new String(kv.getValue()));
            }
        }
        table.close();} catch (IOException e) {e.printStackTrace();
    }
}

4)遍历表

list(String tableName)实现了遍历表 tableName,并打印所有遍历的记录,详细源码请参考:HBaseAPI/src/com/zonesion/hbase/GetScanner.java。

public static void list(String tableName) {Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.zookeeper.quorum", "Master");
    HTable table = null;
    ResultScanner rs = null;
    try {Scan scan = new Scan(); 
        table = new HTable(conf, tableName);
        rs = table.getScanner(scan);
        for(Result row : rs){System.out.format("ROW\t%s\n",new String(row.getRow()));
            for(Map.Entry<byte[], byte[]> entry : row.getFamilyMap("info".getBytes()).entrySet()){String column = new String(entry.getKey());
                String value = new String(entry.getValue());
                System.out.format("COLUMN\t info:%s\t%s\n",column,value);
            }
            for(Map.Entry<byte[], byte[]> entry : row.getFamilyMap("address".getBytes()).entrySet()){String column = new String(entry.getKey());
                String value = new String(entry.getValue());
                System.out.format("COLUMN\t address:%s\t%s\n",column,value);
            }
        }
    } catch (IOException e) {e.printStackTrace();
    } 
}

更多详细的用法请参考:HBaseAPI/src/com/zonesion/hbase 目录,其中 CreateTable.java 用于创建表,DeleteTable.java 用于删除表,FilterQuery.java 用于过滤查询,GetColumn.java 用于获取指定列记录,GetFamily.java 用于获取指定列族的所有记录,GetRow.java 用于获取指定 rowkey 的所有记录,GetScanner.java 用于遍历表,PutRow.java 用于添加记录,HBaseAPI.java 整合了上述所有资源以命令的形式进行调用,在实验过程中我们使用的 HBaseAPI.java 命令调用方式,用户也可单独执行以上所有资源。

3、部署运行


1)启动 Hadoop 集群和 Hbase 服务

[hadoop@K-Master ~]$ start-dfs.sh     #启动 hadoop HDFS 文件管理系统
[hadoop@K-Master ~]$ start-mapred.sh      #启动 hadoop MapReduce 分布式计算服务
[hadoop@K-Master ~]$ start-hbase.sh       #启动 Hbase
[hadoop@K-Master ~]$ jps              #查看进程
22003 HMaster
10611 SecondaryNameNode
22226 Jps
21938 HQuorumPeer
10709 JobTracker
22154 HRegionServer
20277 Main
10432 NameNode

特别注意:用户可先通过 jps 命令查看 Hadoop 集群和 Hbase 服务是否启动,如果 Hadoop 集群和 Hbase 服务已经启动,则不需要执行此操作。

2)部署源码

# 设置工作环境
[hadoop@K-Master ~]$ mkdir -p /usr/hadoop/workspace/Hbase
#部署源码
将 HBaseAPI 文件夹拷贝到 /usr/hadoop/workspace/Hbase/ 路径下;

… 你可以直接 下载 HBaseAPI

—————————————— 分割线 ——————————————

免费下载地址在 http://linux.linuxidc.com/

用户名与密码都是www.linuxidc.com

具体下载目录在 /2015 年资料 / 3 月 / 8 日 /HBase 入门基础教程 /

下载方法见 http://www.linuxidc.com/Linux/2013-07/87684.htm

—————————————— 分割线 ——————————————

3)修改配置文件

a)查看 hbase 核心配置文件 hbase-site.xml 的 hbase.zookeeper.quorum 属性
使用如下命令查看 hadoop 核心配置文件 hbase-site.xml 的 hbase.zookeeper.quorum 属性值,当前 K -Master 服务器的 hbase.zookeeper.quorum 属性值为 K -Master;

[hadoop@K-Master ~]$ cat /usr/hbase/conf/hbase-site.xml 
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="https://www.linuxidc.com/Linux/2015-03/configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->

<configuration>
   <!--zookeeper 运行的机器,要为奇数个,使得投票更公平 -->
<property>
<name>hbase.zookeeper.quorum</name>
<value>K-Master</value>
</property>
</configuration>

b)修改项目 HBaseAPI/src/config.properties 属性文件
将项目 HBaseAPI/src/config.properties 属性文件的 hbase.zookeeper.quorum 属性值修改为上一步查询到的属性值,保持 config.properties 文件的 hbase.zookeeper.quorum 属性值与 hbase-site.xml 文件的 hbase.zookeeper.quorum 属性值一致;

# 切换工作目录
[hadoop@K-Master ~]$ cd /usr/hadoop/workspace/Hbase/HBaseAPI/
#修改属性值
[hadoop@K-Master HBaseAPI]$ vim src/config.properties 
hbase.zookeeper.quorum=K-Master
#拷贝 src/config.properties 到 bin 文件夹
[hadoop@K-Master HBaseAPI]$ cp src/config.properties bin/

4)编译文件

# 执行编译
[hadoop@K-Master HBaseAPI]$ javac -classpath /usr/hadoop/hadoop-core-1.2.1.jar:/usr/hadoop/lib/commons-cli-1.2.jar:lib/zookeeper-3.4.5.jar:lib/hbase-0.94.20.jar -d bin/ src/com/zonesion/hbase/*.java
#查看编译是否成功
[hadoop@K-Master HBaseAPI]$ ls bin/com/zonesion/hbase/ -la
total 52
drwxrwxr-x 2 hadoop hadoop 4096 Dec 30 16:18 .
drwxrwxr-x 3 hadoop hadoop 4096 Dec 30 16:18 ..
-rw-rw-r-- 1 hadoop hadoop 3283 Dec 30 16:18 CreateTable.class
-rw-rw-r-- 1 hadoop hadoop 2702 Dec 30 16:18 DeleteTable.class
-rw-rw-r-- 1 hadoop hadoop 3781 Dec 30 16:18 FilterQuery.class
-rw-rw-r-- 1 hadoop hadoop 2870 Dec 30 16:18 GetColumn.class
-rw-rw-r-- 1 hadoop hadoop 2789 Dec 30 16:18 GetFamily.class
-rw-rw-r-- 1 hadoop hadoop 2511 Dec 30 16:18 GetRow.class
-rw-rw-r-- 1 hadoop hadoop 3519 Dec 30 16:18 GetScanner.class
-rw-rw-r-- 1 hadoop hadoop 3085 Dec 30 16:18 HBaseAPI.class
-rw-rw-r-- 1 hadoop hadoop 4480 Dec 30 16:18 PropertiesHelper.class
-rw-rw-r-- 1 hadoop hadoop 2148 Dec 30 16:18 PutRow.class

5)打包 Jar 文件

# 拷贝 lib 文件夹到 bin 文件夹
[hadoop@K-Master HBaseAPI]$ cp –r lib/ bin/
#打包 Jar 文件
[hadoop@K-Master HBaseAPI]$ jar -cvf HBaseAPI.jar -C  bin/ .
added manifest
adding: lib/(in = 0) (out= 0)(stored 0%)
adding: lib/zookeeper-3.4.5.jar(in = 779974) (out= 721150)(deflated 7%)
adding: lib/protobuf-java-2.4.0a.jar(in = 449818) (out= 420864)(deflated 6%)
adding: lib/hbase-0.94.20.jar(in = 5475284) (out= 5038635)(deflated 7%)
adding: com/(in = 0) (out= 0)(stored 0%)
adding: com/zonesion/(in = 0) (out= 0)(stored 0%)
adding: com/zonesion/hbase/(in = 0) (out= 0)(stored 0%)
adding: com/zonesion/hbase/GetScanner.class(in = 2681) (out= 1422)(deflated 46%)
adding: com/zonesion/hbase/GetColumn.class(in = 2229) (out= 1127)(deflated 49%)
adding: com/zonesion/hbase/DeleteTable.class(in = 2058) (out= 1162)(deflated 43%)
adding: com/zonesion/hbase/CreateTable.class(in = 2534) (out= 1395)(deflated 44%)
adding: com/zonesion/hbase/HBaseAPI.class(in = 2947) (out= 1319)(deflated 55%)
adding: com/zonesion/hbase/FilterQuery.class(in = 3114) (out= 1540)(deflated 50%)
adding: com/zonesion/hbase/GetRow.class(in = 1914) (out= 1017)(deflated 46%)
adding: com/zonesion/hbase/PutRow.class(in = 1600) (out= 888)(deflated 44%)
adding: com/zonesion/hbase/GetFamily.class(in = 2170) (out= 1106)(deflated 49%)

6)运行实例

a)Help 命令

[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI
HBaseAPI action ...
    create <tableName> [family...]  
    delete <tableName>
    put <tableName> <rowKey> <family> <column> <value> 
    scan <tableName> 
    get <tableName> <rowKey>    
    get <tableName> <rowKey> <family>   
    get <tableName> <rowKey> <family> <column>  

b)create 命令

# 查看 create 帮助命令
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI create
    create <tableName> [family...]
#创建 tb_admin 表,其中该表包含 info、address 两个列族
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI create tb_admin info address

c)put 命令

# 查看 put 帮助命令
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI put
    put <tableName> <rowKey> <family> <column> <value> 
#使用 put 命令向表为 tb_admin、<rowkey> 是 'andieguo' 添加一系列记录
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI put tb_admin andieguo info age 25
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI put tb_admin andieguo info birthday 1990-09-08
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI put tb_admin andieguo info company zonesion
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI put tb_admin andieguo address country China
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI put tb_admin andieguo address province hubei
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI put tb_admin andieguo address city wuhan

d)scan 命令

# 查看 scan 帮助命令
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI scan
    scan <tableName>
#使用 scan 命令查看 tb_admin 表里的所有记录 
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI scan tb_admin
ROW andieguo
COLUMN   info:age   25
COLUMN   info:birthday  1990-09-08
COLUMN   info:company   zonesion
COLUMN   address:city   wuhan
COLUMN   address:country    China
COLUMN   address:province   hubei

e)get 命令

# 查看 get 帮助命令
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI get
    get <tableName> <rowKey>    
    get <tableName> <rowKey> <family>   
    get <tableName> <rowKey> <family> <column>  
#使用 get 命令查看表 tb_admin 中 rowkey 为 andieguo 的所有记录
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI get tb_admin andieguo
ROW andieguo
COLUMN   ADDRESS:city   wuhan
COLUMN   ADDRESS:country    China
COLUMN   ADDRESS:province   hubei
COLUMN   INFO:age   25
COLUMN   INFO:birthday  1990-09-08
COLUMN   INFO:company   zonesion
#使用 get 命令查看表 tb_admin 中 rowkey 为 andieguo、列族为 info 的所有记录
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI get tb_admin andieguo info
ROW andieguo
COLUMN   INFO:age   25
COLUMN   INFO:birthday  1990-09-08
COLUMN   INFO:company   zonesion
#使用 get 命令查看表 tb_admin 中 rowkey 为 andieguo、info 为 age 的所有记录
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI get tb_admin andieguo info age
ROW andieguo
COLUMN   INFO:age   25

f)delete 命令

# 查看 delete 帮助命令
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI delete
    delete <tableName>
#使用 delete 命令删除 tb_admin 表
[hadoop@K-Master HBaseAPI]$ hadoop jar HBaseAPI.jar com.zonesion.hbase.HBaseAPI delete tb_admin
14/12/19 19:46:37 INFO client.HBaseAdmin: Disabled tb_admin
14/12/19 19:46:38 INFO client.HBaseAdmin: Deleted tb_admin
关闭 HBaseAdmin

本文将介绍利用 MapReduce 操作 HBase,借助最熟悉的单词计数案例 WordCount,将 WordCount 的统计结果存储到 HBase,而不是 HDFS。

开发环境


硬件环境:CentOS 6.5 服务器 4 台(一台为 Master 节点,三台为 Slave 节点)
软件环境:Java 1.7.0_45、Eclipse Juno Service Release 2、Hadoop-1.2.1、hbase-0.94.20。

1、输入与输出


1)输入文件

file0.txt(WordCountHbaseWriter\input\file0.txt)Hello World Bye World   
file1.txt(WordCountHbaseWriter\input\file1.txt)Hello Hadoop Goodbye Hadoop   

2)输出 HBase 数据库

以下为输出数据库 wordcount 的数据库结构,以及预期的输出结果,如下图所示:

HBase 入门基础教程

2、Mapper 函数实现


WordCountHbaseMapper 程序和 WordCount 的 Map 程序一样,Map 输入为每一行数据,例如”Hello World Bye World”,通过 StringTokenizer 类按空格分割成一个个单词,
通过 context.write(word, one); 输出为一系列 < key,value> 键值对:<”Hello”,1><”World”,1><”Bye”,1><”World”,1>。
详细源码请参考:WordCountHbaseWriter\src\com\zonesion\hbase\WordCountHbaseWriter.java

public static class WordCountHbaseMapper extends
        Mapper<Object, Text, Text, IntWritable> {private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();

    public void map(Object key, Text value, Context context)
            throws IOException, InterruptedException {StringTokenizer itr = new StringTokenizer(value.toString());
        while (itr.hasMoreTokens()) {word.set(itr.nextToken());
            context.write(word, one);// 输出 <key,value> 为 <word,one>
        }
    }
}

3、Reducer 函数实现


WordCountHbaseReducer 继承的是 TableReducer 类,在 Hadoop 中 TableReducer 继承 Reducer 类,它的原型为 TableReducer< KeyIn,Values,KeyOut>,前两个参数必须对应 Map 过程的输出类型 key/value 类型,第三个参数为 ImmutableBytesWritable,即为不可变类型。reduce(Text key, Iterable< IntWritable> values,Context context)具体处理过程分析如下表所示。

HBase 入门基础教程

详细源码请参考:WordCountHbaseWriter\src\com\zonesion\hbase\WordCountHbaseWriter.java

public static class WordCountHbaseReducer extends
            TableReducer<Text, IntWritable, ImmutableBytesWritable> {

        public void reduce(Text key, Iterable<IntWritable> values,
                Context context) throws IOException, InterruptedException {
            int sum = 0;
            for (IntWritable val : values) {// 遍历求和
                sum += val.get();}
            Put put = new Put(key.getBytes());//put 实例化,每一个词存一行
            // 列族为 content, 列修饰符为 count,列值为数目
            put.add(Bytes.toBytes("content"), Bytes.toBytes("count"), Bytes.toBytes(String.valueOf(sum)));
            context.write(new ImmutableBytesWritable(key.getBytes()), put);// 输出求和后的 <key,value>
        }
    }

4、驱动函数实现


与 WordCount 的驱动类不同,在 Job 配置的时候没有配置 job.setReduceClass(),而是用以下方法执行 Reduce 类:

TableMapReduceUtil.initTableReducerJob(tablename, WordCountHbaseReducer.class, job);

该方法指明了在执行 job 的 reduce 过程时,执行 WordCountHbaseReducer,并将 reduce 的结果写入到表明为 tablename 的表中。特别注意:此处的 TableMapReduceUtil 是 hadoop.hbase.mapreduce 包中的,而不是 hadoop.hbase.mapred 包中的,否则会报错。
详细源码请参考:WordCountHbaseWriter\src\com\zonesion\hbase\WordCountHbaseWriter.java

public static void main(String[] args) throws Exception {
    String tablename = "wordcount";
    Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.zookeeper.quorum", "Master");
    HBaseAdmin admin = new HBaseAdmin(conf);
    if(admin.tableExists(tablename)){System.out.println("table exists!recreating.......");
        admin.disableTable(tablename);
        admin.deleteTable(tablename);
    }
    HTableDescriptor htd = new HTableDescriptor(tablename);
    HColumnDescriptor tcd = new HColumnDescriptor("content");
    htd.addFamily(tcd);// 创建列族
    admin.createTable(htd);// 创建表
    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
    if (otherArgs.length != 1) {System.err.println("Usage: WordCountHbase <in>");
      System.exit(2);
    }
    Job job = new Job(conf, "WordCountHbase");
    job.setJarByClass(WordCountHbase.class);
    // 使用 WordCountHbaseMapper 类完成 Map 过程;job.setMapperClass(WordCountHbaseMapper.class);
    TableMapReduceUtil.initTableReducerJob(tablename, WordCountHbaseReducer.class, job);
    // 设置任务数据的输入路径;FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
    // 设置了 Map 过程和 Reduce 过程的输出类型,其中设置 key 的输出类型为 Text;job.setOutputKeyClass(Text.class);
    // 设置了 Map 过程和 Reduce 过程的输出类型,其中设置 value 的输出类型为 IntWritable;job.setOutputValueClass(IntWritable.class);
    // 调用 job.waitForCompletion(true) 执行任务,执行成功后退出;System.exit(job.waitForCompletion(true) ? 0 : 1);
}

5、部署运行


1)启动 Hadoop 集群和 Hbase 服务

[hadoop@K-Master ~]$ start-dfs.sh     #启动 hadoop HDFS 文件管理系统
[hadoop@K-Master ~]$ start-mapred.sh      #启动 hadoop MapReduce 分布式计算服务
[hadoop@K-Master ~]$ start-hbase.sh       #启动 Hbase
[hadoop@K-Master ~]$ jps              #查看进程
22003 HMaster
10611 SecondaryNameNode
22226 Jps
21938 HQuorumPeer
10709 JobTracker
22154 HRegionServer
20277 Main
10432 NameNode

特别注意:用户可先通过 jps 命令查看 Hadoop 集群和 Hbase 服务是否启动,如果 Hadoop 集群和 Hbase 服务已经启动,则不需要执行此操作。

2)部署源码

# 设置工作环境
[hadoop@K-Master ~]$ mkdir -p /usr/hadoop/workspace/Hbase
#部署源码
将 WordCountHbaseWriter 文件夹拷贝到 /usr/hadoop/workspace/Hbase/ 路径下;

… 你可以直接 下载 WordCountHbaseWriter

—————————————— 分割线 ——————————————

FTP 地址:ftp://ftp1.linuxidc.com

用户名:ftp1.linuxidc.com

密码:www.linuxidc.com

在 2015 年 LinuxIDC.com\3 月 \HBase 入门基础教程

下载方法见 http://www.linuxidc.com/Linux/2013-10/91140.htm

—————————————— 分割线 ——————————————

3)修改配置文件

a) 查看 hbase 核心配置文件 hbase-site.xml 的 hbase.zookeeper.quorum 属性

参考“【HBase 入门基础教程】5、HBase API 访问

3、部署运行 3)修改配置文件”查看 hbase 核心配置文件 hbase-site.xml 的 hbase.zookeeper.quorum 属性;

b) 修改项目 WordCountHbaseWriter/src/config.properties 属性文件

将项目 WordCountHbaseWriter/src/config.properties 属性文件的 hbase.zookeeper.quorum 属性值修改为上一步查询到的属性值,保持 config.properties 文件的 hbase.zookeeper.quorum 属性值与 hbase-site.xml 文件的 hbase.zookeeper.quorum 属性值一致;

# 切换工作目录
[hadoop@K-Master ~]$ cd /usr/hadoop/workspace/Hbase/WordCountHbaseWriter
#修改属性值
[hadoop@K-Master WordCountHbaseWriter]$ vim src/config.properties
hbase.zookeeper.quorum=K-Master
#拷贝 src/config.properties 文件到 bin/ 文件夹
[hadoop@K-Master WordCountHbaseWriter]$ cp src/config.properties bin/

4)上传输入文件

# 创建输入文件夹
[hadoop@K-Master WordCountHbaseWriter]$ hadoop fs -mkdir HbaseWriter/input/
#上传文件到输入文件夹 
[hadoop@K-Master WordCountHbaseWriter]$ hadoop fs -put input/file* HbaseWriter/input/
#查看上传文件是否成功
[hadoop@K-Master WordCountHbaseWriter]$ hadoop fs -ls HbaseWriter/input/
Found 2 items
-rw-r--r--   3 hadoop supergroup 22 2014-12-30 17:39 /user/hadoop/HbaseWriter/input/file0.txt
-rw-r--r--   3 hadoop supergroup 28 2014-12-30 17:39 /user/hadoop/HbaseWriter/input/file1.txt

5)编译文件

# 执行编译
[hadoop@K-Master WordCountHbaseWriter]$ javac -classpath /usr/hadoop/hadoop-core-1.2.1.jar:/usr/hadoop/lib/commons-cli-1.2.jar:lib/zookeeper-3.4.5.jar:lib/hbase-0.94.20.jar -d bin/ src/com/zonesion/hbase/*.java
#查看编译是否成功
[hadoop@K-Master WordCountHbaseWriter]$ ls bin/com/zonesion/hbase/ -la
total 24
drwxrwxr-x 2 hadoop hadoop 4096 Dec 30 17:20 .
drwxrwxr-x 3 hadoop hadoop 4096 Dec 30 17:20 ..
-rw-rw-r-- 1 hadoop hadoop 3446 Dec 30 17:29 PropertiesHelper.class
-rw-rw-r-- 1 hadoop hadoop 3346 Dec 30 17:29 WordCountHbaseWriter.class
-rw-rw-r-- 1 hadoop hadoop 1817 Dec 30 17:29 WordCountHbaseWriter$WordCountHbaseMapper.class
-rw-rw-r-- 1 hadoop hadoop 2217 Dec 30 17:29 WordCountHbaseWriter$WordCountHbaseReducer.class

6)打包 Jar 文件

# 拷贝 lib 文件夹到 bin 文件夹
[hadoop@K-Master WordCountHbaseWriter]$ cp –r lib/ bin/
#打包 Jar 文件
[hadoop@K-Master WordCountHbaseWriter]$ jar -cvf WordCountHbaseWriter.jar -C bin/ . 
added manifest
adding: lib/(in = 0) (out= 0)(stored 0%)
adding: lib/zookeeper-3.4.5.jar(in = 779974) (out= 721150)(deflated 7%)
adding: lib/guava-11.0.2.jar(in = 1648200) (out= 1465342)(deflated 11%)
adding: lib/protobuf-java-2.4.0a.jar(in = 449818) (out= 420864)(deflated 6%)
adding: lib/hbase-0.94.20.jar(in = 5475284) (out= 5038635)(deflated 7%)
adding: com/(in = 0) (out= 0)(stored 0%)
adding: com/zonesion/(in = 0) (out= 0)(stored 0%)
adding: com/zonesion/hbase/(in = 0) (out= 0)(stored 0%)
adding: com/zonesion/hbase/WordCountHbaseWriter.class(in = 3136) (out= 1583)(deflated 49%)
adding: com/zonesion/hbase/WordCountHbaseWriter$WordCountHbaseMapper.class(in = 1817) (out= 772)(deflated 57%)
adding: com/zonesion/hbase/WordCountHbaseWriter$WordCountHbaseReducer.class(in = 2217) (out= 929)(deflated 58%)

7)运行实例

[hadoop@K-Master WordCountHbaseWriter]$ hadoop jar WordCountHbaseWriter.jar com.zonesion.hbase.WordCountHbaseWriter /user/hadoop/HbaseWriter/input/
................... 省略.............
14/12/30 11:23:59 INFO input.FileInputFormat: Total input paths to process : 2
14/12/30 11:23:59 INFO util.NativeCodeLoader: Loaded the native-hadoop library
14/12/30 11:23:59 WARN snappy.LoadSnappy: Snappy native library not loaded
14/12/30 11:24:05 INFO mapred.JobClient: Running job: job_201412161748_0020
14/12/30 11:24:06 INFO mapred.JobClient:  map 0% reduce 0%
14/12/30 11:24:27 INFO mapred.JobClient:  map 50% reduce 0%
14/12/30 11:24:30 INFO mapred.JobClient:  map 100% reduce 0%
14/12/30 11:24:39 INFO mapred.JobClient:  map 100% reduce 100%
14/12/30 11:24:41 INFO mapred.JobClient: Job complete: job_201412161748_0020
14/12/30 11:24:41 INFO mapred.JobClient: Counters: 28
14/12/30 11:24:41 INFO mapred.JobClient:   Job Counters
14/12/30 11:24:41 INFO mapred.JobClient: Launched reduce tasks=1
14/12/30 11:24:41 INFO mapred.JobClient: SLOTS_MILLIS_MAPS=20955
14/12/30 11:24:41 INFO mapred.JobClient: Total time spent by all reduces waiting after reserving slots (ms)=0
14/12/30 11:24:41 INFO mapred.JobClient: Total time spent by all maps waiting after reserving slots (ms)=0
14/12/30 11:24:41 INFO mapred.JobClient: Launched map tasks=2
14/12/30 11:24:41 INFO mapred.JobClient: Data-local map tasks=2
14/12/30 11:24:41 INFO mapred.JobClient: SLOTS_MILLIS_REDUCES=11527
14/12/30 11:24:41 INFO mapred.JobClient:   File Output Format Counters
14/12/30 11:24:41 INFO mapred.JobClient: Bytes Written=0
14/12/30 11:24:41 INFO mapred.JobClient:   FileSystemCounters
14/12/30 11:24:41 INFO mapred.JobClient: FILE_BYTES_READ=104
14/12/30 11:24:41 INFO mapred.JobClient: HDFS_BYTES_READ=296
14/12/30 11:24:41 INFO mapred.JobClient: FILE_BYTES_WRITTEN=239816
14/12/30 11:24:41 INFO mapred.JobClient:   File Input Format Counters
14/12/30 11:24:41 INFO mapred.JobClient: Bytes Read=50
14/12/30 11:24:41 INFO mapred.JobClient:   Map-Reduce Framework
14/12/30 11:24:41 INFO mapred.JobClient: Map output materialized bytes=110
14/12/30 11:24:41 INFO mapred.JobClient: Map input records=2
14/12/30 11:24:41 INFO mapred.JobClient: Reduce shuffle bytes=110
14/12/30 11:24:41 INFO mapred.JobClient: Spilled Records=16
14/12/30 11:24:41 INFO mapred.JobClient: Map output bytes=82
14/12/30 11:24:41 INFO mapred.JobClient: Total committed heap usage (bytes)=417546240
14/12/30 11:24:41 INFO mapred.JobClient: CPU time spent (ms)=1110
14/12/30 11:24:41 INFO mapred.JobClient: Combine input records=0
14/12/30 11:24:41 INFO mapred.JobClient: SPLIT_RAW_BYTES=246
14/12/30 11:24:41 INFO mapred.JobClient: Reduce input records=8
14/12/30 11:24:41 INFO mapred.JobClient: Reduce input groups=5
14/12/30 11:24:41 INFO mapred.JobClient: Combine output records=0
14/12/30 11:24:41 INFO mapred.JobClient: Physical memory (bytes) snapshot=434167808
14/12/30 11:24:41 INFO mapred.JobClient: Reduce output records=5
14/12/30 11:24:41 INFO mapred.JobClient: Virtual memory (bytes) snapshot=2192027648
14/12/30 11:24:41 INFO mapred.JobClient: Map output records=8

8)查看输出结果

# 另外开启一个终端,输入 hbase shell 命令进入 hbase shell 命令行
[hadoop@K-Master ~]$ hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.94.20, r09c60d770f2869ca315910ba0f9a5ee9797b1edc, Fri May 23 22:00:41 PDT 2014

hbase(main):002:0> scan 'wordcount'
ROW   COLUMN+CELL
 Bye  column=content:count, timestamp=1419932527321, value=1
 Goodbye  column=content:count, timestamp=1419932527321, value=1
 Hadoope  column=content:count, timestamp=1419932527321, value=2
 Hellope  column=content:count, timestamp=1419932527321, value=2
 Worldpe  column=content:count, timestamp=1419932527321, value=2
5 row(s) in 0.6370 seconds

本 blog 介绍如何读取 Hbase 中的数据并写入到 HDFS 分布式文件系统中。读取数据比较简单,我们借用上一篇【HBase 入门基础教程】6、HBase 之读取 MapReduce 数据写入 HBase 的 hbase 数据输出 wordcount 表作为本篇数据源的输入,编写 Mapper 函数,读取 wordcount 表中的数据填充到 < key,value>,通过 Reduce 函数直接输出得到的结果即可。

开发环境


硬件环境:CentOS 6.5 服务器 4 台(一台为 Master 节点,三台为 Slave 节点)
软件环境:Java 1.7.0_45、Eclipse Juno Service Release 2、Hadoop-1.2.1、hbase-0.94.20。

1、输入与输出


1)输入数据源:

上一篇【HBase 入门基础教程】6、HBase 之读取 MapReduce 数据写入 HBase 实现了读取 MapReduce 数据写入到 Hbase 表 wordcount 中,在本篇 blog 中,我们将 wordcount 表作为输入数据源。

2)输出目标:

HDFS 分布式文件系统中的文件。

2、Mapper 函数实现


WordCountHbaseReaderMapper 类继承了 TableMapper< Text,Text> 抽象类,TableMapper 类专门用于完成 MapReduce 中 Map 过程与 Hbase 表之间的操作。此时的 map(ImmutableBytesWritable key,Result value,Context context)方法,第一个参数 key 为 Hbase 表的 rowkey 主键,第二个参数 value 为 key 主键对应的记录集合,此处的 map 核心实现是遍历 key 主键对应的记录集合 value,将其组合成一条记录通过 contentx.write(key,value)填充到 < key,value> 键值对中。
详细源码请参考:WordCountHbaseReader\src\com\zonesion\hbase\WordCountHbaseReader.java

public static class WordCountHbaseReaderMapper extends 
    TableMapper<Text,Text>{

    @Override
    protected void map(ImmutableBytesWritable key,Result value,Context context)
            throws IOException, InterruptedException {StringBuffer sb = new StringBuffer("");
        for(Entry<byte[],byte[]> entry:value.getFamilyMap("content".getBytes()).entrySet()){String str =  new String(entry.getValue());
            // 将字节数组转换为 String 类型
            if(str != null){sb.append(new String(entry.getKey()));
                sb.append(":");
                sb.append(str);
            }
            context.write(new Text(key.get()), new Text(new String(sb)));
        }
    }
}

3、Reducer 函数实现


此处的 WordCountHbaseReaderReduce 实现了直接输出 Map 输出的 < key,value> 键值对,没有对其做任何处理。详细源码请参考:WordCountHbaseReader\src\com\zonesion\hbase\WordCountHbaseReader.java

public static class WordCountHbaseReaderReduce extends Reducer<Text,Text,Text,Text>{private Text result = new Text();
    @Override
    protected void reduce(Text key, Iterable<Text> values,Context context)
            throws IOException, InterruptedException {for(Text val:values){result.set(val);
            context.write(key, result);
        }
    }
}

4、驱动函数实现


与 WordCount 的驱动类不同,在 Job 配置的时候没有配置 job.setMapperClass(),而是用以下方法执行 Mapper 类:TableMapReduceUtil.initTableMapperJob(tablename,scan,WordCountHbaseReaderMapper.class, Text.class, Text.class, job);
该方法指明了在执行 job 的 Map 过程时,数据输入源是 hbase 的 tablename 表,通过扫描读入对象 scan 对表进行全表扫描,为 Map 过程提供数据源输入,通过 WordCountHbaseReaderMapper.class 执行 Map 过程,Map 过程的输出 key/value 类型是 Text.class 与 Text.class,最后一个参数是作业对象。特别注意:这里声明的是一个最简单的扫描读入对象 scan,进行表扫描读取数据,其中 scan 可以配置参数,这里为了例子简单不再详述,用户可自行尝试。
详细源码请参考:WordCountHbaseReader\src\com\zonesion\hbase\WordCountHbaseReader.java

public static void main(String[] args) throws Exception {
    String tablename = "wordcount";
    Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.zookeeper.quorum", "Master");
    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
    if (otherArgs.length != 1) {System.err.println("Usage: WordCountHbaseReader <out>");
      System.exit(2);
    }
    Job job = new Job(conf, "WordCountHbaseReader");
    job.setJarByClass(WordCountHbaseReader.class);
    // 设置任务数据的输出路径;FileOutputFormat.setOutputPath(job, new Path(otherArgs[0]));
    job.setReducerClass(WordCountHbaseReaderReduce.class);
    Scan scan = new Scan();
    TableMapReduceUtil.initTableMapperJob(tablename,scan,WordCountHbaseReaderMapper.class, Text.class, Text.class, job);
    // 调用 job.waitForCompletion(true) 执行任务,执行成功后退出;System.exit(job.waitForCompletion(true) ? 0 : 1);


}

5、部署运行


1)启动 Hadoop 集群和 Hbase 服务

[hadoop@K-Master ~]$ start-dfs.sh     #启动 hadoop HDFS 文件管理系统
[hadoop@K-Master ~]$ start-mapred.sh      #启动 hadoop MapReduce 分布式计算服务
[hadoop@K-Master ~]$ start-hbase.sh       #启动 Hbase
[hadoop@K-Master ~]$ jps              #查看进程
22003 HMaster
10611 SecondaryNameNode
22226 Jps
21938 HQuorumPeer
10709 JobTracker
22154 HRegionServer
20277 Main
10432 NameNode

2)部署源码

# 设置工作环境
[hadoop@K-Master ~]$ mkdir -p /usr/hadoop/workspace/Hbase
#部署源码
将 WordCountHbaseReader 文件夹拷贝到 /usr/hadoop/workspace/Hbase/ 路径下;

… 你可以直接 下载 WordCountHbaseReader

—————————————— 分割线 ——————————————

FTP 地址:ftp://ftp1.linuxidc.com

用户名:ftp1.linuxidc.com

密码:www.linuxidc.com

在 2015 年 LinuxIDC.com\3 月 \HBase 入门基础教程

下载方法见 http://www.linuxidc.com/Linux/2013-10/91140.htm

—————————————— 分割线 ——————————————

3)修改配置文件

a)查看 hbase 核心配置文件 hbase-site.xml 的 hbase.zookeeper.quorum 属性

参考“【HBase 入门基础教程】5、HBase API 访问 3、部署运行 3)修改配置文件”查看 hbase 核心配置文件 hbase-site.xml 的 hbase.zookeeper.quorum 属性;

b)修改项目 WordCountHbaseWriter/src/config.properties 属性文件

将项目 WordCountHbaseWriter/src/config.properties 属性文件的 hbase.zookeeper.quorum 属性值修改为上一步查询到的属性值,保持 config.properties 文件的 hbase.zookeeper.quorum 属性值与 hbase-site.xml 文件的 hbase.zookeeper.quorum 属性值一致;

# 切换工作目录
[hadoop@K-Master ~]$ cd /usr/hadoop/workspace/Hbase/ WordCountHbaseReader
#修改属性值
[hadoop@K-Master WordCountHbaseReader]$ vim src/config.properties
hbase.zookeeper.quorum=K-Master
#拷贝 src/config.properties 文件到 bin/ 文件夹
[hadoop@K-Master WordCountHbaseReader]$ cp src/config.properties bin/

4)编译文件

# 切换工作目录
[hadoop@K-Master ~]$ cd /usr/hadoop/workspace/Hbase/WordCountHbaseReader
#执行编译
[hadoop@K-Master WordCountHbaseReader]$ javac -classpath /usr/hadoop/hadoop-core-1.2.1.jar:/usr/hadoop/lib/commons-cli-1.2.jar:lib/zookeeper-3.4.5.jar:lib/hbase-0.94.20.jar -d bin/ src/com/zonesion/hbase/WordCountHbaseReader.java
#查看编译文件
[hadoop@K-Master WordCountHbaseReader]$ ls bin/com/zonesion/hbase/ -la
total 20
drwxrwxr-x 2 hadoop hadoop 4096 Dec 29 10:36 .
drwxrwxr-x 3 hadoop hadoop 4096 Dec 29 10:36 ..
-rw-rw-r-- 1 hadoop hadoop 2166 Dec 29 14:31 WordCountHbaseReader.class
-rw-rw-r-- 1 hadoop hadoop 2460 Dec 29 14:31 WordCountHbaseReader$WordCountHbaseReaderMapper.class
-rw-rw-r-- 1 hadoop hadoop 1738 Dec 29 14:31 WordCountHbaseReader$WordCountHbaseReaderReduce.class

5)打包 Jar 文件

# 拷贝 lib 文件夹到 bin 文件夹
[hadoop@K-Master WordCountHbaseReader]$ cp -r lib/ bin/
#打包 Jar 文件
[hadoop@K-Master WordCountHbaseReader]$ jar -cvf WordCountHbaseReader.jar -C bin/ .
added manifest
adding: lib/(in = 0) (out= 0)(stored 0%)
adding: lib/zookeeper-3.4.5.jar(in = 779974) (out= 721150)(deflated 7%)
adding: lib/guava-11.0.2.jar(in = 1648200) (out= 1465342)(deflated 11%)
adding: lib/protobuf-java-2.4.0a.jar(in = 449818) (out= 420864)(deflated 6%)
adding: lib/hbase-0.94.20.jar(in = 5475284) (out= 5038635)(deflated 7%)
adding: com/(in = 0) (out= 0)(stored 0%)
adding: com/zonesion/(in = 0) (out= 0)(stored 0%)
adding: com/zonesion/hbase/(in = 0) (out= 0)(stored 0%)
adding: com/zonesion/hbase/PropertiesHelper.class(in = 4480) (out= 1926)(deflated 57%)
adding: com/zonesion/hbase/WordCountHbaseReader.class(in = 2702) (out= 1226)(deflated 54%)
adding: com/zonesion/hbase/WordCountHbaseReader$WordCountHbaseReaderMapper.class(in = 3250) (out= 1275)(deflated 60%)
adding: com/zonesion/hbase/WordCountHbaseReader$WordCountHbaseReaderReduce.class(in = 2308) (out= 872)(deflated 62%)
adding: config.properties(in = 32) (out= 34)(deflated -6%)

6)运行实例

[hadoop@K-Master WordCountHbase]$ hadoop jar WordCountHbaseReader.jar WordCountHbaseReader /user/hadoop/WordCountHbaseReader/output/
................... 省略.............
14/12/30 17:51:58 INFO mapred.JobClient: Running job: job_201412161748_0035
14/12/30 17:51:59 INFO mapred.JobClient:  map 0% reduce 0%
14/12/30 17:52:13 INFO mapred.JobClient:  map 100% reduce 0%
14/12/30 17:52:26 INFO mapred.JobClient:  map 100% reduce 100%
14/12/30 17:52:27 INFO mapred.JobClient: Job complete: job_201412161748_0035
14/12/30 17:52:27 INFO mapred.JobClient: Counters: 39
14/12/30 17:52:27 INFO mapred.JobClient:   Job Counters
14/12/30 17:52:27 INFO mapred.JobClient:     Launched reduce tasks=1
14/12/30 17:52:27 INFO mapred.JobClient:     SLOTS_MILLIS_MAPS=4913
14/12/30 17:52:27 INFO mapred.JobClient:     Total time spent by all reduces waiting after reserving slots (ms)=0
14/12/30 17:52:27 INFO mapred.JobClient:     Total time spent by all maps waiting after reserving slots (ms)=0
14/12/30 17:52:27 INFO mapred.JobClient:     Rack-local map tasks=1
14/12/30 17:52:27 INFO mapred.JobClient:     Launched map tasks=1
14/12/30 17:52:27 INFO mapred.JobClient:     SLOTS_MILLIS_REDUCES=13035
14/12/30 17:52:27 INFO mapred.JobClient:   HBase Counters
14/12/30 17:52:27 INFO mapred.JobClient:     REMOTE_RPC_CALLS=8
14/12/30 17:52:27 INFO mapred.JobClient:     RPC_CALLS=8
14/12/30 17:52:27 INFO mapred.JobClient:     RPC_RETRIES=0
14/12/30 17:52:27 INFO mapred.JobClient:     NOT_SERVING_REGION_EXCEPTION=0
14/12/30 17:52:27 INFO mapred.JobClient:     NUM_SCANNER_RESTARTS=0
14/12/30 17:52:27 INFO mapred.JobClient:     MILLIS_BETWEEN_NEXTS=9
14/12/30 17:52:27 INFO mapred.JobClient:     BYTES_IN_RESULTS=216
14/12/30 17:52:27 INFO mapred.JobClient:     BYTES_IN_REMOTE_RESULTS=216
14/12/30 17:52:27 INFO mapred.JobClient:     REGIONS_SCANNED=1
14/12/30 17:52:27 INFO mapred.JobClient:     REMOTE_RPC_RETRIES=0
14/12/30 17:52:27 INFO mapred.JobClient:   File Output Format Counters
14/12/30 17:52:27 INFO mapred.JobClient:     Bytes Written=76
14/12/30 17:52:27 INFO mapred.JobClient:   FileSystemCounters
14/12/30 17:52:27 INFO mapred.JobClient:     FILE_BYTES_READ=92
14/12/30 17:52:27 INFO mapred.JobClient:     HDFS_BYTES_READ=68
14/12/30 17:52:27 INFO mapred.JobClient:     FILE_BYTES_WRITTEN=159978
14/12/30 17:52:27 INFO mapred.JobClient:     HDFS_BYTES_WRITTEN=76
14/12/30 17:52:27 INFO mapred.JobClient:   File Input Format Counters
14/12/30 17:52:27 INFO mapred.JobClient:     Bytes Read=0
14/12/30 17:52:27 INFO mapred.JobClient:   Map-Reduce Framework
14/12/30 17:52:27 INFO mapred.JobClient:     Map output materialized bytes=92
14/12/30 17:52:27 INFO mapred.JobClient:     Map input records=5
14/12/30 17:52:27 INFO mapred.JobClient:     Reduce shuffle bytes=92
14/12/30 17:52:27 INFO mapred.JobClient:     Spilled Records=10
14/12/30 17:52:27 INFO mapred.JobClient:     Map output bytes=76
14/12/30 17:52:27 INFO mapred.JobClient:     Total committed heap usage (bytes)=211025920
14/12/30 17:52:27 INFO mapred.JobClient:     CPU time spent (ms)=2160
14/12/30 17:52:27 INFO mapred.JobClient:     Combine input records=0
14/12/30 17:52:27 INFO mapred.JobClient:     SPLIT_RAW_BYTES=68
14/12/30 17:52:27 INFO mapred.JobClient:     Reduce input records=5
14/12/30 17:52:27 INFO mapred.JobClient:     Reduce input groups=5
14/12/30 17:52:27 INFO mapred.JobClient:     Combine output records=0
14/12/30 17:52:27 INFO mapred.JobClient:     Physical memory (bytes) snapshot=263798784
14/12/30 17:52:27 INFO mapred.JobClient:     Reduce output records=5
14/12/30 17:52:27 INFO mapred.JobClient:     Virtual memory (bytes) snapshot=1491795968
14/12/30 17:52:27 INFO mapred.JobClient:     Map output records=5

7)查看运行结果

[hadoop@K-Master WordCountHbaseReader]$ hadoop fs  -ls /user/hadoop/WordCountHbaseReader/output/
Found 3 items
-rw-r--r--   1 hadoop supergroup          0 2014-07-28 18:04 /user/hadoop/WordCountHbaseReader/output/_SUCCESS
drwxr-xr-x   - hadoop supergroup          0 2014-07-28 18:04 /user/hadoop/WordCountHbaseReader/output/_logs
-rw-r--r--   1 hadoop supergroup         76 2014-07-28 18:04 /user/hadoop/WordCountHbaseReader/output/part-r-00000
[hadoop@K-Master WordCountHbaseReader]$ hadoop fs -cat /user/hadoop/WordCountHbaseReader/output/part-r-00000
Bye count:1
Goodbye count:1
Hadoope count:2
Hellope count:2
Worldpe count:2

HBase 的详细介绍:请点这里
HBase 的下载地址:请点这里

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计58805字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中