Help Center/ MapReduce Service/ Getting Started/ Using HBase from Scratch
Updated on 2022-09-14 GMT+08:00

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

  1. Purchase an MRS cluster.

    1. Log in to the Huawei Cloud management console.
    2. Choose Analytics > MapReduce Service to go to the MRS console.

    3. Choose Clusters > Active Clusters and click Buy Cluster. On the displayed page, click Custom Config.

  2. 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.

  3. 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

  4. Configure advanced options.

    1. 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
    2. Click Buy Now. The page is displayed showing that the task has been submitted.
    3. Click Back to Cluster List. You can view the status of the cluster on the Active Clusters page.
    4. 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.

Installing the HBase Client

  1. Choose Clusters > Active Clusters and click mrs_demo. The cluster information page is displayed.
  2. 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.

  3. 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.

  4. Log in to the active node as the root user.
  5. 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

  6. 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.

  7. 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

  1. Log in to the master node using VNC.

    1. 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.

    2. 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.

  2. Run the following command to go to the client directory:

    cd /opt/hbaseclient

  3. 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

  4. Run the following command to access the HBase shell CLI:

    hbase shell

  5. Run the HBase client command to create the user_info table.

    1. 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'

    2. 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'

    3. 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 
    4. 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 
    5. Delete user data from the user information table.

      delete'user_info','12005000201','i'

    6. Delete the user information table.

      disable 'user_info'

      drop 'user_info'