如何连接到Java中的远程HBase? [英] How to connect to remote HBase in Java?

查看:116
本文介绍了如何连接到Java中的远程HBase?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个独立的HBase服务器。
这是我的hbase-site.xml:

 < configuration> 
<属性>
<名称> hbase.rootdir< /名称>
<值> file:/// hbase_data< / value>
< / property>
< / configuration>

我正在尝试编写一个Java程序来处理HBase中的数据。

如果我在HBase服务器上运行该程序,它可以正常工作。但我不知道如何配置它进行远程访问。

 配置config = HBaseConfiguration.create(); 
HTable table = new HTable(config,test);
扫描s =新扫描();

我已经尝试添加IP和端口,它不起作用:

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

任何人都可以告诉我该怎么做吗?



感谢!

解决方案

这是我们使用的系统的一个片段创建一个我们用来连接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";

这篇关于如何连接到Java中的远程HBase?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆