可以通过自带的shell命令来进行基本的操作:
[root@localhost hbase-0.90.3]# bin/hbase shell
hbase(main):002:0> create 'test','cf'
0 row(s) in 0.9940 seconds
hbase(main):019:0> list
TABLE
test
1 row(s) in 0.0290 seconds
hbase(main):022:0> put 'test', 'row1', 'cf:a', 'value1'
0 row(s) in 0.2130 seconds
hbase(main):023:0> put 'test', 'row2', 'cf:b', 'value2'
0 row(s) in 0.0120 seconds
hbase(main):024:0> put 'test', 'row3', 'cf:c', 'value3'
0 row(s) in 0.0130 seconds
hbase(main):025:0> scan 'test'
ROW COLUMN+CELL
row1 column=cf:a, timestamp=1310027460885, value=value1
row2 column=cf:b, timestamp=1310027469458, value=value2
row3 column=cf:c, timestamp=1310027476262, value=value3
3 row(s) in 0.0870 seconds
hbase(main):026:0> get 'test', 'row1'
COLUMN CELL
cf:a timestamp=1310027460885, value=value1
1 row(s) in 0.0250 seconds
hbase(main):027:0> disable 'test'
0 row(s) in 2.0920 seconds
hbase(main):029:0> drop 'test'
0 row(s) in 1.1440 seconds
hbase(main):030:0> exit
hbase(main):002:0> create 'test','cf'
0 row(s) in 0.9940 seconds
hbase(main):019:0> list
TABLE
test
1 row(s) in 0.0290 seconds
hbase(main):022:0> put 'test', 'row1', 'cf:a', 'value1'
0 row(s) in 0.2130 seconds
hbase(main):023:0> put 'test', 'row2', 'cf:b', 'value2'
0 row(s) in 0.0120 seconds
hbase(main):024:0> put 'test', 'row3', 'cf:c', 'value3'
0 row(s) in 0.0130 seconds
hbase(main):025:0> scan 'test'
ROW COLUMN+CELL
row1 column=cf:a, timestamp=1310027460885, value=value1
row2 column=cf:b, timestamp=1310027469458, value=value2
row3 column=cf:c, timestamp=1310027476262, value=value3
3 row(s) in 0.0870 seconds
hbase(main):026:0> get 'test', 'row1'
COLUMN CELL
cf:a timestamp=1310027460885, value=value1
1 row(s) in 0.0250 seconds
hbase(main):027:0> disable 'test'
0 row(s) in 2.0920 seconds
hbase(main):029:0> drop 'test'
0 row(s) in 1.1440 seconds
hbase(main):030:0> exit
停止Hbase实例:
[root@localhost hbase-0.90.3]# ./bin/stop-hbase.sh
stopping hbase......
stopping hbase......
如果使用PHP操作Hbase,可以使用Facebook开源出来的thrift,官网是:http://thrift.apache.org/ ,它是一个类似ice的中间件,用于不同系统语言间信息交换。首先下载最新的版本0.6.1:
[root@localhost hbase]# wget http://mirror.bjtu.edu.cn/apache//thrift/0.6.1/thrift-0.6.1.tar.gz
安装需要的依赖包:
[root@localhost thrift-0.6.1]# sudo yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel
编译安装:
[root@localhost thrift-0.6.1]# ./configure --prefix=/home/banping/hbase/thrift --with-php-config=/usr/local/php/bin/
[root@localhost thrift-0.6.1]# make
[root@localhost thrift-0.6.1]# make install
[root@localhost thrift-0.6.1]# make
[root@localhost thrift-0.6.1]# make install
生成php和hbase的接口文件:
[root@localhost hbase]# thrift/bin/thrift --gen php /home/banping/hbase/hbase-0.90.3/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift
[root@localhost hbase]# cd gen-php/Hbase
[root@localhost Hbase]# ll
total 320
-rw-r--r-- 1 root root 285433 Jul 7 19:22 Hbase.php
-rw-r--r-- 1 root root 27426 Jul 7 19:22 Hbase_types.php
[root@localhost hbase]# cd gen-php/Hbase
[root@localhost Hbase]# ll
total 320
-rw-r--r-- 1 root root 285433 Jul 7 19:22 Hbase.php
-rw-r--r-- 1 root root 27426 Jul 7 19:22 Hbase_types.php
把PHP客户端需要的包及刚才生成的接口文件复制出来供php程序调用:
[root@localhost Hbase]# cp -a /home/banping/hbase/thrift-0.6.1/lib/php /home/webtest/thrift/
[root@localhost Hbase]# cd /home/webtest/thrift/
[root@localhost thrift]# mkdir packages
[root@localhost thrift]# cp -a /home/banping/hbase/gen-php/Hbase /home/webtest/thrift/packages
[root@localhost Hbase]# cd /home/webtest/thrift/
[root@localhost thrift]# mkdir packages
[root@localhost thrift]# cp -a /home/banping/hbase/gen-php/Hbase /home/webtest/thrift/packages
启动hbase和thrift进程:
[root@localhost hbase-0.90.3]# ./bin/start-hbase.sh
[root@localhost hbase-0.90.3]# ./bin/hbase-daemon.sh start thrift
starting thrift, logging to /home/banping/hbase/hbase-0.90.3/bin/../logs/hbase-root-thrift-localhost.localdomain.out
[root@localhost hbase-0.90.3]# ./bin/hbase-daemon.sh start thrift
starting thrift, logging to /home/banping/hbase/hbase-0.90.3/bin/../logs/hbase-root-thrift-localhost.localdomain.out
thrift服务默认监听的端口是9090。至此测试环境搭建完毕。