Some simple shell commands for HBase

Source: Internet
Author: User
Tags compact
Enter hbase shell console
$ HBASE_HOME / bin / hbase shell
If you have kerberos authentication, you need to use the corresponding keytab for authentication (using the kinit command) in advance. After successful authentication, use the hbase shell to enter. You can use the whoami command to view the current user
hbase (main)> whoami
Table management
1) Check which tables are available
hbase (main)> list
2) Create a table

# Syntax: create <table>, {NAME => <family>, VERSIONS => <VERSIONS>}
# For example: create table t1, there are two family names: f1, f2, and the number of versions are 2
hbase (main)> create ‘t1‘, {NAME => ‘f1‘, VERSIONS => 2}, {NAME => ‘f2‘, VERSIONS => 2}
3) Delete the table
There are two steps: first disable, then drop
For example: delete table t1

hbase (main)> disable ‘t1’
hbase (main)> drop ‘t1’
4) View the structure of the table

# Syntax: describe <table>
# For example: view the structure of table t1
hbase (main)> describe ‘t1’
5) Modify the table structure
Modify the table structure must first disable

# Syntax: alter ‘t1’, {NAME => ‘f1’}, {NAME => ‘f2’, METHOD => ‘delete’}
# For example: modify the TTL of cf in table test1 to 180 days
hbase (main)> disable ‘test1’
hbase (main)> alter ‘test1’, {NAME => ‘body’, TTL => ‘15552000’}, {NAME => ‘meta‘, TTL => ‘15552000’}
hbase (main)> enable ‘test1’
authority management
1) Assign permissions
# Syntax: grant <user> <permissions> <table> <column family> <column qualifier> Parameters are separated by commas
# The permission is represented by five letters: "RWXCA".
# READ (‘R‘), WRITE (‘W’), EXEC (‘X’), CREATE (‘C‘), ADMIN (‘A‘)
# For example, assign the user ‘test’ with read and write permissions to table t1,
hbase (main)> grant ‘test’, ‘RW’, ‘t1’
2) View permissions

# Syntax: user_permission <table>
# For example, view the permission list of table t1
hbase (main)> user_permission ‘t1’
3) Regain authority

# Similar to assigning permissions, syntax: revoke <user> <table> <column family> <column qualifier>
# For example, withdraw the test user's permissions on table t1
hbase (main)> revoke ‘test’, ‘t1’
Add, delete, and modify the table data
1) Add data
# Syntax: put <table>, <rowkey>, <family: column>, <value>, <timestamp>
# For example: add a row to the table t1: rowkey is rowkey001, family name: f1, column name: col1, value: value01, timestamp: system default
hbase (main)> put ‘t1’, ‘rowkey001’, ‘f1: col1’, ‘value01’
Usage is relatively simple.
2) Query data
a) Query a row of records

# Syntax: get <table>, <rowkey>, [<family: column>, ....]
# For example: query table t1, the value of col1 under f1 in rowkey001
hbase (main)> get ‘t1’, ‘rowkey001’, ‘f1: col1’
# Or:
hbase (main)> get ‘t1’, ‘rowkey001’, {COLUMN => ‘f1: col1’}
# Query table t1, all column values under f1 in rowke002
hbase (main)> get ‘t1’, ‘rowkey001’
b) Scanning table

# Syntax: scan <table>, {COLUMNS => [<family: column>, ....], LIMIT => num}
# In addition, you can add advanced features such as STARTROW, TIMERANGE and FITLER
# For example: scan the first 5 data of table t1
hbase (main)> scan ‘t1’, {LIMIT => 5}
c) Number of data rows in the query table

# Syntax: count <table>, {INTERVAL => intervalNum, CACHE => cacheNum}
# INTERVAL Set how many rows to display once and the corresponding rowkey, the default is 1000; the size of the cache area that CACHE fetches each time, the default is 10, adjust this parameter to improve the query speed
# For example, the number of rows in the query table t1, displayed once every 100, the cache area is 500
hbase (main)> count ‘t1‘, {INTERVAL => 100, CACHE => 500}
3) Delete data
a) Delete a column value in the row

# Syntax: delete <table>, <rowkey>, <family: column>, <timestamp>, you must specify the column name
# For example: delete the data of f1: col1 in rowkey001 of table t1
hbase (main)> delete ‘t1’, ‘rowkey001’, ‘f1: col1’
Note: will delete all the data of the f1: col1 column
b) delete row

# Syntax: deleteall <table>, <rowkey>, <family: column>, <timestamp>, you can delete the entire row of data without specifying the column name
# For example: delete the data of table t1, rowk001
hbase (main)> deleteall ‘t1’, ‘rowkey001’
c) Delete all data in the table

# Syntax: truncate <table>
# The specific process is: disable table-> drop table-> create table
# For example: delete all data in table t1
hbase (main)> truncate ‘t1’
Region Management
1) Mobile region
# Syntax: move ‘encodeRegionName’, ‘ServerName’
# encodeRegionName refers to the encoding behind regioName, ServerName refers to the list of Region-Servers of master-status
# Example
hbase (main)> move ‘4343995a58be8e5bbc739af1e91cd72d’, ‘db-41.xxx.xxx.org, 60020,1390274516739’
2) Turn on / off region

# Syntax: balance_switch true | false
hbase (main)> balance_switch
3) Manual split

# Syntax: split ‘regionName’, ‘splitKey’
4) Manually trigger major compaction

#grammar:
#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‘
Configuration management and node restart
1) Modify hdfs configuration
hdfs configuration location: / etc / hadoop / conf
# Synchronize hdfs configuration
cat / home / hadoop / slaves | xargs -i -t scp /etc/hadoop/conf/hdfs-site.xml hadoop @ {}: / etc / hadoop / conf / hdfs-site.xml
#shut down:
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 "
#start up:
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) Modify hbase configuration
hbase configuration location:

# Synchronize hbase configuration
cat / home / hadoop / hbase / conf / regionserversxargs -i -t scp /home/hadoop/hbase/conf/hbase-site.xml hadoop @ {}: / home / hadoop / hbase / conf / hbase-site xml
 
# graceful restart
cd ~ / hbase
bin / graceful_stop.sh --restart --reload --debug inspurXXX.xxx.xxx.org
Some simple shell commands of Hbase

Tags: version means ... shell command ssh cin within contain mon

Original address: http://www.cnblogs.com/BBys/p/6200552.html
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.