Getting Started with HBase
HBase is a column-based distributed storage system that features high reliability, performance, and scalability. This section describes how to use HBase from scratch. For example, how to run the HBase shell command to create tables, insert data into tables, modify tables, read and delete table data, and delete tables.
Background Information
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 | Shenzhen, Guangdong |
| 12005000202 | B | Female | 23 | Shijiazhuang, Hebei |
| 12005000203 | C | Male | 26 | Ningbo, Zhejiang |
| 12005000204 | D | Male | 18 | Xiangyang, Hubei |
| 12005000205 | E | Female | 21 | Shangrao, Jiangxi |
| 12005000206 | F | Male | 32 | Zhuzhou, Hunan |
| 12005000207 | G | Female | 29 | Nanyang, Henan |
| 12005000208 | H | Female | 30 | Kaixian, Chongqing |
| 12005000209 | I | Male | 26 | Weinan, Shaanxi |
| 12005000210 | J | Male | 25 | Dalian, Liaoning |
Procedure
- Create a cluster named cloudtable-demo.
For details, see Creating a Cluster Quickly.
- Prepare a Linux ECS.
Assume that the ECS name is ecs_ 20170916. For details, see Preparing an ECS.
- Install a client and start the shell to access the CloudTable cluster.
For details about how to use the HBase shell to access the cluster, see Using HBase Shell to Access a Cluster.
- Run the following commands on the HBase client to implement service A.
- Create the user_info user information table and populate it with related data according to Table 1.
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','Shenzhen, Guangdong'
- 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 command:
delete 'user_info','12005000201','i'
- Run the following command to delete the user information table.
disable 'user_info';drop 'user_info'
- Create the user_info user information table and populate it with related data according to Table 1.
- Delete the cluster.
For details, see Deleting a Cluster.
Last Article: Creating a Cluster Quickly
Next Article: Permissions Management
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.