gpt4 book ai didi

java - HBase Java连接

转载 作者:可可西里 更新时间:2023-11-01 16:14:03 25 4
gpt4 key购买 nike

我想通过 Java 设置与 HBase 的连接,但我遇到了问题。我在我的 CentOS 6.5 上通过 Ambari 安装了一个单节点 HDP 2.1。我有以下代码:

public class PutExample {
public static void main(String[] args) throws IOException {

final String serverFQDN = "hadoop.hortonworks";

Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", serverFQDN);
conf.set("hbase.zookeeper.property.clientPort", "2181");
conf.set("zookeeper.znode.parent", "/hbase-unsecure");

HBaseAdmin admin = new HBaseAdmin(conf);

try {

HTable table = new HTable(conf, "hb_tt2");

} catch ( Exception ex ) {
System.out.println("Error caught.");
ex.printStackTrace();
}

System.out.println("End.");
}
}

这是输出:

log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/bae/Desktop/Neue%20Bibliotheken/lib%20Hadoop/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/bae/Desktop/Neue%20Bibliotheken/lib%20Zookeeper/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
Error caught.
java.io.IOException: Unable to determine ZooKeeper ensemble
at org.apache.hadoop.hbase.zookeeper.ZKUtil.connect(ZKUtil.java:121)
at org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.<init>(ZooKeeperWatcher.java:165)
at org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.<init>(ZooKeeperWatcher.java:134)
at org.apache.hadoop.hbase.client.ZooKeeperKeepAliveConnection.<init>(ZooKeeperKeepAliveConnection.java:43)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.getKeepAliveZooKeeperWatcher(ConnectionManager.java:1725)
at org.apache.hadoop.hbase.client.ZooKeeperRegistry.isTableOnlineState(ZooKeeperRegistry.java:103)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.isTableDisabled(ConnectionManager.java:926)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.relocateRegion(ConnectionManager.java:1093)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegionInMeta(ConnectionManager.java:1374)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegion(ConnectionManager.java:1128)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegion(ConnectionManager.java:1111)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegion(ConnectionManager.java:1070)
at org.apache.hadoop.hbase.client.HTable.finishSetup(HTable.java:347)
at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:201)
at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:159)
at bt.PutExample.main(PutExample.java:41)
End.

我没有更改任何配置文件,我使用的是在 Hadoop 服务器上找到的 jar 文件。我的程序或服务器是否缺少任何配置?我无法弄清楚此错误消息的含义。

提前感谢您的帮助

最佳答案

尝试更改 hbase jar 的版本。有时微小的变化会有所帮助。我遇到了同样的异常,将 hbase 客户端 jar(在 pom.xml 中)从 0.98 修改为 0.98.4 有所帮助。

<version>0.98.4-hadoop2</version>

关于java - HBase Java连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25887127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com