[关闭]
@nalan90 2017-08-22T15:34:40.000000Z 字数 17400 阅读 663

Hbase

大数据


摘自:https://learnhbase.wordpress.com/2013/03/02/hbase-shell-commands/?spm=5176.doc52056.2.3.RkSQvE

核心组件


HBase shell commands

HBase shell commands are mainly categorized into 6 parts

1、General HBase shell commands
  1. ## status
  2. Show cluster status. Can be summary’, simple’, or detailed’. The default is summary’.
  3. hbase> status
  4. hbase> status simple
  5. hbase> status summary
  6. hbase> status detailed
  7. ----------
  8. ## version
  9. Output this HBase versionUsage:
  10. hbase> version
  11. ----------
  12. ## whoami
  13. Show the current hbase user.Usage:
  14. hbase> whoami

2、Tables Management commands
  1. ## alter
  2. Alter column family schema; pass table name and a dictionary specifying new column family schema. Dictionaries are described on the main help command output. Dictionary must include name of column family to alter.For example, to change or add the f1 column family in table t1 from current value to keep a maximum of 5 cell VERSIONS, do:
  3. hbase> alter t1’, NAME => f1’, VERSIONS => 5
  4. You can operate on several column families:
  5. hbase> alter t1’, f1’, {NAME => f2’, IN_MEMORY => true}, {NAME => f3’, VERSIONS => 5}
  6. To delete the f1 column family in table t1’, use one of:
  7. hbase> alter t1’, NAME => f1’, METHOD => delete
  8. hbase> alter t1’, delete => f1
  9. You can also change table-scope attributes like MAX_FILESIZE, READONLY, MEMSTORE_FLUSHSIZE, DEFERRED_LOG_FLUSH, etc. These can be put at the end; for example, to change the max size of a region to 128MB, do:
  10. hbase> alter t1’, MAX_FILESIZE => 134217728
  11. You can add a table coprocessor by setting a table coprocessor attribute:
  12. hbase> alter t1’,‘coprocessor’=>’hdfs:///foo.jar|com.foo.FooRegionObserver|1001|arg1=1,arg2=2’
  13. Since you can have multiple coprocessors configured for a table, a sequence number will be automatically appended to the attribute name to uniquely identify it.
  14. The coprocessor attribute must match the pattern below in order for the framework to understand how to load the coprocessor classes:
  15. [coprocessor jar file location] | class name | [priority] | [arguments]
  16. You can also set configuration settings specific to this table or column family:
  17. hbase> alter t1’, CONFIGURATION => {‘hbase.hregion.scan.loadColumnFamiliesOnDemand => true’}
  18. hbase> alter t1’, {NAME => f2’, CONFIGURATION => {‘hbase.hstore.blockingStoreFiles => 10’}}
  19. You can also remove a table-scope attribute:
  20. hbase> alter t1’, METHOD => table_att_unset’, NAME => MAX_FILESIZE
  21. hbase> alter t1’, METHOD => table_att_unset’, NAME => coprocessor$1
  22. There could be more than one alteration in one command:
  23. hbase> alter t1’, { NAME => f1’, VERSIONS => 3 },{ MAX_FILESIZE => 134217728 }, { METHOD => delete’, NAME => f2 },OWNER => johndoe’, METADATA => { mykey => myvalue }
  24. ----------
  25. ## create
  26. Create table; pass table name, a dictionary of specifications per column family, and optionally a dictionary of table configuration.
  27. hbase> create t1’, {NAME => f1’, VERSIONS => 5}
  28. hbase> create t1’, {NAME => f1’}, {NAME => f2’}, {NAME => f3’}
  29. hbase> # The above in shorthand would be the following:
  30. hbase> create t1’, f1’, f2’, f3
  31. hbase> create t1’, {NAME => f1’, VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true}
  32. hbase> create t1’, {NAME => f1’, CONFIGURATION => {‘hbase.hstore.blockingStoreFiles => 10’}}
  33. Table configuration options can be put at the end.
  34. ----------
  35. ## describe
  36. Describe the named table.
  37. hbase> describe t1
  38. ----------
  39. ## disable
  40. Start disable of named table
  41. hbase> disable t1
  42. ----------
  43. ## disable_all
  44. Disable all of tables matching the given regex
  45. hbase> disable_all t.*’
  46. ----------
  47. ## is_disabled
  48. verifies Is named table disabled
  49. hbase> is_disabled t1
  50. ----------
  51. ## drop
  52. Drop the named table. Table must first be disabled
  53. hbase> drop t1
  54. ----------
  55. ## drop_all
  56. Drop all of the tables matching the given regex
  57. hbase> drop_all t.*’
  58. ----------
  59. ## enable
  60. Start enable of named table
  61. hbase> enable t1
  62. ----------
  63. ## enable_all
  64. Enable all of the tables matching the given regex
  65. hbase> enable_all t.*’
  66. ----------
  67. ## is_enabled
  68. verifies Is named table enabled
  69. hbase> is_enabled t1
  70. ----------
  71. ## exists
  72. Does the named table exist
  73. hbase> exists t1
  74. ----------
  75. ## list
  76. List all tables in hbase. Optional regular expression parameter could be used to filter the output
  77. hbase> list
  78. hbase> list abc.*’
  79. ----------
  80. ## show_filters
  81. Show all the filters in hbase.
  82. hbase> show_filters
  83. ----------
  84. ## alter_status
  85. Get the status of the alter command. Indicates the number of regions of the table that have received the updated schema Pass table name.
  86. hbase> alter_status t1
  87. ----------
  88. ## alter_async
  89. Alter column family schema, does not wait for all regions to receive the schema changes. Pass table name and a dictionary specifying new column family schema. Dictionaries are described on the main help command output.
  90. Dictionary must include name of column family to alter. To change or add the f1 column family in table t1 from defaults to instead keep a maximum of 5 cell VERSIONS, do:
  91. hbase> alter_async t1’, NAME => f1’, VERSIONS => 5
  92. To delete the f1 column family in table t1’, do:
  93. hbase> alter_async t1’, NAME => f1’, METHOD => delete
  94. or a shorter version:
  95. hbase> alter_async t1’, delete => f1
  96. You can also change table-scope attributes like MAX_FILESIZE MEMSTORE_FLUSHSIZE, READONLY, and DEFERRED_LOG_FLUSH.
  97. For example, to change the max size of a family to 128MB, do:
  98. hbase> alter t1’, METHOD => table_att’, MAX_FILESIZE => 134217728
  99. There could be more than one alteration in one command:
  100. hbase> alter t1’, {NAME => f1’}, {NAME => f2’, METHOD => delete’}
  101. To check if all the regions have been updated, use alter_status <table_name>

3、Data Manipulation commands
  1. ## count
  2. Count the number of rows in a table. Return value is the number of rows.This operation may take a LONG time (Run $HADOOP_HOME/bin/hadoop jar hbase.jar rowcount to run a counting mapreduce job). Current count is shown every 1000 rows by default. Count interval may be optionally specified. Scan caching is enabled on count scans by default. Default cache size is 10 rows. If your rows are small in size, you may want to increase this parameter. Examples:
  3. hbase> count t1
  4. hbase> count t1’, INTERVAL => 100000
  5. hbase> count t1’, CACHE => 1000
  6. hbase> count t1’, INTERVAL => 10, CACHE => 1000
  7. The same commands also can be run on a table reference. Suppose you had a reference t to table t1’, the corresponding commands would be:
  8. hbase> t.count
  9. hbase> t.count INTERVAL => 100000
  10. hbase> t.count CACHE => 1000
  11. hbase> t.count INTERVAL => 10, CACHE => 1000
  12. ----------
  13. ## delete
  14. Put a delete cell value at specified table/row/column and optionally timestamp coordinates. Deletes must match the deleted cells coordinates exactly. When scanning, a delete cell suppresses older versions. To delete a cell from t1 at row r1 under column c1
  15. marked with the time ts1’, do:
  16. hbase> delete t1’, r1’, c1’, ts1
  17. The same command can also be run on a table reference. Suppose you had a reference t to table t1’, the corresponding command would be:hbase> t.delete r1’, c1’, ts1
  18. ----------
  19. ## deleteall
  20. Delete all cells in a given row; pass a table name, row, and optionally a column and timestamp.
  21. Examples:
  22. hbase> deleteall t1’, r1
  23. hbase> deleteall t1’, r1’, c1
  24. hbase> deleteall t1’, r1’, c1’, ts1
  25. 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:
  26. hbase> t.deleteall r1
  27. hbase> t.deleteall r1’, c1
  28. hbase> t.deleteall r1’, c1’, ts1
  29. ----------
  30. ## get
  31. Get row or cell contents; pass table name, row, and optionally a dictionary of column(s), timestamp, timerange and versions. Examples:
  32. hbase> get t1’, r1
  33. hbase> get t1’, r1’, {TIMERANGE => [ts1, ts2]}
  34. hbase> get t1’, r1’, {COLUMN => c1’}
  35. hbase> get t1’, r1’, {COLUMN => [‘c1’, c2’, c3’]}
  36. hbase> get t1’, r1’, {COLUMN => c1’, TIMESTAMP => ts1}
  37. hbase> get t1’, r1’, {COLUMN => c1’, TIMERANGE => [ts1, ts2], VERSIONS => 4}
  38. hbase> get t1’, r1’, {COLUMN => c1’, TIMESTAMP => ts1, VERSIONS => 4}
  39. hbase> get t1’, r1’, {FILTER => ValueFilter(=, binary:abc’)”}
  40. hbase> get t1’, r1’, c1
  41. hbase> get t1’, r1’, c1’, c2
  42. hbase> get t1’, r1’, [‘c1’, c2’]
  43. Besides the default toStringBinary format, get also supports custom formatting by column. A user can define a FORMATTER by adding it to the column name in the get specification. The FORMATTER can be stipulated:
  44. 1. either as a org.apache.hadoop.hbase.util.Bytes method name (e.g, toInt, toString)
  45. 2. or as a custom class followed by method name: e.g. c(MyFormatterClass).format’.Example formatting cf:qualifier1 and cf:qualifier2 both as Integers:
  46. hbase> get t1’, r1 {COLUMN => [‘cf:qualifier1:toInt’,‘cf:qualifier2:c(org.apache.hadoop.hbase.util.Bytes).toInt’] }
  47. Note that you can specify a FORMATTER by column only (cf:qualifer). You cannot specify a FORMATTER for all columns of a column family.The same commands also can be run on a reference to a table (obtained via get_table or
  48. create_table). Suppose you had a reference t to table t1’, the corresponding commands would be:
  49. hbase> t.get r1
  50. hbase> t.get r1’, {TIMERANGE => [ts1, ts2]}
  51. hbase> t.get r1’, {COLUMN => c1’}
  52. hbase> t.get r1’, {COLUMN => [‘c1’, c2’, c3’]}
  53. hbase> t.get r1’, {COLUMN => c1’, TIMESTAMP => ts1}
  54. hbase> t.get r1’, {COLUMN => c1’, TIMERANGE => [ts1, ts2], VERSIONS => 4}
  55. hbase> t.get r1’, {COLUMN => c1’, TIMESTAMP => ts1, VERSIONS => 4}
  56. hbase> t.get r1’, {FILTER => ValueFilter(=, binary:abc’)”}
  57. hbase> t.get r1’, c1
  58. hbase> t.get r1’, c1’, c2
  59. hbase> t.get r1’, [‘c1’, c2’]
  60. ----------
  61. ## get_counter
  62. Return a counter cell value at specified table/row/column coordinates.A cell cell should be managed with atomic increment function oh HBase and the data should be binary encoded. Example:
  63. hbase> get_counter t1’, r1’, c1
  64. 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:
  65. hbase> t.get_counter r1’, c1
  66. ----------
  67. ## incr
  68. Increments a cell value at specified table/row/column coordinates. To increment a cell value in table t1 at row r1 under column c1 by 1 (can be omitted) or 10 do:
  69. hbase> incr t1’, r1’, c1
  70. hbase> incr t1’, r1’, c1’, 1
  71. hbase> incr t1’, r1’, c1’, 10
  72. 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.incr r1’, c1
  73. hbase> t.incr r1’, c1’, 1
  74. hbase> t.incr r1’, c1’, 10
  75. ----------
  76. ## put
  77. Put a cell value at specified table/row/column and optionally timestamp coordinates. To put a cell value into table t1 at row r1 under column c1 marked with the time ts1’, do:
  78. hbase> put t1’, r1’, c1’, value’, ts1
  79. 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:
  80. hbase> t.put r1’, c1’, value’, ts1
  81. ----------
  82. ## scan
  83. Scan a table; pass table name and optionally a dictionary of scanner specifications. Scanner specifications may include one or more of: TIMERANGE, FILTER, LIMIT, STARTROW, STOPROW, TIMESTAMP, MAXLENGTH,or COLUMNS, CACHEIf no columns are specified, all columns will be scanned. To scan all members of a column family, leave the qualifier empty as in col_family:’.The filter can be specified in two ways:
  84. 1. Using a filterString more information on this is available in the Filter Language document attached to the HBASE-4176 JIRA
  85. 2. Using the entire package name of the filter.
  86. Some examples:
  87. hbase> scan ‘.META.’
  88. hbase> scan ‘.META.’, {COLUMNS => info:regioninfo’}
  89. hbase> scan t1’, {COLUMNS => [‘c1’, c2’], LIMIT => 10, STARTROW => xyz’}
  90. hbase> scan t1’, {COLUMNS => c1’, TIMERANGE => [1303668804, 1303668904]}
  91. hbase> scan t1’, {FILTER => “(PrefixFilter (‘row2’) AND (QualifierFilter (>=, binary:xyz’))) AND (TimestampsFilter ( 123, 456))”}
  92. hbase> scan t1’, {FILTER => org.apache.hadoop.hbase.filter.ColumnPaginationFilter.new(1, 0)}
  93. For experts, there is an additional option CACHE_BLOCKS which switches block caching for the scanner on (true) or off (false). By default it is enabled. Examples:hbase> scan t1’, {COLUMNS => [‘c1’, c2’], CACHE_BLOCKS => false}
  94. Also for experts, there is an advanced option RAW which instructs the scanner to return all cells (including delete markers and uncollected deleted cells). This option cannot be combined with requesting specific COLUMNS.
  95. Disabled by default. Example:
  96. hbase> scan t1’, {RAW => true, VERSIONS => 10}
  97. Besides the default toStringBinary format, scan supports custom formatting by column. A user can define a FORMATTER by adding it to the column name in the scan specification. The FORMATTER can be stipulated:
  98. 1. either as a org.apache.hadoop.hbase.util.Bytes method name (e.g, toInt, toString)
  99. 2. or as a custom class followed by method name: e.g. c(MyFormatterClass).format’.
  100. Example formatting cf:qualifier1 and cf:qualifier2 both as Integers:
  101. hbase> scan t1’, {COLUMNS => [‘cf:qualifier1:toInt’,‘cf:qualifier2:c(org.apache.hadoop.hbase.util.Bytes).toInt’] }
  102. Note that you can specify a FORMATTER by column only (cf:qualifer). You cannot specify a FORMATTER for all columns of a column family.
  103. Scan can also be used directly from a table, by first getting a reference to a table, like such:
  104. hbase> t = get_table t
  105. hbase> t.scan
  106. Note in the above situation, you can still provide all the filtering, columns, options, etc as described above.
  107. ----------
  108. ## truncate
  109. Disables, drops and recreates the specified table.
  110. Examples:
  111. hbase>truncate t1

4、HBase surgery tools
  1. ## assign
  2. Assign a region. Use with caution. If region already assigned,this command will do a force reassign. For experts only.
  3. Examples:
  4. hbase> assign REGION_NAME
  5. ----------
  6. ## balancer
  7. Trigger the cluster balancer. Returns true if balancer ran and was able to tell the region servers to unassign all the regions to balance (the re-assignment itself is async). Otherwise false (Will not run if regions in transition).
  8. Examples:
  9. hbase> balancer
  10. ----------
  11. ## balance_switch
  12. Enable/Disable balancer. Returns previous balancer state.
  13. Examples:
  14. hbase> balance_switch true
  15. hbase> balance_switch false
  16. ----------
  17. ## close_region
  18. Close a single region. Ask the master to close a region out on the cluster or if SERVER_NAME is supplied, ask the designated hosting regionserver to close the region directly. Closing a region, the master expects REGIONNAME to be a fully qualified region name. When asking the hosting regionserver to directly close a region, you pass the regions encoded name only. A region name looks like this:TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.The trailing period is part of the regionserver name. A regions encoded name is the hash at the end of a region name; e.g. 527db22f95c8a9e0116f0cc13c680396 (without the period). A SERVER_NAME is its host, port plus startcode. For
  19. example: host187.example.com,60020,1289493121758 (find servername in master ui or when you do detailed status in shell). This command will end up running close on the region hosting regionserver. The close is done without the
  20. masters involvement (It will not know of the close). Once closed, region will stay closed. Use assign to reopen/reassign. Use unassign or move to assign the region elsewhere on cluster. Use with caution. For experts only.
  21. Examples:
  22. hbase> close_region REGIONNAME
  23. hbase> close_region REGIONNAME’, SERVER_NAME
  24. ----------
  25. ## compact
  26. Compact all regions in passed table or pass a region row to compact an individual region. You can also compact a single column family within a region.
  27. Examples:
  28. Compact all regions in a table:
  29. hbase> compact t1
  30. Compact an entire region:
  31. hbase> compact r1
  32. Compact only a column family within a region:
  33. hbase> compact r1’, c1
  34. Compact a column family within a table:
  35. hbase> compact t1’, c1
  36. ----------
  37. ## flush
  38. Flush all regions in passed table or pass a region row to flush an individual region.
  39. For example:
  40. hbase> flush TABLENAME
  41. hbase> flush REGIONNAME
  42. ----------
  43. ## major_compact
  44. Run major compaction on passed table or pass a region row to major compact an individual region. To compact a single column family within a region specify the region name followed by the column family name.
  45. Examples:
  46. Compact all regions in a table:
  47. hbase> major_compact t1
  48. Compact an entire region:
  49. hbase> major_compact r1
  50. Compact a single column family within a region:
  51. hbase> major_compact r1’, c1
  52. Compact a single column family within a table:
  53. hbase> major_compact t1’, c1
  54. ----------
  55. ## move
  56. Move a region. Optionally specify target regionserver else we choose one at random. NOTE: You pass the encoded region name, not the region name so this command is a little different to the others. The encoded region name
  57. is the hash suffix on region names: e.g. if the region name were TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396. then the encoded region name portion is 527db22f95c8a9e0116f0cc13c680396 A server name is its host, port plus startcode.
  58. For example:
  59. host187.example.com,60020,1289493121758
  60. Examples:
  61. hbase> move ENCODED_REGIONNAME
  62. hbase> move ENCODED_REGIONNAME’, SERVER_NAME
  63. ----------
  64. ## split
  65. Split entire table or pass a region to split individual region. With the second parameter, you can specify an explicit split key for the region.
  66. Examples:
  67. split tableName
  68. split regionName # format: ‘tableName,startKey,id’
  69. split tableName’, splitKey
  70. split regionName’, splitKey
  71. ----------
  72. ## unassign
  73. Unassign a region. Unassign will close region in current location and then reopen it again. Pass true to force the unassignment (‘force will clear all in-memory state in master before the reassign. If results in double assignment use hbck -fix to resolve. To be used by experts). Use with caution. For expert use only.
  74. Examples:
  75. hbase> unassign REGIONNAME
  76. hbase> unassign REGIONNAME’, true
  77. ----------
  78. ## hlog_roll
  79. Roll the log writer. That is, start writing log messages to a new file.The name of the regionserver should be given as the parameter. A server_name is the host, port plus startcode of a regionserver. For example: host187.example.com,60020,1289493121758 (find servername in master ui or when you do detailed status in shell)
  80. hbase>hlog_roll
  81. ----------
  82. ## zk_dump
  83. Dump status of HBase cluster as seen by ZooKeeper. Example:
  84. hbase>zk_dump

5、Cluster replication tools
  1. ## add_peer
  2. Add a peer cluster to replicate to, the id must be a short and the cluster key is composed like this:
  3. hbase.zookeeper.quorum:hbase.zookeeper.property.clientPort:zookeeper.znode.parent This gives a full path for HBase to connect to another cluster.
  4. Examples:
  5. hbase> add_peer 1’, server1.cie.com:2181:/hbase
  6. hbase> add_peer 2’, zk1,zk2,zk3:2182:/hbase-prod
  7. remove_peer Stops the specified replication stream and deletes all the meta information kept about it. Examples:
  8. hbase> remove_peer 1
  9. ----------
  10. ## list_peers
  11. List all replication peer clusters.
  12. hbase> list_peers
  13. enable_peer Restarts the replication to the specified peer cluster,continuing from where it was disabled.Examples:
  14. hbase> enable_peer 1
  15. ----------
  16. ## disable_peer
  17. Stops the replication stream to the specified cluster, but still keeps track of new edits to replicate.Examples:
  18. hbase> disable_peer 1
  19. ----------
  20. ## start_replication
  21. Restarts all the replication features. The state in which each stream starts in is undetermined.
  22. WARNING:
  23. start/stop replication is only meant to be used in critical load situations.
  24. Examples:
  25. hbase> start_replication
  26. ----------
  27. ## stop_replication
  28. Stops all the replication features. The state in which each stream stops in is undetermined.
  29. WARNING:
  30. start/stop replication is only meant to be used in critical load situations.
  31. Examples:
  32. hbase> stop_replication

6、Security tools
  1. ## grant
  2. Grant users specific rights. Syntax : grantpermissions is either zero or more letters from the set RWXCA”.
  3. READ(‘R’), WRITE(‘W’), EXEC(‘X’), CREATE(‘C’), ADMIN(‘A’)
  4. For example:
  5. hbase> grant bobsmith’, RWXCA
  6. hbase> grant bobsmith’, RW’, t1’, f1’, col1
  7. ----------
  8. ## revoke
  9. Revoke a users access rights.
  10. Syntax : revoke
  11. For example:
  12. hbase> revoke bobsmith’, t1’, f1’, col1
  13. ----------
  14. ## user_permission
  15. Show all permissions for the particular user.
  16. Syntax : user_permission
  17. For example:hbase> user_permission
  18. hbase> user_permission table1
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注