hbase本地模式-安装及基本测试

解压缩hbase二进制安装文件到/opt目录下:
#tar -zxvf hbase-0.98.6-cdh5.3.6.tar.gz -C /opt/cdh-5.3.6/

编辑配置文件,这里仅配置数据目录,如果不指定数据目录,默认hbase数据存储在/tmp目录下:
#vim conf/hbase-site.xml

    <property>
         <name>hbase.rootdir</name>
         <value>file:///opt/hbase0986</value>
     </property>
    
创建hbase数据目录:
#mkdir -p /opt/hbase0986
#chown -R hadoop:hadoop /opt/hbase0986

启动hbase服务并且检查hbase运行状态:
#cd /opt/cdh-5.3.6/hbase-0.98.6/
#bin/start-hbase.sh
#bin/hbase shell
hbase(main):001:0> status
1 servers, 0 dead, 2.0000 average load

以上信息表明hbase已经启动并且正在运行。至此,hbase本地模式安装完成。

下面进行一些基本测试:

创建一张测试表并且新增几条数据:
hbase(main):002:0> create 'testtable','colfaml'
0 row(s) in 0.2570 seconds

=> Hbase::Table - testtable
hbase(main):003:0> list 'testtable'
TABLE                                                                                                                                                                                                    
testtable                                                                                                                                                                                                
1 row(s) in 0.0160 seconds

=> ["testtable"]
hbase(main):004:0> put 'testtable','myrow-1','colfaml:q1','value-1'
0 row(s) in 0.0930 seconds

hbase(main):005:0> put 'testtable','myrow-2','colfaml:q2','value-2'
0 row(s) in 0.0050 seconds

hbase(main):006:0> put 'testtable','myrow-3','colfaml:q3','value-3'
0 row(s) in 0.0060 seconds

hbase(main):007:0> put 'testtable','myrow-2','colfaml:q3','value-3'
0 row(s) in 0.0040 seconds

通过scan检索数据:

hbase(main):012:0> scan 'testtable'
ROW                                                 COLUMN+CELL                                                                                                                                          
  myrow-1                                            column=colfaml:q1, timestamp=1495836746559, value=value-1                                                                                            
  myrow-2                                            column=colfaml:q2, timestamp=1495836769808, value=value-2                                                                                            
  myrow-2                                            column=colfaml:q3, timestamp=1495836883408, value=value-3                                                                                            
  myrow-3                                            column=colfaml:q3, timestamp=1495836780730, value=value-3                                                                                            
3 row(s) in 0.0310 seconds

通过get命令可以获得单个文件的值:

hbase(main):022:0> get 'testtable','myrow-1'
COLUMN                                              CELL                                                                                                                                                 
  colfaml:q1                                         timestamp=1495836746559, value=value-1                                                                                                               
1 row(s) in 0.0060 seconds

hbase(main):023:0> get 'testtable','myrow-2'
COLUMN                                              CELL                                                                                                                                                 
  colfaml:q2                                         timestamp=1495836769808, value=value-2                                                                                                               
  colfaml:q3                                         timestamp=1495836883408, value=value-3                                                                                                               
2 row(s) in 0.0100 seconds

通过delete命令可以删除数据:

hbase(main):027:0> delete 'testtable','myrow-2','colfaml:q3'
0 row(s) in 0.0070 seconds

hbase(main):028:0> scan 'testtable'
ROW                                                 COLUMN+CELL                                                                                                                                          
  myrow-1                                            column=colfaml:q1, timestamp=1495836746559, value=value-1                                                                                            
  myrow-2                                            column=colfaml:q2, timestamp=1495836769808, value=value-2                                                                                            
  myrow-3                                            column=colfaml:q3, timestamp=1495836780730, value=value-3                                                                                            
3 row(s) in 0.0260 seconds

删除表也很简单,不过hbase在删除表之前要先禁用表:

hbase(main):029:0> disable 'testtable'
0 row(s) in 1.2320 seconds

hbase(main):030:0> drop 'testtable'
0 row(s) in 0.1620 seconds

通过exit命令退出hbase shell:

hbase(main):031:0> exit

停止hbase守护进程:

$ bin/stop-hbase.sh
stopping hbase...............

至此,我们完成了一个从安装hbase到对表的创建,增删改查相关的操作,最终删除表,并且停止hbase服务的完整流程。

posted @ 2017-07-19 14:00  ChavinKing  阅读(2832)  评论(0编辑  收藏  举报