http://hbase.apache.org/
通过lib目录下的hadoop-core- ...jar可以看出适配的hadoop版本
hbase-0.98.6-hadoop2 => hadoop 2.2 hbase-0.96.2-hadoop2 => hadoop 2.2 hbase-0.98.6-hadoop1 => hadoop 1.2.1 hbase-0.96.2-hadoop1 => hadoop 1.2.1
首先需要保证已经正确的安装了hadoop和java
配置了正确的环境变量
echo $HADOOP_INSTALL java -version hadoop hadoop version
根据版本对应关系下载并解压正确的hbase版本
hbase-env.sh
export JAVA_HOME=/usr/java/jdk1.7.0_67 export HBASE_CLASSPATH=/home/hadoop/hadoop-1.2.1/conf export 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
修改以下选项
<name>hbase.rootdir</name> <value>hdfs://hadoop1:9000/hbase</value> <name>hbase.cluster.distributed</name> <value>true</value> <name>hbase.tmp.dir</name> <value>/home/hadoop/hbase/tmp</value> <name>hbase.defaults.for.version</name> <value>0.98.6-hadoop1</value> <name>hbase.zookeeper.quorum</name> <value>hadoop1,hadoop2,hadoop3</value> ------------------- #如果不使用自带的zookeeper,下面的dataDir要配置城和zoo.cfg中的datadir一致 <name>hbase.zookeeper.property.dataDir</name> <value>/home/hadoop/zookeeper/build</value>
regionservers
hadoop2 hadoop3
将hbase目录分发到各主机
[hadoop@hadoop1 ~]$ scp -r hbase hadoop2:~ [hadoop@hadoop1 ~]$ scp -r hbase hadoop3:~
HBASE_HOME=/home/hadoop/hbase PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:$HADOOP/bin:$HBASE_HOME/bin
[hadoop@hadoop1 hbase]$ start-hbase.sh hadoop3: starting zookeeper, logging to /home/hadoop/hbase/bin/../logs/hbase-hadoop-zookeeper-hadoop3.out hadoop2: starting zookeeper, logging to /home/hadoop/hbase/bin/../logs/hbase-hadoop-zookeeper-hadoop2.out hadoop1: starting zookeeper, logging to /home/hadoop/hbase/bin/../logs/hbase-hadoop-zookeeper-hadoop1.out starting master, logging to /home/hadoop/hbase/bin/../logs/hbase-hadoop-master-hadoop1.out hadoop3: starting regionserver, logging to /home/hadoop/hbase/bin/../logs/hbase-hadoop-regionserver-hadoop3.out hadoop2: starting regionserver, logging to /home/hadoop/hbase/bin/../logs/hbase-hadoop-regionserver-hadoop2.out [hadoop@hadoop1 ~]$ hbase shell HBase Shell; enter ‘help<RETURN>‘ for list of supported commands. Type "exit<RETURN>" to leave the HBase Shell Version 0.98.6-hadoop1, r3645223d354a81af8d3d1cdfca9b3d45426f9959, Wed Sep 3 19:48:04 PDT 2014 hbase(main):001:0> list TABLE 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>
[hadoop@hadoop1 hbase]$ hbase shell HBase Shell; enter ‘help<RETURN>‘ for list of supported commands. Type "exit<RETURN>" to leave the HBase Shell Version 0.98.6-hadoop1, r3645223d354a81af8d3d1cdfca9b3d45426f9959, Wed Sep 3 19:48:04 PDT 2014 hbase(main):001:0> list TABLE 0 row(s) in 2.6500 seconds => [] hbase(main):002:0> create ‘test‘,‘data‘ 0 row(s) in 0.6960 seconds => Hbase::Table - test hbase(main):003:0> disable ‘test‘ 0 row(s) in 1.5480 seconds hbase(main):007:0* drop ‘test‘ 0 row(s) in 0.3650 seconds hbase(main):008:0> exit [hadoop@hadoop1 hbase]$
[hadoop@hadoop1 hbase]$ stop-hbase.sh stopping hbase. .............. hadoop3: stopping zookeeper. hadoop2: stopping zookeeper. hadoop1: stopping zookeeper.
查询数据库状态, 当前服务器数量和负荷
hbase(main):001:0> status 2 servers, 0 dead, 1.0000 average load hbase(main):002:0>
查询数据库版本
hbase(main):002:0> version 0.98.6-hadoop1, r3645223d354a81af8d3d1cdfca9b3d45426f9959, Wed Sep 3 19:48:04 PDT 2014 hbase(main):003:0>
创建表
hbase(main):013:0> create ‘member‘,‘member_id‘,‘address‘,‘info‘ 0 row(s) in 2.5660 seconds => Hbase::Table - member hbase(main):014:0>
查看表信息
hbase(main):019:0> list TABLE 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 seconds hbase(main):021:0>
删除列族: alter, disabled, enabled命令
hbase(main):003:0> disable ‘member‘ 0 row(s) in 1.5270 seconds hbase(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 seconds hbase(main):004:0> enable ‘member‘ 0 row(s) in 0.6940 seconds
删除表
hbase(main):007:0> disable ‘member‘ 0 row(s) in 1.5230 seconds hbase(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 seconds hbase(main):013:0> is_disabled ‘member‘ false 0 row(s) in 0.0380 seconds
插入记录
#表明,行键,列族名,value hbase(main):016:0> put ‘member‘,‘xiaofeng‘,‘info:birthday‘,‘1987-4-17‘ 0 row(s) in 0.2140 seconds hbase(main):017:0> put ‘member‘,‘scutshuxue‘,‘info:age‘,‘24‘ 0 row(s) in 0.0240 seconds hbase(main):018:0> put ‘member‘,‘xiaofeng‘,‘info:company‘,‘alibaba‘ 0 row(s) in 0.0310 seconds hbase(main):019:0> put ‘member‘,‘xiaofeng‘,‘address:contry‘,‘china‘ 0 row(s) in 0.0250 seconds hbase(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 seconds hbase(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 seconds hbase(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 seconds hbase(main):025:0>
更新一条记录
hbase(main):025:0> put ‘member‘,‘xiaofeng‘,‘info:company‘,‘sina‘ 0 row(s) in 0.0170 seconds hbase(main):026:0> get ‘member‘,‘xiaofeng‘,‘info:company‘ COLUMN CELL info:company timestamp=1410686886831, value=sina 1 row(s) in 0.0170 seconds hbase(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 seconds hbase(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 seconds hbase(main):030:0>
删除指定行键的字段
hbase(main):030:0> delete ‘member‘,‘xiaofeng‘,‘info:company‘ 0 row(s) in 0.0960 seconds hbase(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 seconds hbase(main):032:0>
删除整行
hbase(main):033:0> deleteall ‘member‘,‘xiaofeng‘ 0 row(s) in 0.0390 seconds hbase(main):034:0>
查询表中有多少行
hbase(main):034:0> count ‘member‘ 1 row(s) in 0.0420 seconds => 1 hbase(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 seconds hbase(main):036:0>
http://hbase.apache.org/apidocs/index.html
本文出自 “晓风残月” 博客,请务必保留此出处http://kinda22.blog.51cto.com/2969503/1582574
原文地址:http://kinda22.blog.51cto.com/2969503/1582574