Commissioning the HBase Application in the Linux Environment
Scenario
In a Linux environment where an HBase client is installed, you can upload the JAR package to the prepared Linux running environment and then run an application after the code development is complete.
Prerequisites
- If the client is installed:
- You have installed the HBase client.
- If the host where the client is installed is not a node in the cluster, set the mapping between the host name and the IP address in the hosts file on the node where the client locates. The host name and IP address must be in one-to-one mapping.
- If the client is not installed:
- A JDK has been installed in the Linux environment. The version of the JDK must be consistent with that of the JDK used by the JAR package exported by IntelliJ IDEA.
- If the Linux host is not a node in the cluster, set the mapping between the host name and the IP address in the hosts file on the node. The host name and IP address must be in one-to-one mapping.
Compile and Run the Program when the Client is Installed
- Export a JAR package.
You can build a JAR file in either of the following ways:
- Method 1:
Choose Maven > Sample projectname > Lifecycle > clean, double click clean to run the clean command of Maven.
Choose Maven > Sample project name > Lifecycle > install, double click install to run the install command of Maven.Figure 1 Maven tools: clean and install
- Method 2: Go to the directory where the pom.xml file is located in the Terminal window in the lower part of the IDEA, and run the mvn clean install command to compile the pom.xml file. Figure 2 Enter mvn clean compile in the IDEA Terminal text box.
After the compilation is completed, the message "BUILD SUCCESS" is displayed, the target directory is generated, and the generated JAR file is stored in the target directory.
- Method 1:
- Export the JAR file on which the sample project depends.
Access the directory where the pom.xml file is located in the Terminal window in the lower part of IDEA or by using other command line tools.
Run the command mvn dependency:copy-dependencies -DoutputDirectory=lib.
The lib folder is generated in the directory where the pom.xml file is located. The lib folder contains the JAR files on which the sample project depends.
- Run the JAR package.
- Before running the JAR package on the Linux client, run the following command to go to the client directory:
$BIGDATA_CLIENT_HOME is the installation directory of the HBase client.
- Then run the following command:
After the multi-instance function is enabled, run the following command to switch to the client of the specified service instance before performing application development for the HBase service instance.
For example, for HBase2, run the source /opt/client/HBase2/component_env command.
- Upload the JAR file (non-dependent JAR file) of the sample project generated in the application development environment to the Client installation directory/HBase/hbase/lib directory in the client running environment. In addition, you need to copy the configuration file and authentication file obtained in section Preparing the Configuration Files of the Running Environment to the Client installation directory/HBase/hbase/conf directory.
- Go to the $BIGDATA_CLIENT_HOME/HBase/hbase directory and run the following command to run the JAR package. The task is complete.
hbase com.huawei.bigdata.hbase.examples.TestMain
In the preceding command, hbase com.huawei.bigdata.hbase.examples.TestMain is used as an example.
- Before running the JAR package on the Linux client, run the following command to go to the client directory:
Compile and Run the Program when the Client is not Installed
- Export a JAR package.
You can build a JAR file in either of the following ways:
- Method 1:
Choose Maven > Sample projectname > Lifecycle > clean, double click clean to run the clean command of Maven.
Choose Maven > Sample project name > Lifecycle > install, double click install to run the install command of Maven.Figure 3 Maven tools: clean and install
- Method 2: Go to the directory where the pom.xml file is located in the Terminal window in the lower part of the IDEA, and run the mvn clean install command to compile the pom.xml file. Figure 4 Enter mvn clean compile in the IDEA Terminal text box.
After the compilation is completed, the message "BUILD SUCCESS" is displayed, the target directory is generated, and the generated JAR file is stored in the target directory.
- Method 1:
- Prepare for the required JAR packages and configuration files.
- In the Linux environment, create a directory, for example, /opt/test, and create subdirectories lib and conf. Export the JAR package that the sample project depends on. For details about how to export the JAR package, see 3. Upload this JAR file and that exported in 1 to the lib directory on the Linux server. Upload the conf configuration file and authentication file in the sample project to the conf directory on Linux.
- In /opt/test, create therun.sh script, modify the following content, and save the file:
#!/bin/sh BASEDIR=`cd $(dirname $0);pwd` cd ${BASEDIR} for file in ${BASEDIR}/lib/*.jar do i_cp=$i_cp:$file echo "$file" done for file in ${BASEDIR}/conf/* do i_cp=$i_cp:$file done java -cp .${i_cp} com.huawei.bigdata.hbase.examples.TestMainIn the preceding content, com.huawei.bigdata.hbase.examples.TestMain is used as an example.
- Go to /opt/test and run the following commands to run the JAR packages:
sh run.sh
Viewing Linux Commissioning Results
After an HBase application is run, you can check the running result through one of the following methods:
- Viewing the command output.
- Viewing HBase logs.
- Logging in to the HBase WebUI, see More Information > External Interfaces > WebUI.
- Using HBase Shell command, see More Information > External Interfaces > Shell.
2280 [main] INFOcom.huawei.hadoop.hbase.example.HBaseSample- Entering testCreateTable. 3091 [main] WARNcom.huawei.hadoop.hbase.example.HBaseSample- table already exists 3091 [main] INFOcom.huawei.hadoop.hbase.example.HBaseSample- Exiting testCreateTable. 3091 [main] INFOcom.huawei.hadoop.hbase.example.HBaseSample- Entering testPut. 3264 [main] INFOcom.huawei.hadoop.hbase.example.HBaseSample- Put successfully. 3264 [main] INFOcom.huawei.hadoop.hbase.example.HBaseSample- Exiting testPut. 3264 [main] INFOcom.huawei.hadoop.hbase.example.HBaseSample- Entering testGet. 3283 [main] INFOcom.huawei.hadoop.hbase.example.HBaseSample- 012005000201:info,address,Shenzhen, Guangdong 3283 [main] INFOcom.huawei.hadoop.hbase.example.HBaseSample- 012005000201:info,name,yugeZhang San 3283 [main] INFOcom.huawei.hadoop.hbase.example.HBaseSample- Get data successfully. 3283 [main] INFOcom.huawei.hadoop.hbase.example.HBaseSample- Exiting testGet. 3283 [main] INFOorg.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation- Closing zookeeper sessionid=0xd000035eba278e9 3297 [main] INFOorg.apache.zookeeper.ZooKeeper- Session: 0xd000035eba278e9 closed 3297 [main-EventThread] INFOorg.apache.zookeeper.ClientCnxn- EventThread shut down -----------finish HBase -------------------
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot