简体   繁体   中英

Unable to Connect to HBase 0.96.1.1-hadoop2 Standalone in Java

My problem is that I am attempting to connect to a standalone HBase instance using Java and the program just hangs indefinitely.

I have set up a fresh instance of HBase 0.96.1.1-hadoop2 and Hadoop 2.2.0 on an iMac running OS X 10.8.5. It seems that both are running fine in the sense that I can access the web ui's normally (eg localhost:60010 for HBase) without a hitch.

Running jps gives me this:

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

I am able to use HBase shell to create and scan tables as in the examples on the HBase Quick start guide. I am also running Hbase and Hadoop with the same user (not sure if this matters or not).

Here is the Java program I am trying to run:

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();
    }
}

Finally, I have this dependency in my pom file:

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

The output I am seeing is this:

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

And it just hangs indefinitely...

Remove config.clear(); from your code and see if it helps. Also, config.set("hbase.master", "localhost:60000"); is not required as the client gets information about HM from the ZK quorum.

If problem still persists, please show us the HM log file.

我通过意识到我的Zookeeper的clientPort是2183而不是2181来解决了这个问题。我在HBase Web UI localhost:60010上注意到了这一点,并在hbase-site.xml中确认了这一点。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM