Hbase入门

本文主要包括Hbase的安装以及Hbase Shell命令行简单使用。
一,安装环境
硬件:虚拟机
操作系统:Centos 6.4 64位
IP:10.51.121.10
主机名:datanode-4
安装用户:root
需要安装JDK1.6或者以上版本。
这里安装的JDK为jdk1.7.0_75,并配置好了环境变量。

二,安装Hbase
1,到http://archive.apache.org/dist/hbase/ 下载对应版本的Hbase。这里下载的版本为:Hbase-0.94.14
2,解压安装,#tar -zxvf hbase-0.94.14.tar.gz 到/root/hadoop目录下。
hbase的安装目录为:/root/hadoop/hbase-0.94.14
3,进入conf/hbase-site.xml文件,添加如下配置:

#vi hbase-site.xml
<property>
        <name>hbase.rootdir</name>
        <value>file:///root/hadoop/hbase-0.94.14/data/hbase</value>
</property>
<property>
        <name>hbase.zookeeper.property.dataDir</name>
        <value>/root/hadoop/hbase-0.94.14/data/zookeeper</value>
</property>

三,启动Hbase服务
1,执行# ./bin/start-hbase.sh
2,执行#jps 即可看到有HMaster进程。
在standalone(单机)模式下,Hbase的所有daemons都运行在一个JVM中,比如HMaster,HRegionServer以及Zookeeper daemon。
3,访问HBase的管理界面,访问http://10.51.121.10:60010/master-status
这里写图片描述

四,Hbase Shell命令行
Hbase Shell是一个封装了Java客户端API的JRuby应用软件,有两种运行方式:交互模式和批处理模式。交互模式用于对HBase进行随时访问交互,批处理模式主要通过Shell脚本进行程序交互。这里主要介绍交互模式。
$ ./bin/hbase shell
HBase Shell; enter ‘help’ for list of supported commands.
Type “exit” to leave the HBase Shell
Version 0.94.14, r1543222, Mon Nov 18 23:23:33 UTC 2013

hbase(main):001:0>
hbase(main):016:0> help ‘create’
Create table; pass table name, a dictionary of specifications per
column family, and optionally a dictionary of table configuration.
Dictionaries are described below in the GENERAL NOTES section.
Examples:

hbase> create ‘t1’, {NAME => ‘f1’, VERSIONS => 5}
hbase> create ‘t1’, {NAME => ‘f1’}, {NAME => ‘f2’}, {NAME => ‘f3’}
hbase> # The above in shorthand would be the following:
hbase> create ‘t1’, ‘f1’, ‘f2’, ‘f3’
hbase> create ‘t1’, {NAME => ‘f1’, VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true}
hbase> create ‘t1’, ‘f1’, {SPLITS => [‘10’, ‘20’, ‘30’, ‘40’]}
hbase> create ‘t1’, ‘f1’, {SPLITS_FILE => ‘splits.txt’}
hbase> # Optionally pre-split the table into NUMREGIONS, using
hbase> # SPLITALGO (“HexStringSplit”, “UniformSplit” or classname)
hbase> create ‘t1’, ‘f1’, {NUMREGIONS => 15, SPLITALGO => ‘HexStringSplit’}

hbase(main):001:0> list
TABLE
mycrawl1_webpage
mycrawl2_webpage
mycrawl3_webpage
test
webpage
5 row(s) in 0.6910 seconds
这里执行list命令,有5个表。
1,创建表mytable,列族名为cf
hbase(main):002:0> create ‘mytable’,’cf’
0 row(s) in 0.2290 seconds
2,写数据,在’mytable’表的’first’行中的’cf:message’列对应的数据单元中插入字节数组’Hello Hbase’
hbase(main):003:0> put ‘mytable’,’first’,’cf:message’,’Hello hbase’
0 row(s) in 0.1670 seconds
hbase(main):005:0> put ‘mytable’,’second’,’cf:foo’,0x0
0 row(s) in 0.0040 seconds
hbase(main):006:0> put ‘mytable’,’third’,’cf:bar’,3.14159
0 row(s) in 0.0080 seconds
现在表中有3行和3个数据单元。在使用列时,并没有提前定义这些列,也没有定义列的数据类型。这是因为Hbase是一种无模式(schema-less)的数据库。
3,读取数据
Hbase提供两种方式读取数据:get和scan。
hbase(main):008:0> get ‘mytable’,’first’
COLUMN CELL
cf:message timestamp=1426042536193, value=Hello hbase
1 row(s) in 0.0380 seconds
上面得到了第一行数据,Shell输出了该行所有的数据单元,按列组织,还附带时间戳。Hbase可以存储每个数据单元的多个时间版本。版本的数量默认是3个,可以设置。读取时,默认返回最新时间版本。
hbase(main):009:0> scan ‘mytable’
ROW COLUMN+CELL
first column=cf:message, timestamp=1426042536193, value=Hello hbase
second column=cf:foo, timestamp=1426042582526, value=0
third column=cf:bar, timestamp=1426042602280, value=3.14159
3 row(s) in 0.0380 seconds
hbase(main):010:0> put ‘mytable’,’first’,’cf:message2’,’Hello Hbase2’
0 row(s) in 0.0100 seconds

hbase(main):011:0> put ‘mytable’,’first’,’cf:message’,’Hello Hbase3’
0 row(s) in 0.0030 seconds

hbase(main):012:0> get ‘mytable’,’first’
COLUMN CELL
cf:message timestamp=1426042983834, value=Hello Hbase3
cf:message2 timestamp=1426042968347, value=Hello Hbase2
2 row(s) in 0.0110 seconds

hbase(main):091:0> describe ‘mytable’
DESCRIPTION ENABLED
‘mytable’, {NAME => ‘cf’, DATA_BLOCK_ENCODING => ‘NONE’, BLOOMFILTER => ‘NONE’, REPLICATION_SCOPE => ‘0’, VERSIONS => ‘3’, COM true
PRESSION => ‘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.0230 seconds

五,常见错误
1,启动hbase时,在logs/xxx.log文件中有如下错误:

2015-03-06 17:12:54,785 ERROR org.apache.hadoop.hbase.master.HMasterCommandLine: Failed to start master
java.lang.RuntimeException: Failed suppression of fs shutdown hook: Thread[Thread-27,5,main]
        at org.apache.hadoop.hbase.regionserver.ShutdownHook.suppressHdfsShutdownHook(ShutdownHook.java:196)
        at org.apache.hadoop.hbase.regionserver.ShutdownHook.install(ShutdownHook.java:83)
        at org.apache.hadoop.hbase.util.JVMClusterUtil.startup(JVMClusterUtil.java:191)
        at org.apache.hadoop.hbase.LocalHBaseCluster.startup(LocalHBaseCluster.java:420)
        at org.apache.hadoop.hbase.master.HMasterCommandLine.startMaster(HMasterCommandLine.java:149)
        at org.apache.hadoop.hbase.master.HMasterCommandLine.run(HMasterCommandLine.java:104)
        at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:65)
        at org.apache.hadoop.hbase.util.ServerCommandLine.doMain(ServerCommandLine.java:76)
        at org.apache.hadoop.hbase.master.HMaster.main(HMaster.java:2120)

原因:HBase0.94是基于Hadoop1编译的。而在classpath有存在Hadoop2的包。
解决方法:在classpath中把hadoop2的包移除,问题解决。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值