Hbase安裝: 分佈式模式

網站:

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

 

Hbase安裝 : 分佈式安裝

準備工作

首先需要保證已經正確的安裝了hadoop和java

配置了正確的環境變量

測試環境

echo $HADOOP_INSTALL
java -version
hadoop
hadoop version

 

 

 

配置hbase

根據版本對應關係下載並解壓正確的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

 

啓動Hbase

[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>

 

Hbase測試

[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]$

 

 

 Hbase停止

[hadoop@hadoop1 hbase]$ stop-hbase.sh 
stopping hbase.
..............
hadoop3: stopping zookeeper.
hadoop2: stopping zookeeper.
hadoop1: stopping zookeeper.

 

 


 Shell

查詢數據庫狀態, 當前服務器數量和負荷

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>

 

 

 Hbase API

http://hbase.apache.org/apidocs/index.html

 

 

 

 

 

 

 

 

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章