Updated on 2024-10-09 GMT+08:00

Using the HBase Client

Scenario

This section describes how to use the HBase client in an O&M scenario or a service scenario.

Video Tutorial

This tutorial demonstrates how to create a table, insert data into it, and modify the table data by logging in to the HBase client after setting up an MRS cluster.

The UI may vary depending on the version. This tutorial is for reference only.

Prerequisites

  • The client has been installed. For example, the installation directory is /opt/hadoopclient. The client directory in the following operations is only an example. Change it to the actual installation directory.
  • Service component users have been created by the MRS cluster administrator.

    A machine-machine user needs to download the keytab file and a human-machine user needs to change the password upon the first login.

  • If a non-root user uses the HBase client, ensure that the owner of the HBase client directory is this user. Otherwise, run the following command to change the owner.

    chown user:group -R Client installation directory/HBase

Using the HBase Client

  1. Install the client. For details, see Installing a Client.
  2. Log in to the node where the client is installed as the client installation user.
  3. Run the following command to go to the client directory:

    cd /opt/hadoopclient

  4. Run the following command to configure environment variables:

    source bigdata_env

  5. 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. For details about how to configure a role with the corresponding permissions, seeManaging Roles. To bind a role to a user, see Creating a User. If Kerberos authentication is disabled for the current cluster, skip this step.

    kinit Component service user

    For example, kinit hbaseuser.

  6. Run the following HBase client command:

    hbase shell

Common HBase client commands

The following table lists common HBase client commands. For more commands, see http://hbase.apache.org/2.2/book.html.
Table 1 HBase client commands

Command

Description

create

Used to create a table, for example, create 'test', 'f1', 'f2', 'f3'.

disable

Used to disable a specified table, for example, disable 'test'.

enable

Used to enable a specified table, for example, enable 'test'.

alter

Used to alter the table structure. You can run the alter command to add, modify, or delete column family information and table-related parameter values, for example, alter 'test', {NAME => 'f3', METHOD => 'delete'}.

describe

Used to obtain the table description, for example, describe 'test'.

drop

Used to delete a specified table, for example, drop 'test'. Before deleting a table, you must stop it.

put

Used to write the value of a specified cell, for example, put 'test','r1','f1:c1','myvalue1'. The cell location is unique and determined by the table, row, and column.

get

Used to get the value of a row or the value of a specified cell in a row, for example, get 'test','r1'.

scan

Used to query table data, for example, scan 'test'. The table name and scanner must be specified in the command.