1. 环境
只用文件系统,不用hdfs,也就是说不需要之前安装好hadoop分布式环境。java必须安装好。
2. 配置conf/hbase-site.xml
1 2 3 4 5 6 7 8 9 10
| <configuration> <property> <name>hbase.rootdir</name> <value>file:///home/testuser/hbase</value> </property> <property> <name>hbase.zookeeper.property.dataDir</name> <value>/home/testuser/zookeeper</value> </property> </configuration>
|
目录不用创建,hbase会自动创建。
3. 启动hbase
单机模式下会起一个jvm, 名字叫HMaster,会起一个web ui,端口是16010。
4. hbase使用
用shell:
1 2
| $ ./bin/hbase shell hbase(main):001:0>
|
创建table:
1 2 3 4
| hbase(main):002:0> create 'test', 'cf' 0 row(s) in 2.2080 seconds => Hbase::Table - test
|
list信息:
1 2 3 4 5 6
| hbase(main):003:0> list 'test' TABLE test 1 row(s) in 0.0610 seconds => ["test"]
|
put数据:
1 2 3 4 5 6 7 8
| hbase(main):008:0* put 'test', 'row1', 'cf:a', 'value1' 0 row(s) in 0.6360 seconds hbase(main):009:0> put 'test', 'row2', 'cf:b', 'value2' 0 row(s) in 0.0540 seconds hbase(main):010:0> put 'test', 'row3', 'cf:c', 'value3' 0 row(s) in 0.0290 seconds
|
scan数据:
1 2 3 4 5 6
| hbase(main):012:0> scan 'test' ROW COLUMN+CELL row1 column=cf:a, timestamp=1482133616796, value=value1 row2 column=cf:b, timestamp=1482133663870, value=value2 row3 column=cf:c, timestamp=1482133670211, value=value3 3 row(s) in 0.0930 seconds
|
获取一列数据:
1 2 3 4
| hbase(main):021:0> get 'test','row2' COLUMN CELL cf:b timestamp=1482133663870, value=value2 1 row(s) in 0.0080 seconds
|
disable table:
1 2
| hbase(main):022:0> disable 'test' 0 row(s) in 2.2930 seconds
|
删除数据:
1 2
| hbase(main):023:0> drop 'test' 0 row(s) in 1.2720 seconds
|