Hbase命令整理

来源:互联网 发布:指南针炒股软件装不上 编辑:程序博客网 时间:2024/05/16 04:48

hbase shell 

general命令

hbase(main):010:0> version1.2.0-cdh5.8.3, rUnknown, Wed Oct 12 20:33:08 PDT 2016hbase(main):011:0> whoamihadoop (auth:SIMPLE)    groups: hadoophbase(main):012:0> status1 active master, 0 backup masters, 3 servers, 0 dead, 2.6667 average load

ddl 命令

hbase(main):018:0> create 't2', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}0 row(s) in 88.2960 seconds=> Hbase::Table - t2hbase(main):019:0> describe 't2'Table t2 is ENABLED                                                                                                                                                         t2                                                                                                                                                                          COLUMN FAMILIES DESCRIPTION                                                                                                                                                 {NAME => 'f1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                           {NAME => 'f2', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                           {NAME => 'f3', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                           3 row(s) in 0.1560 secondshbase(main):020:0> exists 't2'Table t2 does exist                                                                                                                                                         0 row(s) in 0.0300 secondshbase(main):021:0> is_disabled 't2'false                                                                                                                                                                       0 row(s) in 0.0300 secondshbase(main):022:0> is_enabled 't2'true                                                                                                                                                                        0 row(s) in 0.0290 secondshbase(main):023:0> alter 't2',{NAME=>'t_info',TTL=>'300'}Updating all regions with the new schema...1/1 regions updated.Done.0 row(s) in 2.2300 secondshbase(main):024:0> desc 't2'Table t2 is ENABLED                                                                                                                                                         t2                                                                                                                                                                          COLUMN FAMILIES DESCRIPTION                                                                                                                                                 {NAME => 'f1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                           {NAME => 'f2', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                           {NAME => 'f3', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                           {NAME => 't_info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', COMPRESSION => 'NONE', VERSIONS => '1', TTL => '300 SECONDS (5 MINUTES)', MIN_VERSIONS => '0', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                       4 row(s) in 0.0430 secondshbase(main):026:0> listTABLE                                                                                                                                                                                         t1                                                                                                                                                                                            t2                                                                                                                                                                                            tc                                                                                                                                                                                            tc1                                                                                                                                                                                           test                                                                                                                                                                                          5 row(s) in 0.0110 seconds=> ["t1", "t2", "tc", "tc1", "test"]hbase(main):027:0> drop 't2' ERROR: Table t2 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):030:0> drop 't2' ERROR: Table t2 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):031:0> disable 't2'0 row(s) in 2.3130 secondshbase(main):032:0> drop 't2' 0 row(s) in 1.3100 secondshbase(main):033:0> listTABLE                                                                                                                                                                                         t1                                                                                                                                                                                            tc                                                                                                                                                                                            tc1                                                                                                                                                                                           test                                                                                                                                                                                          4 row(s) in 0.0100 seconds

namespace相关命令

drop_namespace必需先删除namespace下所有表

hbase(main):054:0> list_namespaceNAMESPACE                                                                                                                                                                                    default                                                                                                                                                                                      hbase                                                                                                                                                                                        tc                                                                                                                                                                                           3 row(s) in 0.0120 secondshbase(main):055:0> create_namespace 'ns1'0 row(s) in 0.0720 secondshbase(main):056:0> create 'ns1:t2',{NAME=>'t_info',TTL=>'300'}0 row(s) in 38.2670 seconds=> Hbase::Table - ns1:t2hbase(main):057:0> list_namespace_tables 'ns1'TABLE                                                                                                                                                                                        t2                                                                                                                                                                                           1 row(s) in 0.0160 secondshbase(main):058:0> describe_namespace 'ns1'DESCRIPTION                                                                                                                                                                                  {NAME => 'ns1'}                                                                                                                                                                              1 row(s) in 0.0070 secondshbase(main):059:0> drop_namespace 'ns1'
dml命令

hbase(main):001:0> put 't2','key1','t_info','123'0 row(s) in 0.4240 secondshbase(main):002:0> put 't2','key2','t_info:age','30'0 row(s) in 0.0130 secondshbase(main):003:0> get 't2','key1','t_info'COLUMN                                           CELL                                                                                                                                         t_info:                                         timestamp=1505381725025, value=123                                                                                                          1 row(s) in 0.0330 secondshbase(main):004:0> scan 't2'ROW                                              COLUMN+CELL                                                                                                                                  key1                                            column=t_info:, timestamp=1505381725025, value=123                                                                                           key2                                            column=t_info:age, timestamp=1505381730825, value=30                                                                                        2 row(s) in 0.0880 secondshbase(main):005:0> count 't2'2 row(s) in 0.0320 seconds=> 2hbase(main):007:0> delete 't2','key1','t_info'0 row(s) in 0.0510 secondshbase(main):008:0> scan 't2'ROW                                              COLUMN+CELL                                                                                                                                  key2                                            column=t_info:age, timestamp=1505381730825, value=30                                                                                        1 row(s) in 0.0120 secondshbase(main):009:0> truncate 't2'Truncating 't2' table (it may take a while): - Disabling table... - Truncating table...另一种表操作方法hbase(main):012:0> tab = get_table 't'0 row(s) in 0.0010 seconds=> Hbase::Table - thbase(main):013:0> tab.put ‘r1’ ,’f’, ‘v’0 row(s) in 0.0100 secondshbase(main):014:0> tab.scanROW                                COLUMN+CELL r1                                column=f:, timestamp=1378473876949, value=v展示并删除t开头的表>hbase(main):016 > tables = list(‘t.*’)TABLEt1 row(s) in 0.1040 secondshbase(main):017:0> tables.map { |t| disable t ; drop  t}0 row(s) in 2.2510 seconds> [nil]

hbase hbck  (检查)

hbase hbck -fix  (修复)

hbase thrift start 启动thrift服务

后台启动关闭:

hbase-daemon.sh start thrift

hbase-daemon.sh stop thrift


前台启动hbase rest服务
bin/hbase rest start -p <port>
后台启动hbase服务
bin/hbase-daemon.sh start rest -p <port>
停止服务
bin/hbase-daemon.sh stop rest

不加端口的情况下,端口默认为8080




原创粉丝点击