HBase-1.0.1学习笔记(二)HBase Shell工具使用
发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,鲁春利的工作笔记,好记性不如烂笔头hbase(main):017:0> create 't_domain', 'c_domain'0 row(s) in 0.4520 seconds=> Hbase:
千家信息网最后更新 2025年11月07日HBase-1.0.1学习笔记(二)HBase Shell工具使用
鲁春利的工作笔记,好记性不如烂笔头
hbase(main):017:0> create 't_domain', 'c_domain'0 row(s) in 0.4520 seconds=> Hbase::Table - t_domain
通过HDFS查看
HBase中行键(RowKey)是表中唯一的,并且按照字典排序由低到高存储在表中的。
hbase(main):018:0> put 't_domain', 'row1', 'c_domain:name', 'baidu.com'0 row(s) in 0.6830 secondshbase(main):019:0> put 't_domain', 'row2', 'c_domain:name', 'sina.com'0 row(s) in 0.0870 secondshbase(main):020:0> put 't_domain', 'row3', 'c_domain:name', 'mycms.com'0 row(s) in 0.0100 secondshbase(main):021:0> put 't_domain', 'row10', 'c_domain:name', 'www.163.com'0 row(s) in 0.0280 secondshbase(main):022:0> put 't_domain', 'row21', 'c_domain:name', 'www.51cto.com'0 row(s) in 0.0240 secondshbase(main):023:0> scan 't_domain'ROW COLUMN+CELL row1 column=c_domain:name, timestamp=1440340474441, value=baidu.com row10 column=c_domain:name, timestamp=1440340536382, value=www.163.com row2 column=c_domain:name, timestamp=1440340492582, value=sina.com row21 column=c_domain:name, timestamp=1440340550534, value=www.51cto.com row3 column=c_domain:name, timestamp=1440340518003, value=mycms.com 5 row(s) in 0.1350 seconds
HBase Shell工具:
选择一台HBase集群的节点(建议选择客户端节点),执行命令bin/hbase shell
看到如下命令说明已进入hbase shell环境,执行help命令可以查看帮助信息:
[hadoop@dnode1 bin]$ hbase shellHBase Shell; enter 'help' for list of supported commands.Type "exit " to leave the HBase ShellVersion 0.98.1-hadoop2, r1583035, Sat Mar 29 17:19:25 PDT 2014hbase(main):001:0> helpHBase Shell, version 0.98.1-hadoop2, r1583035, Sat Mar 29 17:19:25 PDT 2014Type '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> status3 servers, 0 dead, 3.0000 average load # 该集群有3台RegionServer,没有"死掉"的RegionServer中,平均每台有3个Region。 # HBase版本命令hbase(main):003:0> version0.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: alterAlter 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> listTABLEhttptabletb1 tb2tb3 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_namespaceAlter 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_namespaceNAMESPACEdefaulthbase ns1 3 row(s) in 11.0490 seconds hbase(main):050:0> create 'ns1:tb5', 'cf' # 列族cf0 row(s) in 12.0680 seconds => Hbase::Table - ns1:tb5hbase(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 => 2hbase(main):067:0> count 'ns1:tb5', INTERVAL => 1000002 row(s) in 0.0170 seconds => 2# 单行读hbase(main):068:0> get 'ns1:tb5', 'baidu.com'COLUMN CELLcf:address timestamp=1441006344446, value=\xE5\x8C\x97\xE4\xBA\xACcf:ipstr timestamp=1441006329572, value=61.135.169.121cf:owner timestamp=1441006321284, value=BeiJingBaiduCo.cf:reg_date timestamp=1441006335701, value=199904154 row(s) in 0.1150 seconds hbase(main):074:0> get 'ns1:tb5', 'baidu.com', 'cf:ipstr'COLUMN CELLcf:ipstr timestamp=1441006329572, value=61.135.169.1211 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 CELLcf:reg_date timestamp=1441006335701, value=199904151 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 CELLcf:ipstr timestamp=1441006329572, value=61.135.169.121cf:owner timestamp=1441006321284, value=BeiJingBaiduCo.cf:reg_date timestamp=1441006335701, value=199904153 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 其他操作略。
Thrift客户端:
略
MapReduce批量操作HBase
见http://luchunli.blog.51cto.com/2368057/1691298
命令
版本
集群
帮助
三个
客户
客户端
节点
e.g.
选择
工具
笔记
信息
字典
字符
字符串
属性
建议
引号
括号
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
软件开发中项目管理收费标准
网络安全设备ad是什么
工程狮网络安全
企业专利数据库专利探索者
菜鸟网络技术岗年薪
代理服务器如何无线共享
重庆石柱蔬菜软件开发
互联网初创公司服务器
mg国际互联网科技
java 读取服务器配置
普陀区口碑好的数据库服务内容
企业网络安全儿童画
网络安全隐患的起因
福州网络技术服务
计算机网络技术英文介绍
服务器散热风扇转速一般达到多少
查药物靶点临床信息的数据库
深圳市乐豆互联网工业科技
滇剧艺术数据库
软件开发组
奈菲影视 服务器通信
提取数据库名称
网络技术基础与计算思维期末
it网络安全公司成长史
文件服务器资源管理器包括
电子表格丢失数据库
山东商业软件开发现价
web服务器软件是干嘛的
java初始化数据库
云计算和网络安全哪个更好