shell command line operation HBase database instance details
- 2020-05-14 05:44:28
- OfStack
The HBase database is operated on the shell command line
Shell control
Enter the shell command line, execute the hbase command, and append the shell keyword:
[grid@hdnode3 ~]$ hbase shell
HBase Shell; enter ¨ help ¨ for list of supported commands.
Type "exit" to leave the HBase Shell
Version 0.90.5, r1212209, Fri Dec 9 05:40:36 UTC 2011
hbase(main):001:0>
Although we have successfully logged in, we don't know what we can do now or what commands SHELL has. At this point, we can choose to go to the official documentation, or we can type help.
hbase(main):002:0> help
..................
..................
COMMAND GROUPS:
Group name: general
Commands: status, version
Group name: ddl
Commands: alter, create, describe, disable, drop, enable, exists, is_disabled, is_enabled, list
Group name: dml
Commands: count, delete, deleteall, get, get_counter, incr, put, scan, truncate
Group name: tools
Commands: assign, balance_switch, balancer, close_region, compact, flush, major_compact, move, split, unassign, zk_dump
Group name: replication
Commands: add_peer, disable_peer, enable_peer, remove_peer, start_replication, stop_replication
..................
..................
The help message did help, and from the output, we got a sense of what we could do. You can see that there are also statements like ddl/dml in hbase, as well as copy-related, administration-related commands and so on.
First try the general (general) command, query status:
hbase(main):003:0> status
5 servers, 0 dead, 0.4000 average load
Query version:
hbase(main):004:0> version
0.90.5, r1212209, Fri Dec 9 05:40:36 UTC 2011
The next key items, DDL and DML(surprisingly, HBase also contains DML/DDL statements). There is no concept of library in HBase. As a shanzhai product of BigTable, although there is no shanzhai to the name, shanzhai to the essence. In terms of design, it does not need a sub-library or even a sub-table, and all the data can be put into the same table.
Create table objects:
hbase(main):005:0> create ¨ t ¨ , ¨ t_id ¨ , ¨ t_vl ¨
0 row(s) in 2.3490 seconds
The syntax for creating objects in HBase is flexible. The previous example is shorthand, which is equivalent to the full version, "hbase
>
create ¨ t ¨, {NAME =
>
¨ t_id ¨}, {NAME =
>
", the first parameter is used to specify the table name, and all the parameters that follow are column family names. The column family of each table needs to be defined at table creation time (although it can be modified later, but it is best to start with 1), and from this perspective, the objects in HBase are structured.
View table object:
hbase(main):006:0> list
TABLE
t
1 row(s) in 0.0080 seconds
hbase(main):018:0> describe ¨ t ¨
DESCRIPTION ENABLED
{NAME => ¨ t ¨ , FAMILIES => [{NAME => ¨ t_id ¨ , BLOOMFILTER => ¨ NONE ¨ , REPLICATION_SCOPE => ¨ 0 ¨ , COMPRESSION => true
¨ NONE ¨ , VERSIONS => ¨ 3 ¨ , TTL => ¨ 2147483647 ¨ , BLOCKSIZE => ¨ 65536 ¨ , IN_MEMORY => ¨ false ¨ , BLOCKCACHE => ¨ t
rue ¨ }, {NAME => ¨ t_vl ¨ , BLOOMFILTER => ¨ NONE ¨ , REPLICATION_SCOPE => ¨ 0 ¨ , COMPRESSION => ¨ NONE ¨ , VERSIONS =>
¨ 3 ¨ , TTL => ¨ 2147483647 ¨ , BLOCKSIZE => ¨ 65536 ¨ , IN_MEMORY => ¨ false ¨ , BLOCKCACHE => ¨ true ¨ }]}
1 row(s) in 0.0100 seconds
The output is also in the form of an JSON string, from which you can see the number of versions retained, the TTL number (Time to Live, retention time), the column definition, block size, and so on.
Modify the table object, before modification (including deletion) must first disable the object, execute the modification command successfully, then enable the object.
Disabled objects:
hbase(main):004:0> disable ¨ t ¨
0 row(s) in 2.0430 seconds
Determine whether the current table object is enabled or disabled:
hbase(main):007:0> is_enabled ¨ t ¨
false
0 row(s) in 0.0040 seconds
hbase(main):008:0> is_disabled ¨ t ¨
true
0 row(s) in 0.0040 seconds
Modify the table object to add 1 column family:
hbase(main):021:0> alter ¨ t ¨ , {NAME => ¨ t_info ¨ , VERSIONS => 3}
0 row(s) in 0.0360 seconds
hbase(main):023:0> enable ¨ t ¨
0 row(s) in 2.0250 seconds
Insert record:
hbase(main):025:0> put ¨ t ¨ , ¨ 10001 ¨ , ¨ t_vl:name ¨ , ¨ jss ¨
0 row(s) in 0.0060 seconds
hbase(main):026:0> put ¨ t ¨ , ¨ 10001 ¨ , ¨ t_vl:age ¨ , ¨ 99 ¨
0 row(s) in 0.0070 seconds
hbase(main):027:0> put ¨ t ¨ , ¨ 10001 ¨ , ¨ t_info:general ¨ , ¨ his fullname is junsanis! ¨
0 row(s) in 0.0040 seconds
Record acquisition:
hbase(main):002:0> help
..................
..................
COMMAND GROUPS:
Group name: general
Commands: status, version
Group name: ddl
Commands: alter, create, describe, disable, drop, enable, exists, is_disabled, is_enabled, list
Group name: dml
Commands: count, delete, deleteall, get, get_counter, incr, put, scan, truncate
Group name: tools
Commands: assign, balance_switch, balancer, close_region, compact, flush, major_compact, move, split, unassign, zk_dump
Group name: replication
Commands: add_peer, disable_peer, enable_peer, remove_peer, start_replication, stop_replication
..................
..................
0
Gets the data of the specified column family in the specified record:
hbase(main):002:0> help
..................
..................
COMMAND GROUPS:
Group name: general
Commands: status, version
Group name: ddl
Commands: alter, create, describe, disable, drop, enable, exists, is_disabled, is_enabled, list
Group name: dml
Commands: count, delete, deleteall, get, get_counter, incr, put, scan, truncate
Group name: tools
Commands: assign, balance_switch, balancer, close_region, compact, flush, major_compact, move, split, unassign, zk_dump
Group name: replication
Commands: add_peer, disable_peer, enable_peer, remove_peer, start_replication, stop_replication
..................
..................
1
Gets the data of the specified column in the specified column family in the specified record:
hbase(main):002:0> help
..................
..................
COMMAND GROUPS:
Group name: general
Commands: status, version
Group name: ddl
Commands: alter, create, describe, disable, drop, enable, exists, is_disabled, is_enabled, list
Group name: dml
Commands: count, delete, deleteall, get, get_counter, incr, put, scan, truncate
Group name: tools
Commands: assign, balance_switch, balancer, close_region, compact, flush, major_compact, move, split, unassign, zk_dump
Group name: replication
Commands: add_peer, disable_peer, enable_peer, remove_peer, start_replication, stop_replication
..................
..................
2
Record update (no different from insert) :
hbase(main):031:0> put ¨ t ¨ , ¨ 10001 ¨ , ¨ t_vl:age ¨ , ¨ 10 ¨
0 row(s) in 0.0050 seconds
hbase(main):032:0> get ¨ t ¨ , ¨ 10001 ¨ , ¨ t_vl:age ¨
COLUMN CELL
t_vl:age timestamp=1365670912700, value=10
1 row(s) in 0.0080 seconds
Full table scanning:
hbase(main):002:0> help
..................
..................
COMMAND GROUPS:
Group name: general
Commands: status, version
Group name: ddl
Commands: alter, create, describe, disable, drop, enable, exists, is_disabled, is_enabled, list
Group name: dml
Commands: count, delete, deleteall, get, get_counter, incr, put, scan, truncate
Group name: tools
Commands: assign, balance_switch, balancer, close_region, compact, flush, major_compact, move, split, unassign, zk_dump
Group name: replication
Commands: add_peer, disable_peer, enable_peer, remove_peer, start_replication, stop_replication
..................
..................
4
The full table describes a column:
hbase(main):002:0> help
..................
..................
COMMAND GROUPS:
Group name: general
Commands: status, version
Group name: ddl
Commands: alter, create, describe, disable, drop, enable, exists, is_disabled, is_enabled, list
Group name: dml
Commands: count, delete, deleteall, get, get_counter, incr, put, scan, truncate
Group name: tools
Commands: assign, balance_switch, balancer, close_region, compact, flush, major_compact, move, split, unassign, zk_dump
Group name: replication
Commands: add_peer, disable_peer, enable_peer, remove_peer, start_replication, stop_replication
..................
..................
5
Delete record line:
hbase(main):002:0> help
..................
..................
COMMAND GROUPS:
Group name: general
Commands: status, version
Group name: ddl
Commands: alter, create, describe, disable, drop, enable, exists, is_disabled, is_enabled, list
Group name: dml
Commands: count, delete, deleteall, get, get_counter, incr, put, scan, truncate
Group name: tools
Commands: assign, balance_switch, balancer, close_region, compact, flush, major_compact, move, split, unassign, zk_dump
Group name: replication
Commands: add_peer, disable_peer, enable_peer, remove_peer, start_replication, stop_replication
..................
..................
6
Delete table:
hbase(main):002:0> help
..................
..................
COMMAND GROUPS:
Group name: general
Commands: status, version
Group name: ddl
Commands: alter, create, describe, disable, drop, enable, exists, is_disabled, is_enabled, list
Group name: dml
Commands: count, delete, deleteall, get, get_counter, incr, put, scan, truncate
Group name: tools
Commands: assign, balance_switch, balancer, close_region, compact, flush, major_compact, move, split, unassign, zk_dump
Group name: replication
Commands: add_peer, disable_peer, enable_peer, remove_peer, start_replication, stop_replication
..................
..................
7
So after looking at the previous example, do you have any questions or thoughts? There is no UPDATE operation in HBase, only INSERT. However, every time we replace the old version with the new put record, how can we save a large number of records? Can there be only one record per row key columns? It's not scientific! This is clearly not what the people expect and want.
The problem is that the column value saved version (VERSIONS) or the retention time (TTL, Time to Liv) is at work.
For example, if we want to count a user's recent (n) browsing history, create the HBase table object as follows:
hbase > create ¨ rlog ¨, ¨ userid ¨, {NAME = > ¨ article ¨, VERSIONS = > 100}
Current Settings, keep the last 100 versions. When a user browses a post, he inserts a record into the rlog table in the following form:
hbase > put ¨ rlog ¨, $userid, ¨ article: id ¨, $aid
Only the user ID and the browsing page ID are selected here, and the URL address, article title and other information of the page can be saved according to the actual situation. The HBase table column family is unstructured, and you can add as many columns as you want.
So, how should you look up a user's recent browsing history? For example, get the 10 most recently viewed records:
hbase
>
get ¨ rlog ¨, $userid, {COLUMN =
>
¨ article: id ¨, VERSIONS =
>
10}
In addition to being controlled by VERSIONS, you can also consider the version save time of TTL, which is measured in seconds and is saved for 30 days by default.
Thank you for reading, I hope to help you, thank you for your support of this site!