Updated on 2024-08-16 GMT+08:00

Commissioning the HBase Phoenix Sample Program

HBase allows users to access HBase services by invoking JDBC interfaces through Phoenix. Commission the HBase Phoenix sample program. By default, the HBase has been connected to the Phoenix service in the cluster. For details about the connection procedure, see Configuring Phoenix for HBase.

Running and Commissioning Applications on Windows

  1. For details about how to set up the Windows development environment and modify the public configuration of the sample program, see 1 to 3.
  2. Modify the sample project.

    1. Modify the jaas.conf file in the src/main/resources directory of the sample project, where the keyTab and principal parameter correspond to the path for storing user authentication credentials and the username, respectively. Skip this step for a cluster with Kerberos authentication disabled.
    Client {
      com.sun.security.auth.module.Krb5LoginModule required
      useKeyTab=true
      keyTab="D:\\sample_project\\src\\hbase-examples\\hbase-java-examples\\src\\main\\resources\\user.keytab"
      principal="hbaseuser"
      useTicketCache=false
      storeKey=true
      debug=true;
    };
    2. Modify the hbaseclient.properties file in the src/main/resources directory of the sample project. user.name, userKeytabName, and krb5ConfName indicate the username created in and the file names obtained in Preparing an HBase Application Development User. Skip this step for a cluster with Kerberos authentication disabled.
    user.name=hbaseuser
    userKeytabName=user.keytab
    krb5ConfName=krb5.conf
    #for phoenix
    #confiugration for security cluster.
    jaasConfName=jaas.conf

  3. In a development environment (for example, Eclipse), right-click PhoenixExample and choose Run > PhoenixExample.main() to run the application project.

    If error message "Message stream modified (41)" is displayed, the JDK version may be incorrect. Change the JDK version in the sample code to a version earlier than 8u_242 or delete the renew_lifetime = 0m configuration item from the krb5.conf configuration file.

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

    If the following information is displayed, the application runs successfully.

    2020-03-13 14:54:13,369 INFO  [main] client.HBaseAdmin: Operation: CREATE, Table Name: default:TEST, procId: 60 completed
    2020-03-13 14:54:14,269 INFO  [main] examples.PhoenixExample: 1
    2020-03-13 14:54:14,270 INFO  [main] examples.PhoenixExample: John
    2020-03-13 14:54:14,270 INFO  [main] examples.PhoenixExample: 100000
    2020-03-13 14:54:14,271 INFO  [main] examples.PhoenixExample: 1980-01-01
    2020-03-13 14:54:14,464 INFO  [main] client.HBaseAdmin: Started disable of TEST
    2020-03-13 14:54:15,199 INFO  [main] client.HBaseAdmin: Operation: DISABLE, Table Name: default:TEST, procId: 62 completed
    2020-03-13 14:54:15,521 INFO  [main] client.HBaseAdmin: Operation: DELETE, Table Name: default:TEST, procId: 64 completed

Commissioning Phoenix on Linux

To commission Phoenix in a Linux environment, an ECS that can communicate with the cluster network must be available. For details, see Preparing a Local Application Development Environment.

  1. Modify the sample. Change the value of enablePhoenix in the sample code TestMain to true to enable the Phoenix sample program interface.

    /**
     * Phoenix Example
     * if you would like to operate hbase by SQL, please enable it,
     * and you can refrence the url ("https://support.huaweicloud.com/devg-mrs/mrs_06_0041.html").
     * step:
     * 1.login
     * 2.operate hbase by phoenix.
     */
    boolean enablePhoenix = false;
    if (enablePhoenix) {
      PhoenixExample phoenixExample;
      try {
        phoenixExample = new PhoenixExample(conf);
        phoenixExample.testSQL();
      } catch (Exception e) {
        LOG.error("Failed to run Phoenix Example, because ", e);
      }
    }

  2. Run the mvn package command to generate a JAR file, for example, hbase-examples-mrs-2.0.jar. Obtain the JAR file from the target directory in the project directory, and upload it to the /opt/client/Hbase/hbase/lib directory.
  3. Run the JAR file.

    1. Before running the JAR file on the Linux client, run the following command to switch to the client directory as the user that is used for installation:

      cd $BIGDATA_CLIENT_HOME/HBase/hbase

      $BIGDATA_CLIENT_HOME indicates the client installation directory.

    2. Run the following command:

      source $BIGDATA_CLIENT_HOME/bigdata_env

    3. Copy the phoenix-hbase, phoenix-core, and htrace-core-3.1.0-incubating.jar packages obtained after decompressing HBase Phoenix APIs to the /opt/client/HBase/hbase/lib directory.
    4. Copy the JAR package generated in 2 and the krb5.conf and user.keytab files obtained in Preparing an HBase Application Development User to the HBase/hbase/conf directory in the client running environment, for example, /opt/client/HBase/hbase/conf. Create the hbaseclient.properties file in the /opt/client/HBase/hbase/conf directory. In the file, user.name corresponds to the new user hbaseuser, and the values of userKeytabName and krb5ConfName correspond to the authentication-related file names obtained in Preparing an HBase Application Development User (skip this step if Kerberos authentication is not enabled for the cluster).
      user.name=hbaseuser
      userKeytabName=user.keytab
      krb5ConfName=krb5.conf

  4. Execute the JAR file program.

    hbase com.huawei.bigdata.hbase.examples.TestMain /opt/client/HBase/hbase/conf

    com.huawei.bigdata.hbase.examples.TestMain is used as an example. Use the actual code instead.

    /opt/client/HBase/hbase/conf corresponds to the path of files such as user.keytab and krb5.conf mentioned above.

    If error message "Message stream modified (41)" is displayed, the JDK version may be incorrect. Change the JDK version in the sample code to a version earlier than 8u_242 or delete the renew_lifetime = 0m configuration item from the krb5.conf configuration file.

  5. After the Phoenix application is run, you can check the application running status by viewing the running result.

    2020-03-14 16:20:40,192 INFO  [main] client.HBaseAdmin: Operation: CREATE, Table Name: default:TEST, procId: 923 completed
    2020-03-14 16:20:40,806 INFO  [main] examples.PhoenixExample: 1
    2020-03-14 16:20:40,807 INFO  [main] examples.PhoenixExample: John
    2020-03-14 16:20:40,807 INFO  [main] examples.PhoenixExample: 100000
    2020-03-14 16:20:40,807 INFO  [main] examples.PhoenixExample: 1980-01-01
    2020-03-14 16:20:40,830 INFO  [main] client.HBaseAdmin: Started disable of TEST
    2020-03-14 16:20:41,574 INFO  [main] client.HBaseAdmin: Operation: DISABLE, Table Name: default:TEST, procId: 925 completed
    2020-03-14 16:20:41,831 INFO  [main] client.HBaseAdmin: Operation: DELETE, Table Name: default:TEST, procId: 927 completed