设为首页 加入收藏

TOP

Hbase启停与shell常见命令
2019-02-19 13:45:07 】 浏览:74
Tags:Hbase shell 常见 命令

启停脚本

hbase 启动与停止脚本都在hbase安装包bin目录下。

  • 启动HBase集群:

     bin/start-hbase.sh
    
  • 停止集群:

     bin/stop-hbase.sh
    
  • 启动HMaster进程:

     bin/hbase-daemon.sh start master
    
  • 停止HMaster进程:

    bin/hbase-daemon.sh stop master
    
  • 启动HRegionServer进程:

    bin/hbase-daemon.sh start regionserver
    
  • 停止HRegionServer进程:

    bin/hbase-daemon.sh stop regionserver
    

shell 命令

启动Hbase shell:

bin/hbase shell

[hadoop@master hbase-1.2.6]$ ./bin/hbase shell 
hbase(main):001:0>

hbase shell 命令的帮助可以通过help查看

hbase>help  #查看帮助
hbase>help 'command' #查看具体命令的帮助

下面介绍一些常见的命令:

  • 命名空间:
    Hbase命名空间可以对比理解为关系型数据库中的database。
    创建namespace:

    hbase(main):032:0> create_namespace 'ns_test'
    0 row(s) in 0.1090 seconds
    

    查看namespace

    hbase(main):034:0> describe_namespace 'ns_test'
    DESCRIPTION                                                                                          
    {NAME => 'ns_test'}                                                                                  
    1 row(s) in 0.0160 seconds
    

    查看所有namespace

    hbase(main):042:0> list_namespace 'ns'
    NAMESPACE                                                                                            
    ns2                                                                                                  
    ns_test                                                                                              
    2 row(s) in 0.0150 seconds
    

    查看namespace下的表

    hbase(main):047:0> list_namespace_tables 'ns_test'
    TABLE                                                                                                
    0 row(s) in 0.0260 seconds
    
  • 表相关:
    创建表

    hbase(main):017:0* create 'ns_test:t1', {NAME=>'f1'}, {NAME=>'f2'}
    0 row(s) in 2.3050 seconds
    
    => Hbase::Table - ns_test:t1
    

    修改表

    # 表t1增加列族f3
    hbase(main):035:0> alter 'ns_test:t1' , 'f3'
    Updating all regions with the new schema...
    0/1 regions updated.
    1/1 regions updated.
    Done.
    0 row(s) in 3.0650 seconds
    
    # 表t1删除列族f4
    hbase(main):065:0>  alter 'ns_test:t1', NAME => 'f4',METHOD => 'delete'
    Updating all regions with the new schema...
    1/1 regions updated.
    Done.
    0 row(s) in 2.2440 seconds
    

    disable表

    hbase(main):021:0* disable 'ns_test:t1'
    0 row(s) in 2.3210 seconds
    

    enable表

    hbase(main):025:0> enable 'ns_test:t1'
    0 row(s) in 1.3030 seconds
    

    判断表是否存在

    hbase(main):028:0> exists 'ns_test:t1'
    Table ns_test:t1 does exist                                                                          
    0 row(s) in 0.0100 seconds
    

    查看表相关信息

    hbase(main):071:0> describe 'ns_test:t1'
    Table ns_test:t1 is ENABLED                                                                          
    ns_test:t1                                                                                           
    COLUMN FAMILIES DESCRIPTION                                                                          
    {NAME => 'f1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FA
    LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BL
    OCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                  
    {NAME => 'f2', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FA
    LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BL
    OCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                  
    {NAME => 'f3', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FA
    LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BL
    OCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                  
    3 row(s) in 0.0340 seconds
    

    查看所有表

    hbase(main):087:0* list
    TABLE                                                                                                
    ns2:t1                                                                                               
    ns2:t2                                                                                               
    ns_test:t1                                                                                           
    3 row(s) in 0.0060 seconds
    
    => ["ns2:t1", "ns2:t2", "ns_test:t1"]
    

    删除表(只有disable后的表才能被删除)

    hbase(main):096:0> drop 'ns_test:t1'
    0 row(s) in 1.2760 seconds
    
  • 表数据操作:
    添加数据

    hbase(main):101:0> put 'ns_test:t1', '0001', 'f1:name', 'bob'
    0 row(s) in 0.1650 seconds
    

    全表扫描

    hbase(main):105:0> scan 'ns_test:t1'
    ROW                        COLUMN+CELL                                                               
     0001                      column=f1:age, timestamp=1532252491211, value=30                          
     0001                      column=f1:name, timestamp=1532252499881, value=bob                        
    1 row(s) in 0.0460 seconds
    

    获取某一行数据

    # 获取一行的所有数据
    hbase(main):001:0> get 'ns_test:t1', '0001'
    COLUMN                     CELL                                                                      
     f1:age                    timestamp=1532252491211, value=30                                         
     f1:name                   timestamp=1532252499881, value=bob                                        
    2 row(s) in 0.3190 seconds
    
    #获取一行某个列限定符的数据
    hbase(main):014:0* get 'ns_test:t1', '0001', 'f1:age'
    COLUMN                     CELL                                                                      
     f1:age                    timestamp=1532252491211, value=30                                         
    1 row(s) in 0.0140 seconds
    

    删除一个cell的数据

    hbase(main):002:0> delete 'ns_test:t1', '0001', 'f1:age'
    0 row(s) in 0.2380 seconds
    

    获取表的行数

    hbase(main):006:0> count 'ns_test:t1'
    1 row(s) in 0.0590 seconds
    
    => 1
    

    清空表数据

    hbase(main):013:0* truncate 'ns_test:t1'
    Truncating 'ns_test:t1' table (it may take a while):
     - Disabling table...
     - Truncating table...
    0 row(s) in 3.8720 seconds
    
    hbase(main):026:0> scan 'ns_test:t1'
    ROW                        COLUMN+CELL                                                               
    0 row(s) in 0.1380 seconds
    

总结

该文总结了Hbase启停脚本与常见shell命令的使用。

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Hbase,Zookeeper完全分布式安装 下一篇本地调试HBase源码

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目