我的问题是,我试图连接到一个独立的hbase示例使用java和程序只是挂起无限期。
我在运行OSX10.8.5的imac上设置了一个新的hbase 0.96.1.1-hadoop2和hadoop2.2.0示例。从我可以正常访问web ui的Angular 来看,这两个功能似乎都运行良好(例如。localhost:60010 for (hbase)没有任何问题。
运行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
它只是无限期地挂着。。。
2条答案
按热度按时间5gfr0r5j1#
删除
config.clear();
从你的代码,看看是否有帮助。也,config.set("hbase.master", "localhost:60000");
不需要,因为客户机从zk quorum获取有关hm的信息。如果问题仍然存在,请向我们显示hm日志文件。
mrwjdhj32#
我解决了这个问题,因为我意识到我的Zookeeper的客户端口是2183而不是2181。。。我在hbase web ui上注意到了这一点localhost:60010 and 我在hbase-site.xml中确认了这一点。