(一)簡介:html
HBase是一個分佈式的、面向列的開源數據庫。HBase是Google Bigtable的開源實現,它利用Hadoop HDFS做爲其文件存儲系統,利用Hadoop MapReduce來處理HBase中的海量數據,利用Zookeeper做爲協同服務。 linux
表結構:sql
HBase以表的形式存儲數據。表有行和列組成。列劃分爲若干個列族/列簇(column family)。
shell
Row Key | column-family1 | column-family2 | column-family3 | |||
column1 | column2 | column1 | column2 | column3 | column1 | |
key1 | ||||||
key2 | ||||||
key3 |
如上圖所示,key一、key二、key3是三條記錄的惟一的row key值,column-family一、column-family二、column-family3是三個列族,每一個列族下又包括幾列,好比column-family1這個列族下包括兩列,名字是column1和column2。t1:ab ,t2:dx是由row key1和column-family1—column1惟一肯定的一個單元cell。這個cell中有兩個數據,ab和dx。兩個值的時間戳不同,分別是t1,t2,hbase會返回最新時間的值給請求者。數據庫
名詞定義:apache
1)Row Key
與nosql數據庫們同樣,row key是用來檢索記錄的主鍵。訪問hbase table中的行,只有三種方式:ubuntu
tar zxvf hbase-0.94.10.tar.gz3. 修改數據存儲目錄,編輯 conf/hbase-site.xml 配置hbase.rootdir
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>hbase.rootdir</name> <value>存儲目錄</value> </property> </configuration>4. 啓動Hbase
./bin/start-hbase.shstarting master, logging to /home/onlyone/software/hbase-0.94.10/bin/../logs/hbase-onlyone-master-ubuntu.out
./bin/hbase shell
name | grade | course | |
math | art | ||
Tom | 6 | 99 | 100 |
Yangli | 15 |
hbase(main):001:0> create 'scores' ,'grade','course'
hbase(main):002:0> list TABLE scores test 2 row(s) in 0.1320 secondsdescribe命令來查看錶結構
hbase(main):001:0> describe 'scores' DESCRIPTION ENABLED 'scores', {NAME => 'course', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => true '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', BLOC KCACHE => 'true'}, {NAME => 'grade', DATA_BLOCK_ENCODING => 'NONE', BLOOMF ILTER => '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 => 'tru e', BLOCKCACHE => 'true'} 1 row(s) in 0.7240 secondsps:記得全部的表名、列名都須要加上引號
hbase(main):007:0> put 'scores','Tom','grade','6' 0 row(s) in 0.0790 seconds hbase(main):008:0> put 'scores','Tom','course:math','99' 0 row(s) in 0.0060 seconds hbase(main):009:0> put 'scores','Tom','course:art','100' 0 row(s) in 0.0100 seconds //掃描表數據 hbase(main):010:0> scan 'scores' ROW COLUMN+CELL Tom column=course:art, timestamp=1376493359159, value=100 Tom column=course:math, timestamp=1376493340514, value=99 Tom column=grade:, timestamp=1376493316800, value=6 1 row(s) in 0.0530 secondsput命令比較簡單:
hbase(main):012:0> get 'scores' ,'Tom' COLUMN CELL course:art timestamp=1376493359159, value=100 course:math timestamp=1376493340514, value=99 grade: timestamp=1376493316800, value=6 3 row(s) in 0.0170 seconds hbase(main):013:0> get 'scores' ,'Tom','grade' COLUMN CELL grade: timestamp=1376493316800, value=6 1 row(s) in 0.0080 seconds hbase(main):014:0> get 'scores' ,'Tom','course:math' COLUMN CELL course:math timestamp=1376493340514, value=99 1 row(s) in 0.0250 seconds
hbase(main):016:0> delete 'scores' ,'Tom','grade' 0 row(s) in 0.1350 seconds hbase(main):017:0> scan 'scores' ROW COLUMN+CELL Tom column=course:art, timestamp=1376493359159, value=100 Tom column=course:math, timestamp=1376493340514, value=99 1 row(s) in 0.1380 seconds
hbase(main):018:0> count 'scores' 1 row(s) in 0.8500 seconds
shell test.hbaseshell參考資料: http://www.jb51.net/article/31172.htm