使用HBase 和 Hbase使用帮助

  1)、进入HBase 

#使用命令进入HBase Shell
$ hbase shell 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
hbase(main):003:0>

  2)、使用HBase帮助

    HBase  提供了大量的帮助文档,只要在HBase 下使用命令help就能够查看HBase所有关键字的帮助

hbase(main):003:0> help

HBase Shell, version 1.1.3, r72bc50f5fafeb105b2139e42bbee3d61ca724989, Sat Jan 16 18:29:00 PST 2016
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, get_splits, incr, put, scan, truncate, truncate_preserve ...

    如果不知道某个关键字如何使用的话,只需要在Hbase下直接建入该关键字即可:

hbase(main):004:0> put

ERROR: wrong number of arguments (0 for 4)

Here is some help for this command:
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 下,如果输入内容错了,使用回退键是不管用的,必须使用Ctrl+回退键才行。

  3)、创建表、插入数据、查询数据

进入hbase shell console
    $HBASE_HOME/bin/hbase shell
如果有kerberos认证,需要事先使用相应的keytab进行一下认证(使用kinit命令),认证成功之后再使用hbase shell进入可以使用whoami命令可查看当前用户
    hbase(main)> whoami
表的管理
1)查看有哪些表
    hbase(main)> list
2)创建表     # 语法:create <table>, {NAME => <family>, VERSIONS => <VERSIONS>}
    # 例如:创建表t1,有两个family name:f1,f2,且版本数均为2
    hbase(main)> create 't1',{NAME => 'f1', VERSIONS => 2},{NAME => 'f2', VERSIONS => 2}
3)删除表
    分两步:首先disable,然后drop
    例如:删除表t1     hbase(main)> disable 't1'
    hbase(main)> drop 't1'
4)查看表的结构     # 语法:describe <table>
    # 例如:查看表t1的结构
    hbase(main)> describe 't1'
5)修改表结构
    修改表结构必须先disable     # 语法:alter 't1', {NAME => 'f1'}, {NAME => 'f2', METHOD => 'delete'}
    # 例如:修改表test1的cf的TTL为180天
    hbase(main)> disable 'test1'
    hbase(main)> alter 'test1',{NAME=>'body',TTL=>'15552000'},{NAME=>'meta', TTL=>'15552000'}
    hbase(main)> enable 'test1'
权限管理
1)分配权限
    # 语法 : grant <user> <permissions> <table> <column family> <column qualifier> 参数后面用逗号分隔
    # 权限用五个字母表示: "RWXCA".
    # READ('R'), WRITE('W'), EXEC('X'), CREATE('C'), ADMIN('A')
    # 例如,给用户‘test'分配对表t1有读写的权限,
    hbase(main)> grant 'test','RW','t1'
2)查看权限     # 语法:user_permission <table>
    # 例如,查看表t1的权限列表
    hbase(main)> user_permission 't1'
3)收回权限     # 与分配权限类似,语法:revoke <user> <table> <column family> <column qualifier>
    # 例如,收回test用户在表t1上的权限
    hbase(main)> revoke 'test','t1'
表数据的增删改查
1)添加数据
    # 语法:put <table>,<rowkey>,<family:column>,<value>,<timestamp>
    # 例如:给表t1的添加一行记录:rowkey是rowkey001,family name:f1,column name:col1,value:value01,timestamp:系统默认
    hbase(main)> put 't1','rowkey001','f1:col1','value01'
    用法比较单一。
2)查询数据
  a)查询某行记录     # 语法:get <table>,<rowkey>,[<family:column>,....]
    # 例如:查询表t1,rowkey001中的f1下的col1的值
    hbase(main)> get 't1','rowkey001', 'f1:col1'
    # 或者:
    hbase(main)> get 't1','rowkey001', {COLUMN=>'f1:col1'}
    # 查询表t1,rowke002中的f1下的所有列值
    hbase(main)> get 't1','rowkey001'
  b)扫描表     # 语法:scan <table>, {COLUMNS => [ <family:column>,.... ], LIMIT => num}
    # 另外,还可以添加STARTROW、TIMERANGE和FITLER等高级功能
    # 例如:扫描表t1的前5条数据
    hbase(main)> scan 't1',{LIMIT=>5}
  c)查询表中的数据行数     # 语法:count <table>, {INTERVAL => intervalNum, CACHE => cacheNum}
    # INTERVAL设置多少行显示一次及对应的rowkey,默认1000;CACHE每次去取的缓存区大小,默认是10,调整该参数可提高查询速度
    # 例如,查询表t1中的行数,每100条显示一次,缓存区为500
    hbase(main)> count 't1', {INTERVAL => 100, CACHE => 500}
3)删除数据
  a )删除行中的某个列值     # 语法:delete <table>, <rowkey>, <family:column> , <timestamp>,必须指定列名
    # 例如:删除表t1,rowkey001中的f1:col1的数据
    hbase(main)> delete 't1','rowkey001','f1:col1'
    注:将删除改行f1:col1列所有版本的数据
  b )删除行     # 语法:deleteall <table>, <rowkey>, <family:column> , <timestamp>,可以不指定列名,删除整行数据
    # 例如:删除表t1,rowk001的数据
    hbase(main)> deleteall 't1','rowkey001'
  c)删除表中的所有数据     # 语法: truncate <table>
    # 其具体过程是:disable table -> drop table -> create table
    # 例如:删除表t1的所有数据
    hbase(main)> truncate 't1'
Region管理
1)移动region
    # 语法:move 'encodeRegionName', 'ServerName'
    # encodeRegionName指的regioName后面的编码,ServerName指的是master-status的Region Servers列表
    # 示例
    hbase(main)>move '4343995a58be8e5bbc739af1e91cd72d', 'db-41.xxx.xxx.org,60020,1390274516739'
2)开启/关闭region     # 语法:balance_switch true|false
    hbase(main)> balance_switch
3)手动split     # 语法:split 'regionName', 'splitKey'
4)手动触发major compaction     #语法:
    #Compact all regions in a table:
    #hbase> major_compact 't1'
    #Compact an entire region:
    #hbase> major_compact 'r1'
    #Compact a single column family within a region:
    #hbase> major_compact 'r1', 'c1'
    #Compact a single column family within a table:
    #hbase> major_compact 't1', 'c1'
配置管理及节点重启
1)修改hdfs配置
    hdfs配置位置:/etc/hadoop/conf
    # 同步hdfs配置
    cat /home/hadoop/slaves|xargs -i -t scp /etc/hadoop/conf/hdfs-site.xml hadoop@{}:/etc/hadoop/conf/hdfs-site.xml
    #关闭:
    cat /home/hadoop/slaves|xargs -i -t ssh hadoop@{} "sudo /home/hadoop/cdh4/hadoop-2.0.0-cdh4.2.1/sbin/hadoop-daemon.sh --config /etc/hadoop/conf stop datanode"
    #启动:
    cat /home/hadoop/slaves|xargs -i -t ssh hadoop@{} "sudo /home/hadoop/cdh4/hadoop-2.0.0-cdh4.2.1/sbin/hadoop-daemon.sh --config /etc/hadoop/conf start datanode"
2)修改hbase配置
    hbase配置位置:     # 同步hbase配置
    cat /home/hadoop/hbase/conf/regionservers|xargs -i -t scp /home/hadoop/hbase/conf/hbase-site.xml hadoop@{}:/home/hadoop/hbase/conf/hbase-site.xml     # graceful重启
    cd ~/hbase
    bin/graceful_stop.sh --restart --reload --debug inspurXXX.xxx.xxx.org

Week09_day05(Hbase的基本使用)的更多相关文章

  1. Mapreduce的文件和hbase共同输入

    Mapreduce的文件和hbase共同输入 package duogemap;   import java.io.IOException;   import org.apache.hadoop.co ...

  2. Redis/HBase/Tair比较

    KV系统对比表 对比维度 Redis Redis Cluster Medis Hbase Tair 访问模式    支持Value大小 理论上不超过1GB(建议不超过1MB) 理论上可配置(默认配置1 ...

  3. Hbase的伪分布式安装

    Hbase安装模式介绍 单机模式 1> Hbase不使用HDFS,仅使用本地文件系统 2> ZooKeeper与Hbase运行在同一个JVM中 分布式模式– 伪分布式模式1> 所有进 ...

  4. Spark踩坑记——数据库(Hbase+Mysql)

    [TOC] 前言 在使用Spark Streaming的过程中对于计算产生结果的进行持久化时,我们往往需要操作数据库,去统计或者改变一些值.最近一个实时消费者处理任务,在使用spark streami ...

  5. Spark读写Hbase的二种方式对比

    作者:Syn良子 出处:http://www.cnblogs.com/cssdongl 转载请注明出处 一.传统方式 这种方式就是常用的TableInputFormat和TableOutputForm ...

  6. 深入学习HBase架构原理

    HBase定义 HBase 是一个高可靠.高性能.面向列.可伸缩的分布式存储系统,利用Hbase技术可在廉价PC Server上搭建 大规模结构化存储集群. HBase 是Google Bigtabl ...

  7. hbase协处理器编码实例

    Observer协处理器通常在一个特定的事件(诸如Get或Put)之前或之后发生,相当于RDBMS中的触发器.Endpoint协处理器则类似于RDBMS中的存储过程,因为它可以让你在RegionSer ...

  8. hbase集群安装与部署

    1.相关环境 centos7 hadoop2.6.5 zookeeper3.4.9 jdk1.8 hbase1.2.4 本篇文章仅涉及hbase集群的搭建,关于hadoop与zookeeper的相关部 ...

  9. 从零自学Hadoop(22):HBase协处理器

    阅读目录 序 介绍 Observer操作 示例下载 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,Sour ...

  10. Hbase安装和错误

    集群规划情况: djt1 active Hmaster djt2 standby Hmaster djt3 HRegionServer 搭建步骤: 第一步:配置conf/regionservers d ...

随机推荐

  1. merging rhino 哈哈

  2. mysql:sql create database新建utf8mb4 数据库

    create database sina default character set utf8mb4 collate utf8mb4_unicode_ci;或者是create database con ...

  3. Swagger注解-@ApiModel 和 @ApiModelProperty

    @ApiModel 使用场景 在实体类上边使用,标记类时swagger的解析类 概述 提供有关swagger模型的其它信息,类将在操作中用作类型时自动内省 属性 属性名称 数据类型 默认值 说明 va ...

  4. Qt音视频开发13-视频解码线程基类的设计

    一.前言 这个解码线程基类的设计,是到目前为止个人觉得自己设计的最好的基类之一,当然也不是一开始就知道这样设计,没有个三五年的摸爬滚打以及社会的毒打,是想不到要这样设计的,一方面是要不断提炼各种视频类 ...

  5. UML之属性与参数的多重性

    在UML中,多重性是指一个条目潜在的数量范围.多重性可被用于属性.操作参数.关联关系.UML元模型也使用多重性对元模型元素之间的关系进行约束.多重性总是包含基数值,它是相关条目在现实世界中的确切数量. ...

  6. VS2008新建MFC程序时提示:当前页面的脚本发送错误 不是有效的Win32应用程序的解决办法

    错误现象: 解决方案: 1.根据错误信息中的url,找到对应文件夹下的htm文件 2.使用notepad++打开default.htm文件,找到错误提示地方,注释掉其中两句语句,如433和434行所示 ...

  7. Appium_iOS 配置

    一. iOS Driver 配置 options = AppiumOptions()options.load_capabilities({ "platformName": &quo ...

  8. atomic 包底层实现原理

    一.概念介绍(一)volatile关键字 Java 因为指令重排序,优化我们的代码,让程序运行更快,也随之带来了多线程下,指令执行顺序的不可控. 1.volatile关键字的作用: 内存可见性,修饰的 ...

  9. 第二章 dubbo源码解析目录

    6.1 如何在spring中自定义xml标签 dubbo自定义了很多xml标签,例如<dubbo:application>,那么这些自定义标签是怎么与spring结合起来的呢?我们先看一个 ...

  10. Java8新特性时间日期库

    Java8新特性的功能已经更新了不少篇幅了,今天重点讲解时间日期库中DateTime相关处理.同样的,如果你现在依旧在项目中使用传统Date.Calendar和SimpleDateFormat等API ...