table of Contents
Third, the management of the table
Fourth, add, delete, modify and check table data
Five, importtsv of hbase data migration
Hbase Shell start
[root@master conf]# hbase shell SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/usr/hadoop/hbase-1.6.0/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/usr/hadoop/hadoop-2.10.0/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] HBase Shell Use "help" to get list of supported commands. Use "exit" to quit this interactive shell. Version 1.6.0, r5ec5a5b115ee36fb28903667c008218abd21b3f5, Fri Feb 14 12:00:03 PST 2020 hbase(main):001:0>
<!--Attention-->
The hbase shell cannot use backspace to delete text. So we set it up in xshell.
One, basic commands
1. Connect to hbase
hbase shell
2. Display the hbase shell help text
type help
Then press Enter to display some basic usage information of HBASE Shell, as well as some sample commands. Note that the table name, row, and column must be enclosed in quotation marks.
3. Create a table
Use the create
command to create a new table. You must specify the table name and Column class name.
creat 'table_name','family1','family2','familyN'
4. List information about the table
Use the list
command to confirm the existence of the table.
list 'table_name'
Now use the describe
command to view detailed information, including configuration defaults.
describe 'table_name'
5. Insert the data into your table
To put data in the table, use the put
command.
put 'table_name','rowkey','family:column','value' #eg: put 'test', 'row1', 'cf:a', 'value1'
Insert at row1
, column cf:a
, value value1
.
The columns in HBASE are composed of column family prefixes.
6. View all records
One of the methods to obtain data from HBASE is scanning. Use the scan
command to scan the table for data. You can limit the scan, but for now, all data will be captured.
#All display scan'table_name' #Display 10 records scan'table_name',{LIMIT=>10}
7. Get a row of data
To get one row of data at a time, use the get
command.
get 'table_name','rowkey'
8. Disable a table
If you want to delete a table or change its settings, and in some other cases, you need to disable the table first and use the disable
command. You can use enable
commands.
disable 'table_name' # enable 'table_name'
9. Delete a table
To delete (delete) the table, use the drop
command. Note: Disable first
disable 'table_name' drop 'table_name'
10. View the total number of records in the table
This command is not fast, but there is no way to count the number of rows faster than this.
count 'table_name'
11. Delete records
The first way to delete a single column of data in a record
The second way to delete the entire record
delete 'table_name','rowkey','family_name:column' #### delete 'table_name','rowkey'
12. Exit the hbase shell
To exit HBASE Shell and disconnect from the cluster, use the quit
command. HBASE is still running in the background.
quit
Second, the data model
In HBASE, data is stored in a table with rows and columns. This is a term overlapping relational database (RDBMS), but it is not a useful analogy. Instead, it is helpful to think of HBASE tables as multidimensional maps.
HBASE data model terminology
-
table
The HBASE table consists of multiple rows.
At the conceptual level, a table can be seen as a set of sparse rows, but they are actually stored by column families. A new column qualifier (column family: column qualifier) can be added to an existing column family at any time.
-
Row key
A row in HBASE consists of a row key and one or more columns, and column values are associated with them. The rows are sorted alphabetically by pressing the row key when they are stored. Therefore, the design of the row key is very important. The goal is to store data in such a way that related rows are close to each other. The common row key pattern is the website domain. If your row keys are domains, you should store them in reverse (org.apache.www, org.apache.mail, org.apache.jira). In this way, all Apache domains are close to each other in the table, instead of expanding based on the first letter of the subdomain.
-
Column
The columns in HBASE are composed of column families and column qualifiers, which consist of
:
(colon) characters. -
Column family
Column families physically share a set of columns and their values, usually for performance reasons. Each column family has a set of storage attributes, such as whether its value should be cached in memory, how its data is compressed, or how row keys are encoded. Each row in the table has the same column family, although a given row may not store anything in a given column family.
-
Column qualifier
Column qualifiers are added to the column family to provide an index for a given data segment. For the column family
content
, the column qualifier may becontent:html
, and the other may becontent:pdf
. Although the column family is fixed when the table is created, the column qualifiers are variable and can vary greatly between rows. -
Cell
A cell is a combination of row, column series, and column qualifiers, and contains a value and a timestamp, which represents the version of the value.
-
Timestamp
The timestamp is written side-by-side with each value and is an identifier for a given version of the value. By default, the timestamp represents the time on the RegionServer when the data is written, but you can specify a different timestamp value when putting the data into the cell.
Third, the management of the table
-
list command
#语法格式 list <table> hbase(main):001:0> list TABLE 0 row(s) in 3.6950 seconds => [] hbase(main):002:0>
2.create command
hbase(main):002:0> create 'scores2',{NAME=>'course',VERSIONS=>3},{NAME=>'grade',VERSIONS=>3} 0 row(s) in 3.0720 seconds => Hbase::Table - scores2 hbase(main):003:0> create 'scores','course','grade'
3.describe
hbase(main):005:0> describe 'scores' Table scores is ENABLED scores COLUMN FAMILIES DESCRIPTION {NAME => 'course', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS = > 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => ' 0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'} {NAME => 'grade', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0 ', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'} 2 row(s) in 0.1460 seconds hbase(main):006:0>
4.disable
hbase(main):006:0> disable 'scores2' 0 row(s) in 2.4350 seconds hbase(main):007:0> drop 'scores2' 0 row(s) in 1.3560 seconds hbase(main):008:0> list TABLE scores 1 row(s) in 0.0500 seconds => ["scores"] hbase(main):009:0>
5.exists
hbase(main):009:0> exists 'scores2' Table scores2 does not exist 0 row(s) in 0.0200 seconds hbase(main):010:0>
6.is_enabled
Determine whether the table is enable, syntax: enable <table>
hbase(main):013:0> is_enabled 'scores' true 0 row(s) in 0.0280 seconds hbase(main):014:0>
7.is_disabled
Determine whether the table is disabled, format: disable<table>
hbase(main):014:0> is_disabled 'scores' false 0 row(s) in 0.0450 seconds hbase(main):015:0>
8.alter
Modify the table structure.
语法格式:alter <table>,{NAME=><family>},{NAME=><family>,METHOD=>'delete'}
#Add a column of family address to the scores table, and specify the number of versions as 3: hbase(main):015:0> alter'scores',NAME=>'address',VERSIONS=>3 Updating all regions with the new schema.. . 0/1 regions updated. 1/1 regions updated. Done. 0 row(s) in 3.6060 seconds #Delete the grade column family in the scores table hbase(main):016:0> alter'scores',NAME= >'grade',METHOD=>'delete' Updating all regions with the new schema... 0/1 regions updated. 1/1 regions updated. Done. 0 row(s) in 3.7150 seconds
<!--Attention-->
Before making changes to the table structure, the table needs to be deactivated and restarted after the operation is completed. E.g:
disable 'scores' alter 操作 enable 'scores'
9. Delete the column family
(1) Forbidden table
hbase(main):017:0> disable 'scores' 0 row(s) in 2.3090 seconds
(2) Delete the list (note that NAME and METHOD should be capitalized)
hbase(main):018:0> alter 'scores',NAME=>'course',METHOD=>'delete' Updating all regions with the new schema... 1/1 regions updated. Done. 0 row(s) in 2.2050 seconds
(3) Delete the column family and then enable the table
hbase(main):019:0> enable 'scores' 0 row(s) in 1.3910 seconds
(4) Check the table information again, you can see that the course has been deleted
hbase(main):020:0> describe 'scores' Table scores is ENABLED scores COLUMN FAMILIES DESCRIPTION {NAME => 'address', BLOOMFILTER => 'ROW', VERSIONS => '3', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DAT A_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLO CKSIZE => '65536', REPLICATION_SCOPE => '0'} 1 row(s) in 0.0410 seconds
10.whoami
View users currently accessing HBase
hbase(main):021:0> whoami root (auth:SIMPLE) groups: root hbase(main):022:0>
11.version
View HBase version information
hbase(main):022:0> version 1.6.0, r5ec5a5b115ee36fb28903667c008218abd21b3f5, Fri Feb 14 12:00:03 PST 2020
12.status
View current HBase status
#####status hbase(main):023:0> status 1 active master, 0 backup masters, 2 servers, 0 dead, 1.5000 average load ####status 'summary' hbase(main):024:0> status 'summary' 1 active master, 0 backup masters, 2 servers, 0 dead, 1.5000 average load ####status 'detailed' hbase(main):025:0> status 'detailed' version 1.6.0 0 regionsInTransition active master: master:16000 1607158473117 0 backup masters master coprocessors: null 2 live servers slave1:16020 1607158482456 requestsPerSecond=0.0, numberOfOnlineRegions=1, usedHeapMB=20, maxHeapMB=235, numberOfStores=1, numberOfStorefiles=2, storefileUncompressedSizeMB=0, storefileSizeMB=0, memstoreSizeMB=0, storefileIndexSizeMB=0, readRequestsCount=70, writeRequestsCount=9, rootIndexSizeKB=0, totalStaticIndexSizeKB=0, totalStaticBloomSizeKB=0, totalCompactingKVs=21, currentCompactedKVs=21, compactionProgressPct=1.0, coprocessors=[MultiRowMutationEndpoint] "hbase:meta,,1" numberOfStores=1, numberOfStorefiles=2, storeRefCount=0, maxCompactedStoreFileRefCount=0, storefileUncompressedSizeMB=0, lastMajorCompactionTimestamp=1607159362926, storefileSizeMB=0, memstoreSizeMB=0, storefileIndexSizeMB=0, readRequestsCount=70, writeRequestsCount=9, rootIndexSizeKB=0, totalStaticIndexSizeKB=0, totalStaticBloomSizeKB=0, totalCompactingKVs=21, currentCompactedKVs=21, compactionProgressPct=1.0, completeSequenceId=45, dataLocality=1.0 slave2:16020 1607158481937 requestsPerSecond=0.0, numberOfOnlineRegions=2, usedHeapMB=13, maxHeapMB=235, numberOfStores=2, numberOfStorefiles=1, storefileUncompressedSizeMB=0, storefileSizeMB=0, memstoreSizeMB=0, storefileIndexSizeMB=0, readRequestsCount=4, writeRequestsCount=0, rootIndexSizeKB=0, totalStaticIndexSizeKB=0, totalStaticBloomSizeKB=0, totalCompactingKVs=0, currentCompactedKVs=0, compactionProgressPct=NaN, coprocessors=[] "hbase:namespace,,1607137216837.828e7f51fd1fef7501b8ccc4c3b373ca." numberOfStores=1, numberOfStorefiles=1, storeRefCount=0, maxCompactedStoreFileRefCount=0, storefileUncompressedSizeMB=0, lastMajorCompactionTimestamp=0, storefileSizeMB=0, memstoreSizeMB=0, storefileIndexSizeMB=0, readRequestsCount=4, writeRequestsCount=0, rootIndexSizeKB=0, totalStaticIndexSizeKB=0, totalStaticBloomSizeKB=0, totalCompactingKVs=0, currentCompactedKVs=0, compactionProgressPct=NaN, completeSequenceId=-1, dataLocality=1.0 "scores,,1607147570746.91663a6c1657acef0ce3c114638e81af." numberOfStores=1, numberOfStorefiles=0, storeRefCount=0, maxCompactedStoreFileRefCount=0, storefileUncompressedSizeMB=0, lastMajorCompactionTimestamp=0, storefileSizeMB=0, memstoreSizeMB=0, storefileIndexSizeMB=0, readRequestsCount=0, writeRequestsCount=0, rootIndexSizeKB=0, totalStaticIndexSizeKB=0, totalStaticBloomSizeKB=0, totalCompactingKVs=0, currentCompactedKVs=0, compactionProgressPct=NaN, completeSequenceId=-1, dataLocality=0.0 0 dead servers hbase(main):026:0>
13. Authority management
(1) Assign permissions
There are R (read), W (write), X (execute), C (create), A (administrator). Syntax format:
grant<user>,<permissions>,<table>,<column family>,<column qualifier>
Hbase's authority management relies on the coprocessor, and the authority control is implemented through the AccessController Coprocessor coprocessor framework, which can realize the authority control of the user's RWXCA.
Need to configure
hbase.security.authorization=true
hbase.coprocessor.master.classes and hbase.coprocessor.master.classes make it include org.apache.hadoop.hbase.security.access.AccessController to provide security management capabilities, so
The following parameters need to be set: stop HBase running, configure hbase-site.xml
<property> <name>hbase.superuser</name> <value>hbase</value> </property> <property> <name>hbase.coprocessor.region.classes</name> <value>org.apache.hadoop.hbase.security.access.AccessController,org.apache.hadoop.hbase.security.token.TokenProvider</value> </property> <property> <name>hbase.coprocessor.regionserver.classes</name> <value>org.apache.hadoop.hbase.security.access.AccessController</value> </property> <property> <name>hbase.coprocessor.master.classes</name> <value>org.apache.hadoop.hbase.security.access.AccessController</value> </property> <property> <name>hbase.rpc.engine</name> <value>org.apache.hadoop.hbase.ipc.SecureRpcEngine</value> </property> <property> <name>hbase.security.authorization</name> <value>true</value> </property>
After the configuration is complete, save, exit and restart HBase.
(2) Assign permissions
hbase(main)> grant '<user>', '<permission>', '<table>' hbase(main)> grant 'user1', 'RWXCA', 'table1'
(3) View authority
hbase(main)> user_permission '<table>' hbase(main)> user_permission 'table1' User Namespace,Table,Family,Qualifier:Permission user1 default,table1,,: [Permission: actions=READ,WRITE,EXEC,CREATE,ADMIN]
Syntax format: user_permission<table>
(4) Withdrawal of authority
hbase(main)> revoke '<user>', '<table>' hbase(main)> revoke 'user1', 'table1'
Similar to assigning permissions, the syntax format: revoke<user><table><column family><column qualifier>
Fourth, add, delete, modify and check table data
1.put
Insert data into the table. Syntax: put<table>,<rowkey>,<family: column>,<value>,<timesstamp>
For example: insert data into the table scores2, rk001 is the row key, course is the column family, soft is the column name, and the value is database.
hbase(main):012:0> list TABLE scores scores2 2 row(s) in 0.0170 seconds => ["scores", "scores2"] hbase(main):013:0> enable 'scores2' 0 row(s) in 0.0130 seconds hbase(main):014:0> put'scores2','rk001','course:soft','database' 0 row(s) in 0.1900 seconds hbase(main):015:0>
(1) put update record
Update the previous data to english
hbase(main):015:0> put 'scores2','rk001','course:soft','english' 0 row(s) in 0.0160 seconds
(2) Add data in batches
Write a file one.txt, the content is as follows:
put 'scores2','rk002','course:soft','database' put 'scores2','rk002','course:jg','math' put 'scores2','rk003','course:soft','c' put 'scores2','rk004','course:soft','java'
Execute the command hbase shell one.txt on the linux side, the execution result:
[root@master usr]# mkdir egdata [root@master usr]# cd egdata/ [root@master egdata]# vi one.txt [root@master egdata]# hbase shell one.txt SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/usr/hadoop/hbase-1.6.0/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/usr/hadoop/hadoop-2.10.0/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] 0 row(s) in 0.4800 seconds 0 row(s) in 0.0120 seconds 0 row(s) in 0.0100 seconds 0 row(s) in 0.0090 seconds HBase Shell Use "help" to get list of supported commands. Use "exit" to quit this interactive shell. Version 1.6.0, r5ec5a5b115ee36fb28903667c008218abd21b3f5, Fri Feb 14 12:00:03 PST 2020 hbase(main):001:0> list TABLE scores scores2 2 row(s) in 0.0890 seconds => ["scores", "scores2"] hbase(main):002:0> decribe scores2 NameError: undefined local variable or method `scores2' for #<Object:0x31a136a6> hbase(main):003:0> describe 'scores2' Table scores2 is ENABLED scores2 COLUMN FAMILIES DESCRIPTION {NAME => 'course', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS = > 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => ' 0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'} 1 row(s) in 0.0330 seconds hbase(main):004:0> scan 'scores2' ROW COLUMN+CELL rk001 column=course:soft, timestamp=1607221272704, value=english rk002 column=course:jg, timestamp=1607221711379, value=math rk002 column=course:soft, timestamp=1607221711165, value=database rk003 column=course:soft, timestamp=1607221711394, value=c rk004 column=course:soft, timestamp=1607221711402, value=java 4 row(s) in 0.0290 seconds hbase(main):005:0>
2.get
Query data. Syntax: get<table>,<rowkey>,[<family: column>, ........]
#Query the value of the course:soft column of the rk001 row in scores2 hbase(main):005:0> get'scores2','rk001','course:soft' COLUMN CELL course:soft timestamp=1607221272704, value=english 1 row (s) in 0.1590 seconds #Query the value of the course column family in the rk001 row of scores2 hbase(main):006:0> get'scores2','rk001','course' COLUMN CELL course:soft timestamp=1607221272704, value=english 1 row(s) in 0.0130 seconds #Query the value of the rk001 row in scores2 hbase(main):007:0> get 'scores2','rk001' COLUMN CELL course:soft timestamp=1607221272704, value=english 1 row(s) in 0.0120 seconds #Query the value of the course column family in row rk002 in scores2, the version number is 3 hbase(main):008:0> get'scores2', 'rk002',{COLUMN=>'course',VERSIONS=>3} COLUMN CELL course:jg timestamp=1607221711379, value=math course:soft timestamp=1607221711165, value=database 1 row(s) in 0.0710 seconds #The following This way you can get the previously saved historical data. #For example, query the value of the course column family in row rk002 in scores2, the version number is 3, and the value between the timestamps 1607221711300 and 1607221711170. hbase(main):011:0> get'scores2','rk002',{COLUMN=>'course:soft',TIMERANGE=>[1607221711300,1607221711170],VERSIONS=>3}
The following is advanced usage:
(1)ValueFilter
Indicates to filter the value.
#Find the data whose value in the rk001 row in scores2 is database: hbase(main):012:0> get'scores2','rk001',{FILTER=>"ValueFilter(=,'binary:database')"} COLUMN CELL course:soft timestamp=1607221106518, value=database 1 row(s) in 0.5400 seconds hbase(main):013:0> #Find the data containing a in the rk002 row in scores2 : hbase(main):013:0> get ' scores2','rk002',{FILTER=>"ValueFilter(=,'substring:a')"} COLUMN CELL course:jg timestamp=1607221711379, value=math course:soft timestamp=1607221711165, value=database 1 row(s) in 0.0310 seconds hbase(main):014:0>
(2) QualifierFilter
Indicates to filter the column.
#Find the data whose column name is db in row rk001 in scores2: hbase(main):018:0> get'scores2','rk001', {FILTER => "QualifierFilter(=,'binary:db')"} COLUMN CELL 0 row(s) in 0.0390 seconds #Find the data that contains db in the column name of row rk001 in scores2: hbase(main):019:0> get'scores2','rk001', {FILTER => "QualifierFilter(= ,'substring:db')"} COLUMN CELL 0 row(s) in 0.0170 seconds
3.scan
Scan the table. Syntax: scan<table>,{COLUMN=>[<family: column>, ........], LIMIT=>num}
In addition, advanced functions such as STARTROW, TIMERANGE and FILTER can be added.
#scores2表 #扫描整个表: hbase(main):021:0> scan 'scores2' ROW COLUMN+CELL rk001 column=course:soft, timestamp=1607221272704, value=english rk002 column=course:jg, timestamp=1607221711379, value=math rk002 column=course:soft, timestamp=1607221711165, value=database rk003 column=course:soft, timestamp=1607221711394, value=c rk004 column=course:soft, timestamp=1607221711402, value=java 4 row(s) in 0.0160 seconds hbase(main):022:0> #扫描整个表列族为course的数据: hbase(main):022:0> scan 'scores2',{COLUMNS=>'course'} ROW COLUMN+CELL rk001 column=course:soft, timestamp=1607221272704, value=english rk002 column=course:jg, timestamp=1607221711379, value=math rk002 column=course:soft, timestamp=1607221711165, value=database rk003 column=course:soft, timestamp=1607221711394, value=c rk004 column=course:soft, timestamp=1607221711402, value=java 4 row(s) in 0.0310 seconds hbase(main):023:0> #Scan the entire table column family as coursed data, and set the scan's coming and ending row keys at the same time: hbase(main):027:0> scan'scores2',{COLUMNS=>'course',STARTROW=>'rk001' , ENDROW=>'rk003'} ROW COLUMN+CELL rk001 column=course:soft, timestamp=1607221272704, value=english rk002 column=course:jg, timestamp=1607221711379, value=math rk002 column=course:soft, timestamp=1607221711165 , value=database 2 row(s) in 0.0150 seconds #Scan the entire table column family as course data, and set the version to 3: hbase(main):026:0> scan'scores2',{COLUMNS=>'course' ,VERSIONS=>3} ROW COLUMN+CELL rk001 column=course:soft, timestamp=1607221272704, value=english rk002 column=course:jg, timestamp=1607221711379, value=math rk002 column=course:soft, timestamp=1607221711165, value=database rk003 column=course:soft, timestamp=1607221711394, value=c rk004 column=course:soft, timestamp=1607221711402, value=java 4 row(s) in 0.0470 seconds hbase(main):027:0>
4.delete
delete data. Syntax: delete<table>,<rowkey>,<family: column>,<timestamp>
(1) Delete a value in the row
Syntax: delete<table>,<rowkey>,<family: column>,<timestamp>, column name must be specified.
#Delete the course:soft column data in the rk001 row in scores2 hbase(main):028:0> delete'scores2','rk001','course:soft' 0 row(s) in 0.0570 seconds
<!--All versions of data in rk001 row f1: coll column will be deleted-->
(2) Delete the line
You can delete the entire row of data without specifying the column name.
#Delete the data in row rk002 in scores2: hbase(main):002:0> delete'scores2','rk002'
5.deleteall
Delete the row. Syntax: deleteall<table>,<rowkey>,<family: column>,<timestamp>
#Delete all data in row rk004 of table scores: hbase(main):003:0> deleteall'scores2','rk004' 0 row(s) in 0.0330 seconds
6.count
How many rows of data are in the query table. Syntax: count<table>
#Statistics of all data in scores2 hbase(main):005:0> count'scores2' 1 row(s) in 0.0210 seconds => 1
7.truncate
Empty the table. Syntax: truncate<table>
#清空表scores2 hbase(main):006:0> truncate 'scores2' Truncating 'scores2' table (it may take a while): - Disabling table... - Truncating table... 0 row(s) in 4.2990 seconds hbase(main):007:0> list TABLE scores scores2 2 row(s) in 0.1550 seconds => ["scores", "scores2"] hbase(main):008:0> scan 'scores2' ROW COLUMN+CELL 0 row(s) in 0.3380 seconds hbase(main):009:0>
Five, importtsv of hbase data migration
The hbase data comes from log files or RDBMS, and the data is migrated to the HBASE table. Common methods include using the HBASE Put API, using the HBase bulk loading tool, and customizing the implementation of MapReduce.
[root@master egdata]# vi 1.tsv [root@master egdata]# cat 1.tsv 1001 zhangsan 16 1002 lisi 18 1003 wangwu 19 1004 zhaoliu 20 1005 zhengqi 19 [root@master egdata]# hdfs dfs -mkdir -p /hbase/data1 [root@master egdata]# hdfs dfs -put 1.tsv /hbase/data1 [root@master egdata]# hbase shell SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/usr/hadoop/hbase-1.6.0/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/usr/hadoop/hadoop-2.10.0/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] HBase Shell Use "help" to get list of supported commands. Use "exit" to quit this interactive shell. Version 1.6.0, r5ec5a5b115ee36fb28903667c008218abd21b3f5, Fri Feb 14 12:00:03 PST 2020 hbase(main):001:0> create 'student2','info' 0 row(s) in 1.6560 seconds => Hbase::Table - student2 hbase(main):002:0> quit [root@master egdata]# yarn jar /usr/hadoop/hbase-1.6.0/lib/hbase-server-1.6.0.jar importtsv -Dimporttsv.separator=\t-Dimporttsv.columns=HBASE_ROW_KEY,info:name student2 /hbase/data1/1.tsv Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/filter/Filter at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at java.lang.Class.privateGetMethodRecursive(Class.java:3048) at java.lang.Class.getMethod0(Class.java:3018) at java.lang.Class.getMethod(Class.java:1784) at org.apache.hadoop.util.ProgramDriver$ProgramDescription.<init>(ProgramDriver.java:59) at org.apache.hadoop.util.ProgramDriver.addClass(ProgramDriver.java:103) at org.apache.hadoop.hbase.mapreduce.Driver.main(Driver.java:42) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.hadoop.util.RunJar.run(RunJar.java:244) at org.apache.hadoop.util.RunJar.main(RunJar.java:158) Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.filter.Filter at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ... 14 more [root@master egdata]#
......