无法从Java程序连接到HBase

时间:2015-03-28 04:53:38

标签: hadoop hbase apache-zookeeper

我正在尝试从Java Program连接到我的Ubuntu机器上安装的HBase独立单个集群。 我按照本博客中给出的步骤进行操作。 https://autofei.wordpress.com/2012/04/02/java-example-code-using-hbase-data-model-operations/

当我在AWS EC2上运行此代码但无法在本地执行此操作时,我能够连接到EMR群集中的HBase。我的hadoop正在运行,我可以打开hbase shell并扫描' storetable'正在向我显示一些行,没有任何异常。似乎该程序在行的无限循环中进行 -

table = new HTable(HBaseConfig, "storetable");

因为消息" HBase表创建了......"永远不会打印。 catch块没有捕获任何异常。 请帮帮我。

感谢您的帮助。

代码:

public void connectHBase()
    {
        System.out.println("Trying to establish HBase connection...");
        HBaseConfig = HBaseConfiguration.create();
        HBaseConfig.set("hbase.zookeeper.quorum", "localhost");
        HBaseConfig.set("hbase.zookeeper.property.clientPort", "2181");
        System.out.println("HBase Connection succeded...");
        try 
        {
            System.out.println("Creating HBase table...");
            table = new HTable(HBaseConfig, "storetable");
            System.out.println("HBase table created...");
        } 
        catch(Exception e) 
        {
            System.out.println("Some exception occured...");
            e.printStackTrace();
        }        
    }

控制台输出:

Trying to establish HBase connection...
HBase Connection succeded...
Creating HBase table...
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.4.3-1240972, built on 02/06/2012 10:48 GMT
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:host.name=localhost
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:java.version=1.7.0_76
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:java.home=/usr/lib/jvm/java-7-oracle/jre
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:java.class.path=/home/sankalp/workspace/AWSHadoopProject/bin:/home/sankalp/aws-java-sdk/1.9.27/lib/aws-java-sdk-1.9.27.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/javax-mail-1.4.6/javax.mail-api-1.4.6.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/joda-time-2.2/joda-time-2.2.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/jackson-annotations-2.3.0/jackson-annotations-2.3.0.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/freemarker-2.3.18/freemarker-2.3.18.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/httpcomponents-client-4.3/httpcore-4.3.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/httpcomponents-client-4.3/httpclient-4.3.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/jackson-core-2.3.2/jackson-core-2.3.2.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/commons-logging-1.1.3/commons-logging-1.1.3.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/spring-3.0/spring-context-3.0.7.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/spring-3.0/spring-beans-3.0.7.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/spring-3.0/spring-core-3.0.7.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/jackson-databind-2.3.2/jackson-databind-2.3.2.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/aspectj-1.6/aspectjweaver.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/aspectj-1.6/aspectjrt.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/commons-codec-1.6/commons-codec-1.6.jar:/home/sankalp/workspace/AWSHadoopProject/undertow-examples-1.2.0.Beta9.jar:/home/sankalp/workspace/AWSHadoopProject/commons-configuration-1.8.jar:/home/sankalp/workspace/AWSHadoopProject/commons-lang-2.6.jar:/home/sankalp/workspace/AWSHadoopProject/commons-logging-1.1.1.jar:/home/sankalp/workspace/AWSHadoopProject/hadoop-core-1.0.0.jar:/home/sankalp/workspace/AWSHadoopProject/hbase-0.92.1.jar:/home/sankalp/workspace/AWSHadoopProject/log4j-1.2.16.jar:/home/sankalp/workspace/AWSHadoopProject/slf4j-api-1.5.8.jar:/home/sankalp/workspace/AWSHadoopProject/slf4j-log4j12-1.5.8.jar:/home/sankalp/workspace/AWSHadoopProject/zookeeper-3.4.3.jar:/home/sankalp/workspace/AWSHadoopProject/json-simple-1.1.1.jar
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=/tmp
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA>
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:os.name=Linux
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:os.version=3.16.0-33-generic
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:user.name=sankalp
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:user.home=/home/sankalp
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:user.dir=/home/sankalp/workspace/AWSHadoopProject
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=180000 watcher=hconnection
15/03/29 16:53:37 INFO zookeeper.ClientCnxn: Opening socket connection to server /127.0.0.1:2181
15/03/29 16:53:37 INFO client.ZooKeeperSaslClient: Client will not SASL-authenticate because the default JAAS configuration section 'Client' could not be found. If you are not using SASL, you may ignore this. On the other hand, if you expected SASL to work, please fix your JAAS configuration.
15/03/29 16:53:37 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is 9146@skynet
15/03/29 16:53:37 INFO zookeeper.ClientCnxn: Socket connection established to localhost/127.0.0.1:2181, initiating session
15/03/29 16:53:37 INFO zookeeper.ClientCnxn: Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x14c6746b9f4000d, negotiated timeout = 40000

2 个答案:

答案 0 :(得分:1)

检查您的jar版本,使用与您尝试连接的HBase相同版本的jar,同时检查您的hosts文件是否有环回地址。

答案 1 :(得分:0)

我遇到过这个问题,其中create table无法使用java。就我而言,我还没有将hbasee-site纳入我的课程路径。

您可以在链接下方引用。

Not able to create hbase using java