Updated on 2022-06-01 GMT+08:00

Commissioning HBase Python Sample Code

Only MRS 1.9.x and earlier versions support this function.

HBase allows users to use the ThriftServer2 service to access HBase using Python. The Python sample program can run only in the Linux environment. To commission the HBase Python sample program, an ECS that can communicate with the cluster environment must be available. For details, see Preparing Development and Operating Environments. In addition, the Python environment must be installed. For details about how to download the installation package, visit https://www.python.org/. The following describes how to run the sample on the master node of the cluster.

  1. Set up the sample running environment.

    Obtain the Python dependency for running the sample program, search for and download the decorator, gssapi, kerberos, krbcontext, pure-sasl, and thrift packages from https://pypi.org/. (If Kerberos authentication is not enabled for a common cluster, only the thrift package needs to be installed.) Upload the package to the master node. For example, create the /opt/hbase-examples/python directory and upload it to the directory.
    decorator-4.3.2.tar.gz
    gssapi-1.5.1.tar.gz
    kerberos-1.3.0.tar.gz
    krbcontext-0.8.tar.gz
    pure-sasl-0.6.1.tar.gz
    thrift-0.11.0.tar.gz

  2. Upload the hbase-python-example folder in the sample project to the /opt/hbase-examples directory on the master node of the cluster, and upload the authentication file obtained from Preparing a Development User to the directory.
  3. Create the hbasepython.properties file in /opt/hbase-examples and modify the configuration as follows:

    clientHome=/opt/client
    exampleCodeDir=/opt/hbase-examples/hbase-python-example
    pythonLib=/opt/hbase-examples/python
    keyTabFile=/opt/hbase-examples/user.keytab
    userName=hbaseuser
    thriftIp=xxx.xxx.xx.xxx
    • clientHome: path of the cluster client
    • exampleCodeDir: path of the hbase-python-example file
    • pythonLib: path for storing python dependency files in 1
    • keyTabFile: user authentication credential user.keytab obtained from Preparing a Development User
    • userName: developer username in Preparing a Development User
    • thriftIp: IP address of the node where the thriftserver2 is installed

  4. Run the following command to create an HBase table named example:

    source /opt/client/bigdata_env

    kinit Username

    echo "create 'example','family1','family2'" | hbase shell

  5. Install the Python environment and run the program.

    cd /opt/hbase-examples/hbase-python-example
    sh initEnvAndRunDemo.sh /opt/hbase-examples/hbasepython.properties
    • Format the initEnvAndRunDemo.sh script before running the program. For example, run the following command: dos2unix /opt/hbase-examples/hbasepython.properties
    • Before executing the script, ensure that the example table contains the column family 'family1''family2' and already exists in the cluster.
    • To run the program again, go to the /opt/hbase-examples/hbase-python-example directory and run the following command to execute the program commissioning example: python DemoClient.py

  6. After the HBase Python application is run, you can check the application running status by viewing the running result.

    Figure 1 Application running success