Using HBase from Scratch
HBase is a column-based distributed storage system that features high reliability, performance, and scalability. This section describes how to use HBase from scratch, including how to update the client on the Master node in the cluster, create a table using the client, insert data in the table, modify the table, read data from the table, delete table data, and delete the table.
Background
Suppose a user develops an application to manage users who use service A in an enterprise. The procedure of operating service A on the HBase client is as follows:
- Create the user_info table.
- Add users' educational backgrounds and titles to the table.
- Query user names and addresses by user ID.
- Query information by user name.
- Deregister users and delete user data from the user information table.
- Delete the user information table after service A ends.
ID |
Name |
Gender |
Age |
Address |
---|---|---|---|---|
12005000201 |
A |
Male |
19 |
City A |
12005000202 |
B |
Female |
23 |
City B |
12005000203 |
C |
Male |
26 |
City C |
12005000204 |
D |
Male |
18 |
City D |
12005000205 |
E |
Female |
21 |
City E |
12005000206 |
F |
Male |
32 |
City F |
12005000207 |
G |
Female |
29 |
City G |
12005000208 |
H |
Female |
30 |
City H |
12005000209 |
I |
Male |
26 |
City I |
12005000210 |
J |
Male |
25 |
City J |
Prerequisites
The client has been installed in a directory, for example, /opt/client. The client directory in the following operations is only an example. Change it to the actual installation directory. Before using the client, download and update the client configuration file, and ensure that the active management node of Manager is available.
Procedure
- Use the client on the active management node.
- Log in to the node where the client is installed as the client installation user and run the following command to switch to the client directory:
- Run the following command to configure environment variables:
- If Kerberos authentication has been enabled for the current cluster, run the following command to authenticate the current user. The current user must have the permission to create HBase tables. If Kerberos authentication is disabled for the current cluster, skip this step.
For example, kinit hbaseuser.
- Run the following HBase client command:
- Run the following commands on the HBase client to implement service A.
- Create the user_info user information table according to Table 1 and add data to it.
create 'user_info',{NAME => 'i'}
For example, to add information about the user whose ID is 12005000201, run the following commands:
put 'user_info','12005000201','i:name','A'
put 'user_info','12005000201','i:gender','Male'
put 'user_info','12005000201','i:age','19'
put 'user_info','12005000201','i:address','City A'
- Add users' educational backgrounds and titles to the user_info table.
For example, to add educational background and title information about user 12005000201, run the following commands:
put 'user_info','12005000201','i:degree','master'
put 'user_info','12005000201','i:pose','manager'
- Query user names and addresses by user ID.
For example, to query the name and address of user 12005000201, run the following command:
scan'user_info',{STARTROW=>'12005000201',STOPROW=>'12005000201',COLUMNS=>['i:name','i:address']}
- Query information by user name.
For example, to query information about user A, run the following command:
scan'user_info',{FILTER=>"SingleColumnValueFilter('i','name',=,'binary:A')"}
- Delete user data from the user information table.
All user data needs to be deleted. For example, to delete data of user 12005000201, run the following commands:
- Delete the user information table.
drop 'user_info'
- Create the user_info user information table according to Table 1 and add data to it.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot