gpt4 book ai didi

java - 无法在 Java 中连接到 HBase 0.96.1.1-hadoop2 Standalone

转载 作者:行者123 更新时间:2023-12-01 13:33:41 24 4
gpt4 key购买 nike

我的问题是,我尝试使用 Java 连接到独立的 HBase 实例,但程序无限期挂起。

我已在运行 OS X 10.8.5 的 iMac 上设置了 HBase 0.96.1.1-hadoop2 和 Hadoop 2.2.0 的新实例。看起来两者都运行良好,因为我可以正常访问 Web ui(例如 HBase 的 localhost:60010)。

运行 jps 给我这个:

bash-3.2$ jps
77164 SecondaryNameNode
81089 Jps
80685 HMaster
77360 NodeManager
77273 ResourceManager
77061 DataNode
76975 NameNode

我能够使用 HBase shell 创建和扫描表,如 HBase 快速入门指南中的示例所示。我还使用同一用户运行 Hbase 和 Hadoop(不确定这是否重要)。

这是我尝试运行的 Java 程序:

package com.mypackage.dao.hbase;

import java.io.IOException;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.conf.Configuration;

public class HBaseDao {

private static final String DICTIONARY_TABLE = "mytable";
private static final String DICTIONARY_CF = "mycf";
private static final String DICTIONARY_CF_TYPE = "type";

private final Configuration conf;

public HBaseDao() throws IOException {
Configuration config = HBaseConfiguration.create();
config.clear();
config.set("hbase.zookeeper.quorum", "localhost");
config.set("hbase.zookeeper.property.clientPort","2181");
config.set("hbase.master", "localhost:60000");
config.addResource(new Path("/usr/local/hbase/hbase/conf/hbase-site.xml"));
this.conf = config;
}

public void addNameToTable(HTableInterface table, String name, String type) throws IOException {
Put p = new Put(Bytes.toBytes(name));
p.add(Bytes.toBytes(DICTIONARY_CF),
Bytes.toBytes(DICTIONARY_CF_TYPE),
Bytes.toBytes(type));
System.out.println("About to put");
table.put(p);
}


public void loadDictionaryIntoTable() throws IOException {
HConnection connection = HConnectionManager.createConnection(this.conf);
HTableInterface table = connection.getTable(DICTIONARY_TABLE);
try {
// Use the table as needed, for a single operation and a single thread
String s = "TestName2";
String t = "TestType2";
addNameToTable(table,s,t);
} finally {
System.out.println("Got here");
table.close();
connection.close();
}
}

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

HBaseDao dao = new HBaseDao();
dao.loadDictionaryIntoTable();
}
}

最后,我的 pom 文件中有这个依赖项:

<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>0.96.1.1-hadoop2</version>
</dependency>

我看到的输出是这样的:

Ok we started 
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: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
2014-01-28 16:19:48.453 java[81102:1903] Unable to load realm info from SCDynamicStore

它只是无限期地挂起......

最佳答案

从代码中删除 config.clear(); 并查看是否有帮助。另外,不需要 config.set("hbase.master", "localhost:60000");,因为客户端从 ZK 仲裁中获取有关 HM 的信息。

如果问题仍然存在,请向我们显示 HM 日志文件。

关于java - 无法在 Java 中连接到 HBase 0.96.1.1-hadoop2 Standalone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21408213/

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