Connecting to a GeminiDB HBase Instance
This section describes how to connect to a GeminiDB HBase instance using a private IP address and Java.
Prerequisites
- A GeminiDB HBase instance has been created and is running normally. For details about how to create a GeminiDB HBase instance, see Buying a GeminiDB HBase Instance.
- For details about how to create an ECS, see Purchasing an ECS in Getting Started with Elastic Cloud Server.
- JDK has been installed on the ECS.
- Download the HBase client.
Viewing the IP Address of an Instance
- Log in to the GeminiDB console.
- On the Instances page, click the name of the target instance.
Method 1
In the Node Information area on the Basic Information page, view the private IP address of each node in the GeminiDB HBase instance.
Public IP addresses cannot be bound to GeminiDB HBase instances.
Figure 1 Obtaining IP addresses
In the Network Information area, you can view the port of the GeminiDB HBase instance. The default port displayed on the page is 8635, but the default port in use is 2181.
Figure 2 Viewing the port number
Method 2
In the navigation pane on the left, click Connections.
Figure 3 Viewing the IP addresses and port number
Connecting to an Instance over a Private Network
- Log in to ECS.
For details, see Logging In to an ECS in Getting Started with Elastic Cloud Server.
- Upload the HBase client installation package to the ECS.
- Run the following command to decompress the package:
tar -xvf hbase-2.5.8-client-bin.tar.gz
- Add the following configurations to conf/hbase-site.xml in the client directory and set value to the IP address of your instance. Use commas (,) to separate multiple IP addresses. The private IP address can be obtained by following Viewing the IP Address of an Instance.
<configuration> <property> <name>hbase.zookeeper.quorum</name> <value>127.0.0.1,127.0.0.2,127.0.0.3</value> </property> </configuration>
- Go to the bin directory of the decompressed client and run the following command to connect to the instance: Replace YOUR_USERNAME and YOUR_PASSWORD with the user password set during instance creation. The username is fixed to rwuser.
export HADOOP_PROXY_USER="YOUR_USERNAME" export HADOOP_USER_NAME="YOUR_PASSWORD" ./hbase shell
- If information similar to the following is displayed, the connection was successful.
hbase:001:0>
Connecting to an Instance Using Java
- Obtain the private IP address and port number of the instance.
For details about how to obtain the private IP address and port number, see Viewing the IP Address of an Instance.
- Log in to the ECS. For details, see Logging In to an ECS in Getting Started with Elastic Cloud Server.
- Add the following Maven dependencies to your project.
<dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-client</artifactId> <version>2.5.3</version> </dependency>
- Edit the code for connecting to the instance.
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.*; import org.apache.hadoop.hbase.util.Bytes; import java.io.IOException; public class HBaseExample { public static void main(String[] args) throws IOException { // Creates a configuration object and sets HBase connection parameters. Configuration config = HBaseConfiguration.create(); config.set("hbase.zookeeper.quorum", "your_hbase_instance_quorum"); config.set("hbase.zookeeper.property.clientPort", "your_hbase_instance_port"); // Enters a username and password. UserGroupInformation ugi = UserGroupInformation.createProxyUser("your_user_name", UserGroupInformation.createRemoteUser("your_password")); // Establishes a connection to the HBase instance. Connection connection = ConnectionFactory.createConnection(config, User.create(ugi)); try { // Obtains table objects. TableName tableName = TableName.valueOf("your_table_name"); Table table = connection.getTable(tableName); // Inserts data. Put put = new Put(Bytes.toBytes("row_key")); put.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("col"), Bytes.toBytes("value")); table.put(put); // Obtains a single row of data. Get get = new Get(Bytes.toBytes("row_key")); Result result = table.get(get); byte[] value = result.getValue(Bytes.toBytes("cf"), Bytes.toBytes("col")); System.out.println("Value: " + Bytes.toString(value)); } finally { // Closes the connection. connection.close(); } } }
- Run the sample code to check whether the result is normal.
Feedback
Was this page helpful?
Provide feedbackThank 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