网站:
http://hbase.apache.org/
版本对应关系:
通过lib目录下的hadoop-core- ...jar可以看出适配的hadoop版本
hbase-0.98.6-hadoop2 => hadoop 2.2hbase-0.96.2-hadoop2 => hadoop 2.2hbase-0.98.6-hadoop1 => hadoop 1.2.1hbase-0.96.2-hadoop1 => hadoop 1.2.1
Hbase安装 : 分布式安装
准备工作
首先需要保证已经正确的安装了hadoop和java
配置了正确的环境变量
测试环境
echo $HADOOP_INSTALLjava -versionhadoophadoop version
配置hbase
根据版本对应关系下载并解压正确的hbase版本
hbase-env.sh
export JAVA_HOME=/usr/java/jdk1.7.0_67export HBASE_CLASSPATH=/home/hadoop/hadoop-1.2.1/confexport HBASE_MANAGES_ZK=true #使用hbase自带的zookeeper
hbase-site.xml
从hbase-src包中拷贝默认的hbase-default.xml
[hadoop@hadoop1 hbase-0.98.6]$ cp ./hbase-common/src/main/resources/hbase-default.xml ../hbase/conf/hbase-site.xml
修改以下选项
hbase.rootdir hdfs://hadoop1:9000/hbase hbase.cluster.distributed true hbase.tmp.dir /home/hadoop/hbase/tmp hbase.defaults.for.version 0.98.6-hadoop1 hbase.zookeeper.quorum hadoop1,hadoop2,hadoop3 -------------------#如果不使用自带的zookeeper,下面的dataDir要配置城和zoo.cfg中的datadir一致hbase.zookeeper.property.dataDir /home/hadoop/zookeeper/build
regionservers
hadoop2hadoop3
分发配置
将hbase目录分发到各主机
[hadoop@hadoop1 ~]$ scp -r hbase hadoop2:~[hadoop@hadoop1 ~]$ scp -r hbase hadoop3:~
配置环境变量
HBASE_HOME=/home/hadoop/hbasePATH=$PATH:$HOME/bin:$JAVA_HOME/bin:$HADOOP/bin:$HBASE_HOME/bin
启动Hbase
[hadoop@hadoop1 hbase]$ start-hbase.sh hadoop3: starting zookeeper, logging to /home/hadoop/hbase/bin/../logs/hbase-hadoop-zookeeper-hadoop3.outhadoop2: starting zookeeper, logging to /home/hadoop/hbase/bin/../logs/hbase-hadoop-zookeeper-hadoop2.outhadoop1: starting zookeeper, logging to /home/hadoop/hbase/bin/../logs/hbase-hadoop-zookeeper-hadoop1.outstarting master, logging to /home/hadoop/hbase/bin/../logs/hbase-hadoop-master-hadoop1.outhadoop3: starting regionserver, logging to /home/hadoop/hbase/bin/../logs/hbase-hadoop-regionserver-hadoop3.outhadoop2: starting regionserver, logging to /home/hadoop/hbase/bin/../logs/hbase-hadoop-regionserver-hadoop2.out[hadoop@hadoop1 ~]$ hbase shellHBase Shell; enter 'help' for list of supported commands.Type "exit " to leave the HBase ShellVersion 0.98.6-hadoop1, r3645223d354a81af8d3d1cdfca9b3d45426f9959, Wed Sep 3 19:48:04 PDT 2014hbase(main):001:0> listTABLE SLF4J: Class path contains multiple SLF4J bindings.SLF4J: Found binding in [jar:file:/home/hadoop/hbase/lib/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]SLF4J: Found binding in [jar:file:/home/hadoop/hadoop-1.2.1/lib/slf4j-log4j12-1.4.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.0 row(s) in 3.2690 seconds=> []hbase(main):002:0>
Hbase测试
[hadoop@hadoop1 hbase]$ hbase shellHBase Shell; enter 'help' for list of supported commands.Type "exit " to leave the HBase ShellVersion 0.98.6-hadoop1, r3645223d354a81af8d3d1cdfca9b3d45426f9959, Wed Sep 3 19:48:04 PDT 2014hbase(main):001:0> listTABLE 0 row(s) in 2.6500 seconds=> []hbase(main):002:0> create 'test','data'0 row(s) in 0.6960 seconds=> Hbase::Table - testhbase(main):003:0> disable 'test'0 row(s) in 1.5480 secondshbase(main):007:0* drop 'test'0 row(s) in 0.3650 secondshbase(main):008:0> exit[hadoop@hadoop1 hbase]$
Hbase停止
[hadoop@hadoop1 hbase]$ stop-hbase.sh stopping hbase...............hadoop3: stopping zookeeper.hadoop2: stopping zookeeper.hadoop1: stopping zookeeper.
Shell
查询数据库状态, 当前服务器数量和负荷
hbase(main):001:0> status2 servers, 0 dead, 1.0000 average loadhbase(main):002:0>
查询数据库版本
hbase(main):002:0> version0.98.6-hadoop1, r3645223d354a81af8d3d1cdfca9b3d45426f9959, Wed Sep 3 19:48:04 PDT 2014hbase(main):003:0>
创建表
hbase(main):013:0> create 'member','member_id','address','info'0 row(s) in 2.5660 seconds=> Hbase::Table - memberhbase(main):014:0>
查看表信息
hbase(main):019:0> listTABLE member 1 row(s) in 0.0300 seconds=> ["member"]hbase(main):020:0> describe 'member'DESCRIPTION ENABLED 'member', {NAME => 'address', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', true REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => ' 0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMOR Y => 'false', BLOCKCACHE => 'true'}, {NAME => 'info', DATA_BLOCK_ENCODING => 'NONE' , BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => ' NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'false', BLOCKS IZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}, {NAME => 'member_id', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERS IONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DEL ETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 't rue'} 1 row(s) in 0.0850 secondshbase(main):021:0>
删除列族: alter, disabled, enabled命令
hbase(main):003:0> disable 'member'0 row(s) in 1.5270 secondshbase(main):002:0> alter 'member',{NAME=>'member_id',METHOD=>'delete'}Updating all regions with the new schema...0/1 regions updated.1/1 regions updated.Done.0 row(s) in 2.5150 secondshbase(main):004:0> enable 'member'0 row(s) in 0.6940 seconds
删除表
hbase(main):007:0> disable 'member'0 row(s) in 1.5230 secondshbase(main):008:0> drop 'member'0 row(s) in 0.2730 seconds
查询一个表是否存在
hbase(main):009:0> exists 'member'Table member does not exist 0 row(s) in 0.0980 seconds
判断表是否enable或disable
hbase(main):012:0> is_enabled 'member'true 0 row(s) in 0.0470 secondshbase(main):013:0> is_disabled 'member'false 0 row(s) in 0.0380 seconds
插入记录
#表明,行键,列族名,valuehbase(main):016:0> put 'member','xiaofeng','info:birthday','1987-4-17'0 row(s) in 0.2140 secondshbase(main):017:0> put 'member','scutshuxue','info:age','24'0 row(s) in 0.0240 secondshbase(main):018:0> put 'member','xiaofeng','info:company','alibaba'0 row(s) in 0.0310 secondshbase(main):019:0> put 'member','xiaofeng','address:contry','china'0 row(s) in 0.0250 secondshbase(main):020:0> put 'member','xiaofeng','address:province','guangdong'0 row(s) in 0.0210 seconds
获取一个行键的所有数据
hbase(main):021:0> get 'member','xiaofeng'COLUMN CELL address:contry timestamp=1410686546454, value=china address:province timestamp=1410686562013, value=guangdong info:birthday timestamp=1410686079424, value=1987-4-17 info:company timestamp=1410686529393, value=alibaba 4 row(s) in 0.1440 secondshbase(main):022:0>
获取一个行键, 一个列族的所有数据
hbase(main):022:0> get 'member','xiaofeng','info'COLUMN CELL info:birthday timestamp=1410686079424, value=1987-4-17 info:company timestamp=1410686529393, value=alibaba 2 row(s) in 0.0330 secondshbase(main):023:0>
获取一个行键, 一个列族中一个列的所有数据
hbase(main):024:0> get 'member','xiaofeng','info:company'COLUMN CELL info:company timestamp=1410686529393, value=alibaba 1 row(s) in 0.0190 secondshbase(main):025:0>
更新一条记录
hbase(main):025:0> put 'member','xiaofeng','info:company','sina'0 row(s) in 0.0170 secondshbase(main):026:0> get 'member','xiaofeng','info:company'COLUMN CELL info:company timestamp=1410686886831, value=sina 1 row(s) in 0.0170 secondshbase(main):027:0>
通过timestamp来获取数据
hbase(main):027:0> get 'member','xiaofeng',{COLUMN=>'info:company',TIMESTAMP=>1410686886831}COLUMN CELL info:company timestamp=1410686886831, value=sina 1 row(s) in 0.0410 secondshbase(main):028:0>
全表扫描
hbase(main):029:0> scan 'member'ROW COLUMN+CELL scutshuxue column=info:age, timestamp=1410686181691, value=24 xiaofeng column=address:contry, timestamp=1410686546454, value=china xiaofeng column=address:province, timestamp=1410686562013, value=guangdong xiaofeng column=info:birthday, timestamp=1410686079424, value=1987-4-17 xiaofeng column=info:company, timestamp=1410686886831, value=sina 2 row(s) in 0.0860 secondshbase(main):030:0>
删除指定行键的字段
hbase(main):030:0> delete 'member','xiaofeng','info:company'0 row(s) in 0.0960 secondshbase(main):031:0> get 'member','xiaofeng'COLUMN CELL address:contry timestamp=1410686546454, value=china address:province timestamp=1410686562013, value=guangdong info:birthday timestamp=1410686079424, value=1987-4-17 3 row(s) in 0.0280 secondshbase(main):032:0>
删除整行
hbase(main):033:0> deleteall 'member','xiaofeng'0 row(s) in 0.0390 secondshbase(main):034:0>
查询表中有多少行
hbase(main):034:0> count 'member'1 row(s) in 0.0420 seconds=> 1hbase(main):035:0>
清空表
hbase(main):035:0> truncate 'member'Truncating 'member' table (it may take a while): - Disabling table... - Dropping table... - Creating table...0 row(s) in 2.4100 secondshbase(main):036:0>
Hbase API
http://hbase.apache.org/apidocs/index.html