HBase学习之路 (三)HBase集群Shell操作
进入HBase命令行
在你安装的随意台服务器节点上,执行命令:hbase shell,会进入到你的 hbase shell 客 户端
[hadoop@hadoop1 ~]$ hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/apps/hbase-1.2./lib/slf4j-log4j12-1.7..jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/apps/hadoop-2.7./share/hadoop/common/lib/slf4j-log4j12-1.7..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., rUnknown, Mon May :: CDT hbase(main)::>
说明,先看一下提示。其实是不是有一句很重要的话:
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
讲述了怎么获得帮助,怎么退出客户端
help 获取帮助
help:获取所有命令提示
help "dml" :获取一组命令的提示
help "put" :获取一个单独命令的提示帮助
exit 退出 hbase shell 客户端
HBase表的操作
关于表的操作包括(创建create,查看表列表list。查看表的详细信息desc,删除表drop,清空表truncate,修改表的定义alter)
创建create
可以输入以下命令进行查看帮助命令
hbase(main)::> help 'create'
hbase(main)::> help 'create'
Creates a table. Pass a table name, and a set of column family
specifications (at least one), and, optionally, table configuration.
Column specification can be a simple string (name), or a dictionary
(dictionaries are described below in main help output), necessarily
including NAME attribute.
Examples: Create a table with namespace=ns1 and table qualifier=t1
hbase> create 'ns1:t1', {NAME => 'f1', VERSIONS => } Create a table with namespace=default and table qualifier=t1
hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
hbase> # The above in shorthand would be the following:
hbase> create 't1', 'f1', 'f2', 'f3'
hbase> create 't1', {NAME => 'f1', VERSIONS => , TTL => , BLOCKCACHE => true}
hbase> create 't1', {NAME => 'f1', CONFIGURATION => {'hbase.hstore.blockingStoreFiles' => ''}} Table configuration options can be put at the end.
Examples: hbase> create 'ns1:t1', 'f1', SPLITS => ['', '', '', '']
hbase> create 't1', 'f1', SPLITS => ['', '', '', '']
hbase> create 't1', 'f1', SPLITS_FILE => 'splits.txt', OWNER => 'johndoe'
hbase> create 't1', {NAME => 'f1', VERSIONS => }, METADATA => { 'mykey' => 'myvalue' }
hbase> # Optionally pre-split the table into NUMREGIONS, using
hbase> # SPLITALGO ("HexStringSplit", "UniformSplit" or classname)
hbase> create 't1', 'f1', {NUMREGIONS => , SPLITALGO => 'HexStringSplit'}
hbase> create 't1', 'f1', {NUMREGIONS => , SPLITALGO => 'HexStringSplit', REGION_REPLICATION => , CONFIGURATION => {'hbase.hregion.scan.loadColumnFamiliesOnDemand' => 'true'}}
hbase> create 't1', {NAME => 'f1', DFS_REPLICATION => } You can also keep around a reference to the created table: hbase> t1 = create 't1', 'f1' Which gives you a reference to the table named 't1', on which you can then
call methods.
hbase(main)::>
可以看到其中一条提示
hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
其中t1是表名,f1,f2,f3是列簇的名,如:
hbase(main)::> create 'myHbase',{NAME => 'myCard',VERSIONS => 5}
row(s) in 3.1270 seconds => Hbase::Table - myHbase
hbase(main)::>
创建了一个名为myHbase的表,表里面有1个列簇,名为myCard,保留5个版本信息
查看表列表list
可以输入以下命令进行查看帮助命令
hbase(main)::> help 'list'
List all tables in hbase. Optional regular expression parameter could
be used to filter the output. Examples: hbase> list
hbase> list 'abc.*'
hbase> list 'ns:abc.*'
hbase> list 'ns:.*'
hbase(main)::>
直接输入list进行查看
hbase(main)::> list
TABLE
myHbase
row(s) in 0.0650 seconds => ["myHbase"]
hbase(main)::>
只有一条结果,就是刚刚创建的表myHbase
查看表的详细信息desc
一个大括号,就相当于一个列簇。
hbase(main)::> desc 'myHbase'
Table myHbase is ENABLED
myHbase
COLUMN FAMILIES DESCRIPTION
{NAME => 'myCard', BLOOMFILTER => 'ROW', VERSIONS => '', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', D
ATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '', BLOCKCACHE => 'true'
, BLOCKSIZE => '', REPLICATION_SCOPE => ''}
row(s) in 0.2160 seconds hbase(main)::>
修改表的定义alter
添加一个列簇
hbase(main):007:0> alter 'myHbase', NAME => 'myInfo'
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 2.0690 seconds
hbase(main):008:0> desc 'myHbase'
Table myHbase is ENABLED
myHbase
COLUMN FAMILIES DESCRIPTION
{NAME => 'myCard', BLOOMFILTER => 'ROW', VERSIONS => '5', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', D
ATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true'
, BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
{NAME => 'myInfo', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', D
ATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true'
, BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
2 row(s) in 0.0420 seconds
hbase(main):009:0>
删除一个列簇
hbase(main)::> alter 'myHbase', NAME => 'myCard', METHOD => 'delete'
Updating all regions with the new schema...
/ regions updated.
Done.
row(s) in 2.1920 seconds hbase(main)::> desc 'myHbase'
Table myHbase is ENABLED
myHbase
COLUMN FAMILIES DESCRIPTION
{NAME => 'myInfo', BLOOMFILTER => 'ROW', VERSIONS => '', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', D
ATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '', BLOCKCACHE => 'true'
, BLOCKSIZE => '', REPLICATION_SCOPE => ''}
row(s) in 0.0290 seconds hbase(main)::>
删除一个列簇也可以执行以下命令
alter 'myHbase', 'delete' => 'myCard'
添加列簇hehe同时删除列簇myInfo
hbase(main)::> alter 'myHbase', {NAME => 'hehe'}, {NAME => 'myInfo', METHOD => 'delete'}
Updating all regions with the new schema...
/ regions updated.
Done.
Updating all regions with the new schema...
/ regions updated.
Done.
row(s) in 3.8260 seconds hbase(main)::> desc 'myHbase'
Table myHbase is ENABLED
myHbase
COLUMN FAMILIES DESCRIPTION
{NAME => 'hehe', BLOOMFILTER => 'ROW', VERSIONS => '', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DAT
A_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '', BLOCKCACHE => 'true',
BLOCKSIZE => '', REPLICATION_SCOPE => ''}
row(s) in 0.0410 seconds hbase(main)::>
清空表truncate
hbase(main)::> truncate 'myHbase'
Truncating 'myHbase' table (it may take a while):
- Disabling table...
- Truncating table...
row(s) in 3.6760 seconds hbase(main)::>
删除表drop
hbase(main)::> drop 'myHbase' ERROR: Table myHbase is enabled. Disable it first. Here is some help for this command:
Drop the named table. Table must first be disabled:
hbase> drop 't1'
hbase> drop 'ns1:t1' hbase(main)::>
直接删除表会报错,根据提示需要先停用表
hbase(main)::> disable 'myHbase'
row(s) in 2.2620 seconds hbase(main)::> drop 'myHbase'
row(s) in 1.2970 seconds hbase(main)::> list
TABLE
row(s) in 0.0110 seconds => []
hbase(main)::>
HBase表中数据的操作
关于数据的操作(增put,删delete,查get + scan, 改==变相的增加)
创建 user 表,包含 info、data 两个列簇
hbase(main)::> create 'user_info',{NAME=>'base_info',VERSIONS=>3 },{NAME=>'extra_info',VERSIONS=>1 }
row(s) in 4.2670 seconds => Hbase::Table - user_info
hbase(main)::>
增put
查看帮助,需要传入表名,rowkey,列簇名、值等
hbase(main)::> help 'put'
Put a cell 'value' at specified table/row/column and optionally
timestamp coordinates. To put a cell value into table 'ns1:t1' or 't1'
at row 'r1' under column 'c1' marked with the time 'ts1', do: hbase> put 'ns1:t1', 'r1', 'c1', 'value'
hbase> put 't1', 'r1', 'c1', 'value'
hbase> put 't1', 'r1', 'c1', 'value', ts1
hbase> put 't1', 'r1', 'c1', 'value', {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> put 't1', 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> put 't1', 'r1', 'c1', 'value', ts1, {VISIBILITY=>'PRIVATE|SECRET'} The same commands also can be run on a table reference. Suppose you had a reference
t to table 't1', the corresponding command would be: hbase> t.put 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase(main)::>
向 user 表中插入信息,row key 为 user0001,列簇 base_info 中添加 name 列标示符,值为 zhangsan1
hbase(main)::> put 'user_info', 'user0001', 'base_info:name', 'zhangsan1'
row(s) in 0.2900 seconds hbase(main)::>
此处可以多添加几条数据
put 'user_info', 'zhangsan_20150701_0001', 'base_info:name', 'zhangsan1'
put 'user_info', 'zhangsan_20150701_0002', 'base_info:name', 'zhangsan2'
put 'user_info', 'zhangsan_20150701_0003', 'base_info:name', 'zhangsan3'
put 'user_info', 'zhangsan_20150701_0004', 'base_info:name', 'zhangsan4'
put 'user_info', 'zhangsan_20150701_0005', 'base_info:name', 'zhangsan5'
put 'user_info', 'zhangsan_20150701_0006', 'base_info:name', 'zhangsan6'
put 'user_info', 'zhangsan_20150701_0007', 'base_info:name', 'zhangsan7'
put 'user_info', 'zhangsan_20150701_0008', 'base_info:name', 'zhangsan8' put 'user_info', 'zhangsan_20150701_0001', 'base_info:age', ''
put 'user_info', 'zhangsan_20150701_0002', 'base_info:age', ''
put 'user_info', 'zhangsan_20150701_0003', 'base_info:age', ''
put 'user_info', 'zhangsan_20150701_0004', 'base_info:age', ''
put 'user_info', 'zhangsan_20150701_0005', 'base_info:age', ''
put 'user_info', 'zhangsan_20150701_0006', 'base_info:age', ''
put 'user_info', 'zhangsan_20150701_0007', 'base_info:age', ''
put 'user_info', 'zhangsan_20150701_0008', 'base_info:age', '' put 'user_info', 'zhangsan_20150701_0001', 'extra_info:Hobbies', 'music'
put 'user_info', 'zhangsan_20150701_0002', 'extra_info:Hobbies', 'sport'
put 'user_info', 'zhangsan_20150701_0003', 'extra_info:Hobbies', 'music'
put 'user_info', 'zhangsan_20150701_0004', 'extra_info:Hobbies', 'sport'
put 'user_info', 'zhangsan_20150701_0005', 'extra_info:Hobbies', 'music'
put 'user_info', 'zhangsan_20150701_0006', 'extra_info:Hobbies', 'sport'
put 'user_info', 'zhangsan_20150701_0007', 'extra_info:Hobbies', 'music' put 'user_info', 'baiyc_20150716_0001', 'base_info:name', 'baiyc1'
put 'user_info', 'baiyc_20150716_0002', 'base_info:name', 'baiyc2'
put 'user_info', 'baiyc_20150716_0003', 'base_info:name', 'baiyc3'
put 'user_info', 'baiyc_20150716_0004', 'base_info:name', 'baiyc4'
put 'user_info', 'baiyc_20150716_0005', 'base_info:name', 'baiyc5'
put 'user_info', 'baiyc_20150716_0006', 'base_info:name', 'baiyc6'
put 'user_info', 'baiyc_20150716_0007', 'base_info:name', 'baiyc7'
put 'user_info', 'baiyc_20150716_0008', 'base_info:name', 'baiyc8' put 'user_info', 'baiyc_20150716_0001', 'base_info:age', ''
put 'user_info', 'baiyc_20150716_0002', 'base_info:age', ''
put 'user_info', 'baiyc_20150716_0003', 'base_info:age', ''
put 'user_info', 'baiyc_20150716_0004', 'base_info:age', ''
put 'user_info', 'baiyc_20150716_0005', 'base_info:age', ''
put 'user_info', 'baiyc_20150716_0006', 'base_info:age', ''
put 'user_info', 'baiyc_20150716_0007', 'base_info:age', ''
put 'user_info', 'baiyc_20150716_0008', 'base_info:age', '' put 'user_info', 'baiyc_20150716_0001', 'extra_info:Hobbies', 'music'
put 'user_info', 'baiyc_20150716_0002', 'extra_info:Hobbies', 'sport'
put 'user_info', 'baiyc_20150716_0003', 'extra_info:Hobbies', 'music'
put 'user_info', 'baiyc_20150716_0004', 'extra_info:Hobbies', 'sport'
put 'user_info', 'baiyc_20150716_0005', 'extra_info:Hobbies', 'music'
put 'user_info', 'baiyc_20150716_0006', 'extra_info:Hobbies', 'sport'
put 'user_info', 'baiyc_20150716_0007', 'extra_info:Hobbies', 'music'
put 'user_info', 'baiyc_20150716_0008', 'extra_info:Hobbies', 'sport'
查get + scan
获取 user 表中 row key 为 user0001 的所有信息
hbase(main)::> get 'user_info', 'user0001'
COLUMN CELL
base_info:name timestamp=, value=zhangsan1
row(s) in 0.1310 seconds hbase(main)::>
获取user表中row key为rk0001,info列簇的所有信息
hbase(main)::> get 'user_info', 'rk0001', 'base_info'
COLUMN CELL
base_info:name timestamp=, value=zhangsan
row(s) in 0.0320 seconds hbase(main)::>
查询user_info表中的所有信息
hbase(main)::> scan 'user_info'
ROW COLUMN+CELL
rk0001 column=base_info:name, timestamp=, value=zhangsan
user0001 column=base_info:name, timestamp=, value=zhangsan1
row(s) in 0.0970 seconds hbase(main)::>
查询user_info表中列簇为base_info的信息
hbase(main)::> scan 'user_info', {COLUMNS => 'base_info'}
ROW COLUMN+CELL
rk0001 column=base_info:name, timestamp=, value=zhangsan
user0001 column=base_info:name, timestamp=, value=zhangsan1
row(s) in 0.0620 seconds hbase(main)::>
删delete
删除user_info表row key为rk0001,列标示符为base_info:name的数据
hbase(main)::> delete 'user_info', 'rk0001', 'base_info:name'
row(s) in 0.0780 seconds hbase(main)::> scan 'user_info', {COLUMNS => 'base_info'}
ROW COLUMN+CELL
user0001 column=base_info:name, timestamp=, value=zhangsan1
row(s) in 0.0530 seconds hbase(main)::>
HBase学习之路 (三)HBase集群Shell操作的更多相关文章
- HBase(四)HBase集群Shell操作
一.进入HBase命令行 在你安装的随意台服务器节点上,执行命令:hbase shell,会进入到你的 hbase shell 客 户端 [admin@node21 ~]$ hbase shell S ...
- Dubbo源码学习总结系列三 dubbo-cluster集群模块
Dubbo集群模块的目的是将集群Invokers构造一个透明的Invoker对象,其中包含了容错机制.负载均衡.目录服务(服务地址集合).路由机制等,为RPC层提供高可用.高并发.自动发现.可治理的S ...
- HBase 学习之路(四)—— HBase集群环境配置
一.集群规划 这里搭建一个3节点的HBase集群,其中三台主机上均为Regin Server.同时为了保证高可用,除了在hadoop001上部署主Master服务外,还在hadoop002上部署备用的 ...
- HBase 学习之路(十)—— HBase的SQL中间层 Phoenix
一.Phoenix简介 Phoenix是HBase的开源SQL中间层,它允许你使用标准JDBC的方式来操作HBase上的数据.在Phoenix之前,如果你要访问HBase,只能调用它的Java API ...
- Elasticsearch学习总结 (Centos7下Elasticsearch集群部署记录)
一. ElasticSearch简单介绍 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elasticse ...
- 一文掌握Redis的三种集群方案
在开发测试环境中,我们一般搭建Redis的单实例来应对开发测试需求,但是在生产环境,如果对可用性.可靠性要求较高,则需要引入Redis的集群方案.虽然现在各大云平台有提供缓存服务可以直接使用,但了解一 ...
- 学习之路三十九:新手学习 - Windows API
来到了新公司,一开始就要做个程序去获取另外一个程序里的数据,哇,挑战性很大. 经过两周的学习,终于搞定,主要还是对Windows API有了更多的了解. 文中所有的消息常量,API,结构体都整理出来了 ...
- 大数据入门第十六天——流式计算之storm详解(三)集群相关进阶
一.集群提交任务流程分析 1.集群提交操作 参考:https://www.jianshu.com/p/6783f1ec2da0 2.任务分配与启动流程 参考:https://www.cnblogs.c ...
- Redis源码阅读(三)集群-连接初始化
Redis源码阅读(三)集群-连接建立 对于并发请求很高的生产环境,单个Redis满足不了性能要求,通常都会配置Redis集群来提高服务性能.3.0之后的Redis支持了集群模式. Redis官方提供 ...
随机推荐
- [LeetCode] Next Permutation(一种巧妙的解题方法)
Next Permutation Implement next permutation, which rearranges numbers into the lexicographically nex ...
- Invoke 和 BeginInvoke 的区别
在Invoke或者BeginInvoke的使用中无一例外地使用了委托Delegate 一.为什么Control类提供了Invoke和BeginInvoke机制? 关于这个问题的最主要的原因已经是dot ...
- 小程序:获取input输入的值
wxml <input placeholder='输入你的姓名' value='{{name}}' bindblur='nameblur'></input> js data ...
- srop实战
前言 srop 的作用比较强,在条件允许的情况下,尽量使用它.题目来自于 i春秋的一个比赛. 题目链接: https://gitee.com/hac425/blog_data/blob/master/ ...
- Android Studio 快速实现上传项目到Github(详细步骤)
前言: 本文主要讲解如何将Android Studio项目上传至GitHub,在此之前,先介绍几个概念. Android Studio:是谷歌推出一个Android集成开发工具,基于IntelliJ ...
- 大数据量报表APPLET打印分页传输方案
1 . 问题概述 当报表运算完成时,客户端经常需要调用润乾自带的runqianReport4Applet.jar来完成打印操作, 然而数据量比较大的时候,会导致无法加载完成,直至applet内存 ...
- doPost方法不支持 a 标签和地址栏直接输入地址访问
demo <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- 大O表示法
概念 大O表示法是和数据项的个数相关联的粗略度量算法时间复杂度的快捷方法. 常数一个无序可重复数组插入一个数据项的时间T是常数K,常数K表示一次插入所花费的时间,包含cpu.编译器等工作时间.可表示为 ...
- 结对编程的感想&收获
关于结对编程的感想.感受,见我的另一篇随笔——<构建之法>结对编程 感想 下面我来谈谈本次结对编程的收获以及发现的问题 收获 ①这是我人生中第一次做UI界面设计,刚拿到这个题目还是比较 ...
- Mysql中的delimiter详解
初学mysql时,可能不太明白delimiter的真正用途,delimiter在mysql很多地方出现,比如存储过程.触发器.函数等. 学过oracle的人,再来学mysql就会感到很奇怪,百思不得其 ...