设为首页 收藏本站
查看: 875|回复: 0

HBase-1.0.1学习笔记(二)HBase Shell工具使用

[复制链接]

尚未签到

发表于 2018-8-25 08:12:11 | 显示全部楼层 |阅读模式
[hadoop@dnode1 bin]$ hbase shell  
HBase Shell; enter 'help' for list of supported commands.
  
Type "exit" to leave the HBase Shell
  
Version 0.98.1-hadoop2, r1583035, Sat Mar 29 17:19:25 PDT 2014
  

  
hbase(main):001:0> help
  
HBase Shell, version 0.98.1-hadoop2, r1583035, Sat Mar 29 17:19:25 PDT 2014
  
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, 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, incr, put, scan, truncate, truncate_preserve
  

  
  Group name: tools
  
  Commands: assign, balance_switch, balancer, catalogjanitor_enabled, catalogjanitor_run, catalogjanitor_switch, close_region, compact, flush, hlog_roll, major_compact, merge_region, move, split, trace, unassign, zk_dump
  

  
  Group name: replication
  
  Commands: add_peer, disable_peer, enable_peer, list_peers, list_replicated_tables, remove_peer, set_peer_tableCFs, show_peer_tableCFs
  

  
  Group name: snapshot
  
  Commands: clone_snapshot, delete_snapshot, list_snapshots, rename_snapshot, restore_snapshot, snapshot
  

  
  Group name: security
  
  Commands: grant, revoke, user_permission
  

  
  Group name: visibility labels
  
  Commands: add_labels, clear_auths, get_auths, set_auths
  

  
# 查看集群状态
  
hbase(main):002:0> status
  
3 servers, 0 dead, 3.0000 average load
  

  
# 该集群有3台RegionServer,没有”死掉“的RegionServer中,平均每台有3个Region。
  

  
# HBase版本命令
  
hbase(main):003:0> version
  
0.98.1-hadoop2, r1583035, Sat Mar 29 17:19:25 PDT 2014
  

  
# 返回值为由逗号分割的三个部分,0.98.1-hadoop2表示HBase版本号,r1583035表示修订版本,第三部分为编译HBase的时间。
  

  
# 查看ddl命令组的帮助
  
hbase(main):006:0> help 'ddl'
  
Command: alter
  
Alter a table. Depending on the HBase setting ("hbase.online.schema.update.enable"),
  
the table must be disabled or not to be altered (see help 'disable').
  
You can add/modify/delete column families, as well as change table
  
configuration. Column families work similarly to create; column family
  
spec can either be a name string, or a dictionary with NAME attribute.
  
Dictionaries are described on the main help command output.
  

  
For example, to change or add the 'f1' column family in table 't1' from
  
current value to keep a maximum of 5 cell VERSIONS, do:
  

  
  hbase> alter 't1', NAME => 'f1', VERSIONS => 5
  

  
You can operate on several column families:
  

  
  hbase> alter 't1', 'f1', {NAME => 'f2', IN_MEMORY => true}, {NAME => 'f3', VERSIONS => 5}
  

  
// 略
  

  
# 示例:
  
hbase(main):033:0> create 'tb1', {NAME => 'cf1', VERSIONS => 5}
  
0 row(s) in 20.1040 seconds
  

  
=> Hbase::Table - tb1
  

  
hbase(main):035:0> create 'tb2', {NAME => 'cf1'}, {NAME => 'cf2'}, {NAME => 'cf3'}
  
0 row(s) in 19.1130 seconds
  

  
=> Hbase::Table - tb2
  

  
# 上述命令的简化版本如下
  
hbase(main):036:0> create 'tb3', 'cf1'
  
0 row(s) in 6.8610 seconds
  

  
=> Hbase::Table - tb3
  

  
hbase(main):037:0> create 'tb4', 'cf1', 'cf2', 'cf3'  # 三个列族
  
0 row(s) in 6.2010 seconds
  

  
hbase(main):045:0> list
  
TABLE
  
httptable
  
tb1
  
tb2
  
tb3
  
tb4
  
testtable
  
6 row(s) in 2.3430 seconds
  

  
=> ["httptable", "tb1", "tb2", "tb3", "tb4", "testtable"]
  
hbase(main):046:0>
  

  
# 说明:
  
# => 表示赋值,如{NAME = 'cf1'};
  
# 字符串必须使用单引号引起来,如'cf2';
  
# 如果创建表时需要指定列族的特定属性,需要花括号括起来,如{NAME='cf1', VERSIONS=5}
  

  
hbase(main):025:0> help 'namespace'
  
Command: alter_namespace
  
Alter namespace properties.
  

  
To add/modify a property:
  

  
  hbase> alter_namespace 'ns1', {METHOD => 'set', 'PROERTY_NAME' => 'PROPERTY_VALUE'}
  

  
To delete a property:
  

  
  hbase> alter_namespace 'ns1', {METHOD => 'unset', NAME=>'PROERTY_NAME'}
  

  
// 略
  

  
hbase(main):048:0> create_namespace 'ns1'
  
0 row(s) in 4.7320 seconds
  

  
hbase(main):049:0> list_namespace
  
NAMESPACE
  
default
  
hbase
  
ns1
  
3 row(s) in 11.0490 seconds
  

  
hbase(main):050:0> create 'ns1:tb5', 'cf' # 列族cf
  
0 row(s) in 12.0680 seconds
  

  
=> Hbase::Table - ns1:tb5
  
hbase(main):051:0> list_namespace_tables 'ns1'
  
TABLE
  
tb5
  
1 row(s) in 2.1220 seconds
  

  
hbase(main):052:0>
  

  
# 查看DML命令的帮助
  
hbase(main):026:0> help 'dml'
  

  
hbase(main):052:0> put 'ns1:tb5', 'baidu.com', 'cf:owner', 'BeiJingBaiduCo.'
  
0 row(s) in 0.4400 seconds
  

  
hbase(main):053:0> put 'ns1:tb5', 'baidu.com', 'cf:ipstr', '61.135.169.121'
  
0 row(s) in 1.1640 seconds
  

  
hbase(main):054:0> put 'ns1:tb5', 'baidu.com', 'cf:reg_date', '19990415'
  
0 row(s) in 0.3530 seconds
  

  
hbase(main):055:0> put 'ns1:tb5', 'baidu.com', 'cf:address', '北京'
  
0 row(s) in 2.7540 seconds
  

  
hbase(main):056:0> put 'ns1:tb5', 'alibaba.com', 'cf:ipstr', '205.204.101.42'
  
0 row(s) in 1.2040 seconds
  

  
# 统计表的行数
  
hbase(main):064:0> count 'tb5'
  

  
ERROR: Unknown table tb5!
  
hbase(main):066:0> count 'ns1:tb5'
  
2 row(s) in 0.3110 seconds
  

  
=> 2
  
hbase(main):067:0> count 'ns1:tb5', INTERVAL => 100000
  
2 row(s) in 0.0170 seconds
  

  
=> 2
  
# 单行读
  
hbase(main):068:0> get 'ns1:tb5', 'baidu.com'
  
COLUMN       CELL
  
cf:address     timestamp=1441006344446, value=\xE5\x8C\x97\xE4\xBA\xAC
  
cf:ipstr      timestamp=1441006329572, value=61.135.169.121
  
cf:owner      timestamp=1441006321284, value=BeiJingBaiduCo.
  
cf:reg_date    timestamp=1441006335701, value=19990415
  
4 row(s) in 0.1150 seconds
  

  
hbase(main):074:0> get 'ns1:tb5', 'baidu.com', 'cf:ipstr'
  
COLUMN        CELL
  
cf:ipstr      timestamp=1441006329572, value=61.135.169.121
  
1 row(s) in 0.0200 seconds
  

  
hbase(main):075:0>
  
# 如果COLUMN未指定column family则会提示错误
  
# ERROR: Unknown column family! Valid column names: cf:*
  
hbase(main):076:0> get 'ns1:tb5', 'baidu.com', {COLUMN => 'cf:reg_date'}
  
COLUMN                 CELL
  
cf:reg_date            timestamp=1441006335701, value=19990415
  
1 row(s) in 0.0170 seconds
  

  
hbase(main):077:0>
  

  
# 扫描表
  
scan 'hbase:meta'
  
scan 'hbase:meta', {COLUMNS => 'info:regioninfo'}
  

  
# 删除列
  
hbase(main):004:0> delete 'ns1:tb5', 'baidu.com', 'cf:address'
  
0 row(s) in 0.2260 seconds
  

  
hbase(main):005:0> get 'ns1:tb5', 'baidu.com'
  
COLUMN      CELL
  
cf:ipstr    timestamp=1441006329572, value=61.135.169.121
  
cf:owner    timestamp=1441006321284, value=BeiJingBaiduCo.
  
cf:reg_date   timestamp=1441006335701, value=19990415
  
3 row(s) in 0.0210 seconds
  

  
# 清空表
  
hbase(main):006:0> truncate 'ns1:tb5'
  
Truncating 'ns1:tb5' table (it may take a while):
  
- Disabling table...
  
- Dropping table...
  
- Creating table...
  
0 row(s) in 76.4690 seconds
  

  
hbase(main):007:0> get 'ns1:tb5', 'baidu.com'
  
COLUMN       CELL
  
0 row(s) in 0.0480 seconds
  

  
其他操作略。



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-556159-1-1.html 上篇帖子: shell中字符串的截取方法、cut基本用法 下篇帖子: shell脚本练习后续可能继续追加~~~
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表