HBase学习(二) HBase Shell 操作基本命令

通过使用HBase Shell,用命令行和HBase进行交互。

1、启动HBase Shell

[xxxx@localhost bin]$ ./hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.94.24, r68ed793a1d89226f8fb1ee1ee618c1e7779d46cd, Mon Sep 29 23:09:31 UTC 2014

hbase(main):001:0> 

2、查看Hbase中的表

hbase(main):001:0> list
TABLE                                                                                                                               
mytable                                                                                                                             
mytable2                                                                                                                            
2 row(s) in 0.4670 seconds

hbase(main):002:0> 

3、创建表,testtable:表名,cf:列族

hbase(main):002:0> create 'testtable','cf'
0 row(s) in 1.4170 seconds

hbase(main):003:0> list
TABLE                                                                                                                               
mytable                                                                                                                             
mytable2                                                                                                                            
testtable                                                                                                                           
3 row(s) in 0.0240 seconds

hbase(main):004:0> 

4、写数据

hbase(main):004:0> put 'testtable','first','cf:message','hello Hbase'
0 row(s) in 0.0610 seconds

hbase(main):005:0> put 'testtable','second','cf:foo',0x0
0 row(s) in 0.0160 seconds

hbase(main):006:0> put 'testtable','third','cf:bar',3.1415926
0 row(s) in 0.0230 seconds

hbase(main):007:0> 

5、读数据

hbase(main):013:0> get 'testtable','first'
COLUMN                             CELL                                                                                             
 cf:message                        timestamp=1419268133154, value=hello Hbase                                                       
1 row(s) in 0.0150 seconds

hbase(main):014:0> scan 'testtable'
ROW                                COLUMN+CELL                                                                                      
 first                             column=cf:message, timestamp=1419268133154, value=hello Hbase                                    
 second                            column=cf:foo, timestamp=1419268974405, value=0                                                  
 third                             column=cf:bar, timestamp=1419268992995, value=3.1415926                                          
3 row(s) in 0.0470 seconds

hbase(main):015:0> 


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Hbase 基本操作类 static { //此处可以使用hbase的配置文件,也可以通过代码来实例化hbase连接 /* * Configuration HBASE_CONFIG = new Configuration(); * HBASE_CONFIG.set("hbase.zookeeper.quorum", "10.229.171.45"); * HBASE_CONFIG.set("hbase.zookeeper.property.clientPort", "2181"); * HBASE_CONFIG.set("hbase.zookeeper.quorum","10.233.92.85,10.233.92.86,10.233.92.88"); * HBASE_CONFIG.set("hbase.zookeeper.property.clientPort", "2181"); * HBASE_CONFIG.set("zookeeper.znode.parent", "/hbase-unsecure"); conf = HBaseConfiguration.create(HBASE_CONFIG); */ conf = HBaseConfiguration.create(); if("kerberos".equals(conf.get("hbase.security.authentication"))){ try { //设置hadoop.security.authentication为kerberos conf.set("hadoop.security.authentication", "kerberos"); //获取kerberos配置文件路径(krb为kerberos配置文件) String krbStr=Thread.currentThread().getContextClassLoader().getResource("krb").getFile(); //获取用户票据hezhong路径(hezhong为给合众分配的用户配置文件) String keyStr=Thread.currentThread().getContextClassLoader().getResource("jdzy").getFile(); //初始化配置文件 System.setProperty("java.security.krb5.conf", krbStr); //使用用户hezhong登录 UserGroupInformation.setConfiguration(conf); UserGroupInformation.loginUserFromKeytab("jdzy/f04345e6-70c1-448a-9bbb-4ac6b4c0109b@POLICE.COM", keyStr); } catch (IOException e) { e.printStackTrace(); } } tablePool = new HTablePool(conf, poolsize); logger.debug("create hbase connection success"); // System.out.println("create hbase connection success"); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值