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


=> []


你可能感兴趣的:(Ubuntu 安装HBase)