且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何连接到Java中的远程HBase?

更新时间:2022-10-31 10:24:20

这是我们使用的系统的一个片段创建一个我们用来连接HBase的HTable

 配置hConf = HBaseConfiguration.create(conf); 
hConf.set(Constants.HBASE_CONFIGURATION_ZOOKEEPER_QUORUM,hbaseZookeeperQuorum);
hConf.setInt(Constants.HBASE_CONFIGURATION_ZOOKEEPER_CLIENTPORT,hbaseZookeeperClientPort);

HTable hTable = new HTable(hConf,tableName);

HTH



编辑: 示例值:

  public static final String HBASE_CONFIGURATION_ZOOKEEPER_QUORUM =hbase.zookeeper.quorum; 
public static final String HBASE_CONFIGURATION_ZOOKEEPER_CLIENTPORT =hbase.zookeeper.property.clientPort;
...
hbaseZookeeperQuorum =PDHadoop1.corp.CompanyName.com,PDHadoop2.corp.CompanyName.com;
hbaseZookeeperClientPort = 10000;
tableName =HBaseTableName;


I have a standlone HBase server. This is my hbase-site.xml:

<configuration>
 <property>
    <name>hbase.rootdir</name>
    <value>file:///hbase_data</value>
  </property>
</configuration>

I am trying to write a Java program to manipulate the data in the HBase.

If I run the program on the HBase server, it works fine. But I don't know how to config it for remote access.

  Configuration config = HBaseConfiguration.create();
   HTable table = new HTable(config, "test");
   Scan s = new Scan();

I have tried adding IP and Port, it doesn't work:

config.set("hbase.master", "146.169.35.28:60000")

Can anyone tell me how to do it?

Thanks!

Here's a snippet from a system we use to create an HTable we use to connect to HBase

Configuration hConf = HBaseConfiguration.create(conf);
hConf.set(Constants.HBASE_CONFIGURATION_ZOOKEEPER_QUORUM, hbaseZookeeperQuorum);
hConf.setInt(Constants.HBASE_CONFIGURATION_ZOOKEEPER_CLIENTPORT, hbaseZookeeperClientPort);

HTable hTable = new HTable(hConf, tableName);

HTH

EDIT: Example Values:

public static final String HBASE_CONFIGURATION_ZOOKEEPER_QUORUM                     = "hbase.zookeeper.quorum";
public static final String HBASE_CONFIGURATION_ZOOKEEPER_CLIENTPORT                 = "hbase.zookeeper.property.clientPort";
...
hbaseZookeeperQuorum="PDHadoop1.corp.CompanyName.com,PDHadoop2.corp.CompanyName.com";
hbaseZookeeperClientPort=10000;
tableName="HBaseTableName";