Using HBase from Scratch
MapReduce Service (MRS) provides enterprise-level big data clusters on the cloud. Tenants can fully control the clusters and run big data components such as Hadoop, Spark, HBase, and Kafka in the clusters.
This section uses a cluster with Kerberos authentication disabled as an example to describe how to log in to the HBase client, create a table, insert data into the table, and modify the table.
Preparing an MRS Cluster
- Purchase an MRS cluster.
- Log in to the Huawei Cloud management console.
- Choose Analytics > MapReduce Service to go to the MRS console.
- Choose Clusters > Active Clusters and click Buy Cluster. On the displayed page, click Custom Config.
- Set the following parameters and click Next.
- Region: Select a region as required.
- Cluster Name: Enter mrs_demo or specify a name according to naming rules.
- Cluster Version: Select MRS 3.1.0.
- Cluster Type: Select Analysis Cluster and select HBase.
- On the Configure Hardware page, set the parameters by referring to Table 1, and click Next.
Table 1 MRS cluster hardware configuration Parameter
Example Value
Billing Mode
Pay-per-use
AZ
AZ2
VPC
Retain the default value. You can also click View VPC to create a VPC.
EIP
You can select an existing EIP from the drop-down list. If no EIP is available in the drop-down list, click Manage EIP to access the EIPs page to create one.
Enterprise Project
default
Figure 1 Hardware configurations
- Configure advanced options.
- On the Set Advanced Options page, set parameters by referring to Table 2.
Table 2 MRS cluster advanced options Parameter
Example Value
Kerberos Authentication
Disabled
Password
Test@!123456
Confirm Password
Test@!123456
Login Mode
Password
Password
Test@#123456
Confirm Password
Test@#123456
Secure Communications
Select Enable.
Figure 2 Advanced options
- Click Buy Now. The page is displayed showing that the task has been submitted.
- Click Back to Cluster List. You can view the status of the cluster on the Active Clusters page.
- Wait for the cluster creation to complete. The initial status of the cluster is Starting. After the cluster has been created successfully, the cluster status becomes Running.
- On the Set Advanced Options page, set parameters by referring to Table 2.
Installing the HBase Client
- Choose Clusters > Active Clusters and click mrs_demo. The cluster information page is displayed.
- Click Access Manager next to MRS Manager. On the displayed page, configure the EIP information and click OK. Enter the username and password to access FusionInsight Manager.
- Choose Cluster > Services > HBase, and select Download Client from the More drop-down list. Select Complete Client, the corresponding platform type, and Save to path, and click OK.
- Log in to the active node as the root user.
- Go to the directory where the installation package is stored and run the following commands to decompress and verify the installation package, and decompress the obtained installation file:
cd /tmp/FusionInsight-Client
tar -xvf FusionInsight_Cluster_1_HBase_Client.tar
sha256sum -c FusionInsight_Cluster_1_HBase_ClientConfig.tar.sha256
tar -xvf FusionInsight_Cluster_1_HBase_ClientConfig.tar
- Go to the directory where the installation package is stored, and run the following command to install the client to a specified directory (an absolute path), for example, /opt/hbaseclient:
cd /tmp/FusionInsight-Client/FusionInsight_Cluster_1_HBase_ClientConfig
Run the ./install.sh /opt/hbaseclient command and wait until the client installation is complete.
- Check whether the client is successfully installed.
cd /opt/hbaseclient
source bigdata_env
hbase shell
If the command is successfully executed, the HBase client is successfully installed.
Creating a Table Using the HBase Client
- Log in to the master node using VNC.
- On the MRS console, choose Clusters > Active Clusters, and select mrs_demo from the cluster list. Click Nodes, and click the node whose name contains master1 to access its ECS details page.
- Click Remote Login in the upper right corner of the page to log in to the master node as user root. The password is the one set when the cluster is purchased.
- On the MRS console, choose Clusters > Active Clusters, and select mrs_demo from the cluster list. Click Nodes, and click the node whose name contains master1 to access its ECS details page.
- Run the following command to go to the client directory:
cd /opt/hbaseclient
- Run the following command to configure environment variables:
source bigdata_env
If Kerberos authentication is enabled for the cluster, run the following command to authenticate the current user. The current user must have the permission to create HBase tables.
For example:
kinit hbaseuser
- Run the following command to access the HBase shell CLI:
hbase shell
- Run the HBase client command to create the user_info table.
- Create the user_info table and add related data.
create 'user_info',{NAME => 'i'}
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 professional titles to the user_info table.
put 'user_info','12005000201','i:degree','master'
put 'user_info','12005000201','i:pose','manager'
- Query user names and addresses by user ID.
scan'user_info',{STARTROW=>'12005000201',STOPROW=>'12005000201',COLUMNS=>['i:name','i:address']}
ROW COLUMN+CELL 12005000201 column=i:address, timestamp=2021-10-30T10:21:42.196, value=City A 12005000201 column=i:name, timestamp=2021-10-30T10:21:18.594, value=A 1 row(s) Took 0.0996 seconds
- Query information by user name.
scan'user_info',{FILTER=>"SingleColumnValueFilter('i','name',=,'binary:A')"}
ROW COLUMN+CELL 12005000201 column=i:address, timestamp=2021-10-30T10:21:42.196, value=City A 12005000201 column=i:age, timestamp=2021-10-30T10:21:30.777, value=19 12005000201 column=i:degree, timestamp=2021-10-30T10:21:53.284, value=master 12005000201 column=i:gender, timestamp=2021-10-30T10:21:18.711, value=Male 12005000201 column=i:name, timestamp=2021-10-30T10:21:18.594, value=A 12005000201 column=i:pose, timestamp=2021-10-30T10:22:07.152, value=manager 1 row(s) Took 0.2158 seconds
- Delete user data from the user information table.
- Delete the user information table.
drop 'user_info'
- Create the user_info table and add related data.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.