HBase Shell 操作

一 HBase Shell基本操作

二 HBase组命令 
 

三 general与namespace演示

四 实战
1 启动相关进程
[root@centos hbase-1.2.6]# jps
3684 HRegionServer
2758 SecondaryNameNode
3512 HMaster
3784 Jps
3033 NodeManager
2923 ResourceManager
3387 HQuorumPeer
2462 NameNode
2591 DataNode

2 HBase帮助查看
[root@centos hbase-1.2.6]# bin/hbase
Usage: hbase [<options>] <command> [<args>]
Options:
  --config DIR    Configuration direction to use. Default: ./conf
  --hosts HOSTS   Override the list in 'regionservers' file
  --auth-as-server Authenticate to ZooKeeper using servers configuration
Commands:
Some commands take arguments. Pass no args or -h for usage.
  shell           Run the HBase shell
  hbck            Run the hbase 'fsck' tool
  snapshot        Create a new snapshot of a table
  snapshotinfo    Tool for dumping snapshot information
  wal             Write-ahead-log analyzer
  hfile           Store file analyzer
  zkcli           Run the ZooKeeper shell
  upgrade         Upgrade hbase
  master          Run an HBase HMaster node
  regionserver    Run an HBase HRegionServer node
  zookeeper       Run a Zookeeper server
  rest            Run an HBase REST server
  thrift          Run the HBase Thrift server
  thrift2         Run the HBase Thrift2 server
  clean           Run the HBase clean up script
  classpath       Dump hbase CLASSPATH
  mapredcp        Dump CLASSPATH entries required by mapreduce
  pe              Run PerformanceEvaluation
  ltt             Run LoadTestTool
  version         Print the version
  CLASSNAME       Run the class named CLASSNAME

3 shell帮助
[root@centos hbase-1.2.6]# bin/hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hbase-1.2.6/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.2.6, rUnknown, Mon May 29 02:25:32 CDT 2017
hbase(main):001:0> help
HBase Shell, version 1.2.6, rUnknown, Mon May 29 02:25:32 CDT 2017
Type 'help "COMMAND"', (e.g. 'help "get"' -- the quotes are necessary) for help on a specific command.
Commands are grouped. Type 'help "COMMAND_GROUP"', (e.g. 'help "general"') for help on a command group.
COMMAND GROUPS:
  Group name: general
  Commands: status, table_help, version, whoami
  Group name: ddl
  Commands: alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, locate_region, show_filters
  Group name: namespace
  Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables
  Group name: dml
  Commands: append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserve
  Group name: tools
  Commands: assign, balance_switch, balancer, balancer_enabled, catalogjanitor_enabled, catalogjanitor_run, catalogjanitor_switch, close_region, compact, compact_rs, flush, major_compact, merge_region, move, normalize, normalizer_enabled, normalizer_switch, split, trace, unassign, wal_roll, zk_dump
  Group name: replication
  Commands: add_peer, append_peer_tableCFs, disable_peer, disable_table_replication, enable_peer, enable_table_replication, list_peers, list_replicated_tables, remove_peer, remove_peer_tableCFs, set_peer_tableCFs, show_peer_tableCFs
  Group name: snapshots
  Commands: clone_snapshot, delete_all_snapshot, delete_snapshot, list_snapshots, restore_snapshot, snapshot
  Group name: configuration
  Commands: update_all_config, update_config
  Group name: quotas
  Commands: list_quotas, set_quota
  Group name: security
  Commands: grant, list_security_capabilities, revoke, user_permission
  Group name: procedures
  Commands: abort_procedure, list_procedures
  Group name: visibility labels
  Commands: add_labels, clear_auths, get_auths, list_labels, set_auths, set_visibility
SHELL USAGE:
Quote all names in HBase Shell such as table and column names.  Commas delimit
command parameters.  Type <RETURN> after entering a command to run it.
Dictionaries of configuration used in the creation and alteration of tables are
Ruby Hashes. They look like this:
  {'key1' => 'value1', 'key2' => 'value2', ...}
and are opened and closed with curley-braces.  Key/values are delimited by the
'=>' character combination.  Usually keys are predefined constants such as
NAME, VERSIONS, COMPRESSION, etc.  Constants do not need to be quoted.  Type
'Object.constants' to see a (messy) list of all constants in the environment.
If you are using binary keys or values and need to enter them in the shell, use
double-quote'd hexadecimal representation. For example:
  hbase> get 't1', "key\x03\x3f\xcd"
  hbase> get 't1', "key\003\023\011"
  hbase> put 't1', "test\xef\xff", 'f1:', "\x01\x33\x40"
The HBase shell is the (J)Ruby IRB with the above HBase-specific commands added.
For more on the HBase Shell, see http://hbase.apache.org/book.html

4 对表的shell操作
hbase(main):001:0> create 'user','info'
0 row(s) in 11.7620 seconds
=> Hbase::Table - user
hbase(main):002:0> list
TABLE                                                                           
user                                                                            
1 row(s) in 0.1700 seconds
=> ["user"]
hbase(main):003:0> put 'user','rk0001','info:name','lisi'
0 row(s) in 0.5160 seconds
hbase(main):001:0> put 'user','rk0002','info:name','zhangsan'
0 row(s) in 0.9940 seconds
hbase(main):002:0> put 'user','rk0003','info:name','wangwu'
0 row(s) in 0.1240 seconds
hbase(main):003:0> put 'user','rk0003','info:age','20'
0 row(s) in 0.0740 seconds
hbase(main):004:0> scan 'user'
ROW                   COLUMN+CELL                                               
rk0001               column=info:name, timestamp=1514378933219, value=lisi     
rk0002               column=info:name, timestamp=1514379059951, value=zhangsan
rk0003               column=info:age, timestamp=1514379128679, value=20        
rk0003               column=info:name, timestamp=1514379079748, value=wangwu   
3 row(s) in 0.1410 seconds
hbase(main):005:0> get 'user','rk0001'
COLUMN                CELL                                                      
info:name            timestamp=1514378933219, value=lisi                       
1 row(s) in 0.1230 seconds
hbase(main):006:0> deleteall 'user','rk0001'
0 row(s) in 0.1590 seconds
hbase(main):007:0> scan 'user'
ROW                   COLUMN+CELL                                               
rk0002               column=info:name, timestamp=1514379059951, value=zhangsan
rk0003               column=info:age, timestamp=1514379128679, value=20        
rk0003               column=info:name, timestamp=1514379079748, value=wangwu   
2 row(s) in 0.0810 seconds
hbase(main):008:0> disable 'user'
0 row(s) in 3.0900 seconds
hbase(main):009:0> drop 'user'
0 row(s) in 2.5120 seconds
hbase(main):011:0> list
TABLE                                                                           
0 row(s) in 0.0640 seconds
=> []

5 组命令的使用
hbase(main):016:0* status
1 active master, 0 backup masters, 1 servers, 0 dead, 2.0000 average load
hbase(main):017:0> whoami
root (auth:SIMPLE)
    groups: root

6 namespace使用
hbase(main):018:0> list_namespace
NAMESPACE                                                                       
default                                                                         
hbase                                                                           
2 row(s) in 0.2220 seconds
hbase(main):019:0> create_namespace 'ns1'
0 row(s) in 0.2110 seconds
hbase(main):020:0> list_namespace
NAMESPACE                                                                       
default                                                                         
hbase                                                                           
ns1        
hbase(main):022:0> drop_namespace 'ns1'
0 row(s) in 0.2880 seconds
hbase(main):023:0> list_namespace
NAMESPACE                                                                       
default                                                                         
hbase                                                                           
2 row(s) in 0.0180 seconds

五 参考
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值