HBase 常用Shell命令

1、进入hbase shell console
$HBASE_HOME/bin/hbase shell
如果有kerberos认证,需要事先使用相应的keytab进行一下认证(使用kinit命令),认证成功之后再使用hbase shell进入
2、可以使用whoami命令可查看当前用户
  1. hbase(main):001:0> whoami
  2. a6 (auth:SIMPLE)
  3. groups: staff, com.apple.sharepoint.group.1, everyone, localaccounts, _appserverusr, admin, _appserveradm, _lpadmin, com.apple.sharepoint.group.2, _appstore, _lpoperator, _developer, _analyticsusers, com.apple.access_ftp, com.apple.access_screensharing, com.apple.access_ssh-disabled

3、表管理

    1)查看有哪些表
  1. hbase(main):002:0> list
  2. TABLE
  3. test
  4. test001
  5. test010
  6. 10 row(s) in 0.4870 seconds

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}

  1. hbase(main):003:0> create 't1',{NAME => 'f1', VERSIONS => 2},{NAME => 'f2', VERSIONS => 2}
  2. 0 row(s) in 1.3840 seconds
  3. => Hbase::Table - t1

3)查看表结构

# 语法:describe <table>
# 例如:查看表t1的结构
hbase(main)> describe 't1'

  1. hbase(main):006:0> desc 't1'
  2. Table t1 is ENABLED
  3. t1
  4. COLUMN FAMILIES DESCRIPTION
  5. {NAME => 'f1', BLOOMFILTER => 'ROW', VERSIONS => '2', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
  6. {NAME => 'f2', BLOOMFILTER => 'ROW', VERSIONS => '2', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
  7. 2 row(s) in 0.2250 seconds

4)删除表

  1. hbase(main):004:0> list
  2. TABLE
  3. t1
  4. test
  5. test001
  6. test010
  7. 11 row(s) in 0.0490 seconds
  8. => ["t1", "test", "test001", "test010"]

5)删除表
分两步:首先disable,然后drop
例如:删除表t1
hbase(main)> disable 't1'

hbase(main)> drop 't1'

  1. hbase(main):006:0> desc 't1'
  2. Table t1 is ENABLED
  3. t1
  4. COLUMN FAMILIES DESCRIPTION
  5. ……
  6. 2 row(s) in 0.2250 seconds
  7. hbase(main):007:0> disable 't1'
  8. 0 row(s) in 2.3340 seconds
  9. hbase(main):008:0> desc 't1'
  10. Table t1 is DISABLED
  11. t1
  12. COLUMN FAMILIES DESCRIPTION
  13. ……
  14. 2 row(s) in 0.0350 seconds
  15. hbase(main):009:0> drop 't1'
  16. 0 row(s) in 1.3390 seconds
  17. hbase(main):010:0> desc 't1'
  18. ERROR: Unknown table t1!
  19. Here is some help for this command:
  20. Describe the named table. For example:
  21. hbase> describe 't1'
  22. hbase> describe 'ns1:t1'
  23. Alternatively, you can use the abbreviated 'desc' for the same thing.
  24. hbase> desc 't1'
  25. hbase> desc 'ns1:t1'

6)修改表结构
修改表结构必须先disable
# 语法:alter 't1', {NAME => 'f1'}, {NAME => 'f2', METHOD => 'delete'}
# 例如:修改表test1的cf的TTL为180天
hbase(main)> disable 't1'
hbase(main)> alter 't1',{NAME=>'body',TTL=>'15552000'},{NAME=>'meta', TTL=>'15552000'}

hbase(main)> enable 't1'

  1. hbase(main):014:0> alter 't1',{NAME=>'body',TTL=>'15552000'},{NAME=>'meta', TTL=>'15552000'}
  2. Updating all regions with the new schema...
  3. 1/1 regions updated.
  4. Done.
  5. Updating all regions with the new schema...
  6. 1/1 regions updated.
  7. Done.
  8. 0 row(s) in 3.8910 seconds
  9. hbase(main):015:0> desc 't1'
  10. Table t1 is ENABLED
  11. t1
  12. COLUMN FAMILIES DESCRIPTION
  13. {NAME => 'body', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => '15552000 SECONDS (180 DAYS)', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLIC
  14. ATION_SCOPE => '0'}
  15. {NAME => 'f1', BLOOMFILTER => 'ROW', VERSIONS => '2', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
  16. {NAME => 'f2', BLOOMFILTER => 'ROW', VERSIONS => '2', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
  17. {NAME => 'meta', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => '15552000 SECONDS (180 DAYS)', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLIC
  18. ATION_SCOPE => '0'}
  19. 4 row(s) in 0.0540 seconds

4、权限管理
    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'
5、表数据的增删改查
    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',www.089188.cn'rowkey001'
        b)扫描表
# 语法:scan <table>, {COLUMNS => [ <family:column>,.... ], LIMIT => num}
# 另外,还可以添加STARTROW、TIMERANGE和FITLER等高级功能
# 例如:扫描表t1的前5条数据
hbase(main)> scan 't1',{LIMIT=>5}
        c)查询表中的数据行数
# 语法:count <table>,www.baohuayule.net   {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'www.feifanyule.cn/ ,'rowkey001','f1:col1'
注:将删除改行f1:col1列所有版本的数据
    b)删除行
# 语法:deleteall <table>, <rowkey>,  <family:column> , <timestamp>,可以不指定列名,删除整行数据
# 例如:删除表t1,rowk001的数据
hbase(main)> deleteall 't1','rowkey001'
   c)删除表中的所有数据
# 语法: truncate <table>
# 其具体过程是:disable table -> www.vboyule.cn  drop table -> create table
# 例如:删除表t1的所有数据
hbase(main)> truncate 't1'
6、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 www.thd178.com a region:
#hbase> major_compact 'r1', 'c1'
#Compact a single column family within a table:
#hbase> major_compact 'www.leyouzaixan.cn t1', 'c1'
7、配置管理及节点重启
    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 www.cnzhaotai.com/ inspurXXX.xxx.xxx.org

原 HBase 常用Shell命令的更多相关文章

  1. (转)HBase 常用Shell命令

    转自:http://my.oschina.net/u/189445/blog/595232 hbase shell命令                             描述  alter 修改 ...

  2. HBase 常用Shell命令

    两个月前使用过hbase,现在最基本的命令都淡忘了,留一个备查~ 进入hbase shell console$HBASE_HOME/bin/hbase shell如果有kerberos认证,需要事先使 ...

  3. 5 HBase 常用Shell命令

    进入hbase shell console $HBASE_HOME/bin/hbase shell 如果有kerberos认证,需要事先使用相应的keytab进行一下认证(使用kinit命令),认证成 ...

  4. HBase 学习之路(五)——HBase常用 Shell 命令

    一.基本命令 打开Hbase Shell: # hbase shell 1.1 获取帮助 # 获取帮助 help # 获取命令的详细信息 help 'status' 1.2 查看服务器状态 statu ...

  5. HBase 系列(五)——HBase 常用 Shell 命令

    一.基本命令 打开 Hbase Shell: # hbase shell 1.1 获取帮助 # 获取帮助 help # 获取命令的详细信息 help 'status' 1.2 查看服务器状态 stat ...

  6. Hbase常用Shell命令

    status 查看系统状态 hbase(main):010:0> status 1 active master, 0 backup masters, 4 servers, 0 dead, 6.5 ...

  7. 【原】常用shell命令

    #ss -ln  监听常用端口 #netstat -an |grep 80    80端口被占用情况 #linux 下使用 tc 模拟网络延迟和丢包

  8. HBase 安装与配置及常用Shell命令

    HBase 安装与配置 首要配置 配置时间同步(所有节点上执行) yum -y install chrony vi /etc/chrony.conf #写入(7版本用server:8版本用pool): ...

  9. Linux Shell常用shell命令

    Linux Shell常用shell命令 一.文件.目录操作命令 1.ls命令 功能:显示文件和目录的信息 ls 以默认方式显示当前目录文件列表 ls -a 显示所有文件包括隐藏文件 ls -l 显示 ...

随机推荐

  1. 关于img底部空白

    <img>元素底部为何有空白? 问题: 最近听网课遇到这样一个问题,先po出代码如下: <!--html--> <div class="top"> ...

  2. js、jquery初始化加载顺序

    // ready 这个方法只是在页面所有的DOM加载完毕后就会触发 // 方式1 $(function(){ // do something }); // 方式2 $(document).ready( ...

  3. egg的使用方法

    1.controller const {ctx,service} = this: let id = ctx.query.id // 获取GET的参数 let body = ctx.request.bo ...

  4. Thinkphp 取消Url默认模块的现实

    例子http://www.tp.com/home/index/index 想要现实的效果是:http://www.tp.com/index/index 1是通过配置路由来达到目的 2通过配置首页的入口 ...

  5. python--re(匹配字符串)

    \d 匹配任何十进制数:它相当于类 [0-9]. \D 匹配任何非数字字符:它相当于类 [^0-9]. \s 匹配任何空白字符:它相当于类 [ fv]. \S 匹配任何非空白字符:它相当于类 [^ f ...

  6. kangle环境liunx一键安装脚本

    1.kangle官方脚本 linux下easypanel版本安装及升级(集成了kangle web 服务器和mysql,仅支持centos 5和centos 6)执行下面的命令即可,安装程序将自动安装 ...

  7. EVALUation mode running with code size limit:2k keil进行仿真过程中出现的报错

    EVALUation mode running with code size limit:2k 如果keil软件未破解,会限制程序的存储大小.第一是你的软件没有破解,不能编译2K以上的程序:这种情况下 ...

  8. hadoop中namenode发生故障的处理方法

    Namenode 故障后,可以采用如下两种方法恢复数据: 方法一:将 SecondaryNameNode 中数据拷贝到 namenode 存储数据的目录: 方法 二: 使用 -importCheckp ...

  9. python语法root=Tkinter.Tk()

    1. Tkinter 是一个python模块,是一个调用Tcl/Tk的接口,它是一个跨平台的脚本图形界面接口.Tkinter不是唯一的python图形编程接口,但是是 其中比较流行的一个.最大的特点是 ...

  10. Java设计模式-----装饰者

    对方法做增强,并不能添加新的接口方法.