Ubuntu 安裝HBase

下載:http://mirror.bit.edu.cn/apache/hbase/stable/

官方指南:http://abloz.com/hbase/book.html


安裝配置:

解壓:

tar -xzvf hbase-0.96.0-hadoop1-bin.tar.gz

進入$hbase/lib下查看相關的hadoop包,看是哪個版本的hadoop。


此處只記錄僞分佈式Hbase的安裝。


配置參數,修改hbase-site.xml:

<configuration>
  ...
  <property>
    <name>hbase.rootdir</name>
    <value>hdfs://localhost:9000/hbase</value>
    <description>The directory shared by RegionServers.
    </description>
  </property>
  <property>
    <name>dfs.replication</name>
    <value>1</value>
    <description>The replication count for HLog & HFile storage. Should not be greater than HDFS datanode count.
    </description>
  </property>
  ...
</configuration>


僞分佈式啓動:

僞分佈式是基於HDFS的,所以需要先啓動HDFS.

之後啓動HBase

sh start-hbase.sh


不出意外的報錯:

dat@dat-HP:/opt/hbase-0.96/bin$ sh start-hbase.sh 
start-hbase.sh: 79: /opt/hbase-0.96/bin/hbase-config.sh: [[: not found
start-hbase.sh: 88: /opt/hbase-0.96/bin/hbase-config.sh: [[: not found
start-hbase.sh: 53: [: false: unexpected operator

localhost: zookeeper running as process 24164. Stop it first.
starting master, logging to /opt/hbase-0.96/bin/../logs/hbase-dat-master-dat-HP.out
Could not start ZK at requested port of 2181.  ZK was started at port: -1.  Aborting as clients (e.g. shell) will not be able to find this ZK quorum.

看樣子是2181被佔用了,查看佔用2181端口的進程:

 lsof -i:2181

dat@dat-HP:/opt/hbase-0.96/logs$ lsof -i:2181
COMMAND   PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
java    24164  dat   87u  IPv6 2800953      0t0  TCP *:2181 (LISTEN)

ps -ef|grep 24164

dat@dat-HP:/opt/hbase-0.96/logs$ ps -ef|grep 24164
dat      24164 24151  0 10:09 ?        00:00:03 /opt/jdk1.7.0_25/bin/java -Dproc_zookeeper -XX:OnOutOfMemoryError=kill -9 %p -Xmx1000m -XX:+UseConcMarkSweepGC -Dhbase.log.dir=/opt/hbase-0.96/bin/../logs -Dhbase.log.file=hbase-dat-zookeeper-dat-HP.log -Dhbase.home.dir=/opt/hbase-0.96/bin/.. -Dhbase.id.str=dat -Dhbase.root.logger=INFO,RFA -Dhbase.security.logger=INFO,RFAS org.apache.hadoop.hbase.zookeeper.HQuorumPeer start

顯示已經是hbase的zookeeper服務,殺掉pid,重試,

dat@dat-HP:/opt/hbase-0.96/bin$ ./start-hbase.sh 
starting master, logging to /opt/hbase-0.96/bin/../logs/hbase-dat-master-dat-HP.out

正常啓動,檢測jps

dat@dat-HP:/opt/hbase-0.96/bin$ jps
25644 HMaster
23468 TaskTracker
23199 SecondaryNameNode
23307 JobTracker
25849 Jps
22827 NameNode
23031 DataNode

正常。。。


HBase Shell

編輯/etc/profile加入hbase_home,重新生效,source /etc/profile

export PIG_INSTALL=/opt/pig-0.12.0
export PATH=$PATH:$PIG_INSTALL/bin
export PIG_CLASSPATH=/opt/hadoop-1.2.1/conf
export HIVE_HOME=/opt/hive-0.12.0
export PATH=$HIVE_HOME/bin:$HIVE_HOME/conf:$PATH
export ANT_HOME=/opt/ant
export PATH=$PATH:$ANT_HOME/bin
export HBASE_HOME=/opt/hbase-0.96
export PATH=$PATH:$HBASE_HOME/bin
hbase shell進入:
dat@dat-HP:/opt/hbase-0.96/bin$ hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.96.0-hadoop1, r1531434, Fri Oct 11 15:11:29 PDT 2013

hbase(main):001:0> 


輸入help,會列出hbase shell所支持的命令

shutdown是關閉hbase集羣,exit是退出hbase shell。


HBase Shell 練習

建表

hbase(main):006:0> create 'test','cf'


列出所有表

hbase(main):007:0> list
TABLE                                                                               
test                                                                                
1 row(s) in 0.0440 seconds


=> ["test"]


插入數據

hbase(main):008:0> put 'test','row1','cf:a','value1'
0 row(s) in 0.0750 seconds


hbase(main):009:0> put 'test','row2','cf:b','value2'
0 row(s) in 0.0080 seconds


hbase(main):010:0> put 'test','row3','cf:c','value3'
0 row(s) in 0.0060 seconds


檢查插入情況

hbase(main):011:0> scan 'test'
ROW                    COLUMN+CELL                                                  
 row1                  column=cf:a, timestamp=1386389158263, value=value1           
 row2                  column=cf:b, timestamp=1386389170821, value=value2           
 row3                  column=cf:c, timestamp=1386389185954, value=value3           
3 row(s) in 0.0450 seconds

get一行

hbase(main):012:0> get 'test','row2'
COLUMN                 CELL                                                         
 cf:b                  timestamp=1386389170821, value=value2                        
1 row(s) in 0.0140 seconds


disable之後drop表

hbase(main):013:0> disable 'test'
0 row(s) in 1.4220 seconds


hbase(main):014:0> drop 'test'
0 row(s) in 0.2740 seconds


hbase(main):015:0> list
TABLE                                                                               
0 row(s) in 0.0270 seconds


=> []


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