我有一个独立的 HBase 服务器。 这是我的 hbase-site.xml:
<configuration>
<property>
<name>hbase.rootdir</name>
<value>file:///hbase_data</value>
</property>
</configuration>
我正在尝试编写一个Java程序来操作HBase中的数据。
如果我在 HBase 服务器上运行该程序,它工作正常。但我不知道如何配置它以进行远程访问。
Configuration config = HBaseConfiguration.create();
HTable table = new HTable(config, "test");
Scan s = new Scan();
我尝试添加IP和端口,但不起作用:
config.set("hbase.master", "146.169.35.28:60000")
谁能告诉我该怎么做?
谢谢!
最佳答案
这是我们用来创建用于连接到 HBase 的 HTable 的系统的片段
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
编辑:示例值:
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";
关于hbase - 如何用Java连接远程HBase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6614413/