网上已经有很多关于这方面的资料了,但是还是需要将自己搭建的过程写下来,毕竟每个人的机器配置不同,遇到的问题也就不同,全当自己做个网络笔记吧。
1 在http://apache.dataguru.cn/hbase/hbase-0.90.5/上面下载hbase,然后将其解压。
2 修改con/下面的hbase-env.sh,export JAVA_HOME=you java home
3 修改con/下面的hbase-site.xml因为是单机启动,所以只设定了HBase写入的本地路径,修改如下:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hbase.rootdir</name>
<value>/home/hbase</value>
</property>
</configuration>
单机版的做以上修改就可以跑起来,在目录下面输入bin/start-hbase.sh,就可以启动hbase
以下是hbase的测试命令:
1、用shell来连接HBase.
root@ubuntu:/usr/hbase/hbase-0.90.4# bin/hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.90.4, r1150278, Sun Jul 24 15:53:29 PDT 2011
3、 建表操作演示
hbase(main):004:0> create 'table1','col1'
0 row(s) in 1.1070 seconds
hbase(main):005:0> list
TABLE
table1
test1
2 row(s) in 0.0210 seconds
hbase(main):006:0> put 'table1','row1','col1:a','value1'
0 row(s) in 0.2710 seconds
hbase(main):008:0> put 'table1','row2','col1:b','value2'
0 row(s) in 0.0090 seconds
hbase(main):009:0> put 'table1','row3','col1:c','value3'
0 row(s) in 0.0070 seconds
hbase(main):010:0>
4、 用scan查看表所有数据
hbase(main):010:0> scan 'table1'
ROW COLUMN+CELL
row1 column=col1:a, timestamp=1317180621803, value=value1
row2 column=col1:b, timestamp=1317180679999, value=value2
row3 column=col1:c, timestamp=1317180708854, value=value3
3 row(s) in 0.0570 seconds
5、 用get查看单行数据
hbase(main):011:0> get 'table1','row1'
COLUMN CELL
col1:a timestamp=1317180621803, value=value1
1 row(s) in 0.0160 seconds
6、 用disable和drop删除表
hbase(main):017:0> disable 'table1'
0 row(s) in 2.0470 seconds
hbase(main):018:0> drop 'table1'
0 row(s) in 0.0960 seconds
hbase(main):019:0> list
TABLE
1 row(s) in 0.0170 seconds