HBase-在EC2实例上将Java客户端从Eclipse连接到HBase时出错

时间:2018-09-17 10:34:18

标签: client hbase

我正在eclipse IDE上编写Java客户端代码,以在我的EC2实例上运行的HBase中创建一个表。我已经通过Maven下载了Jar文件。 HBase版本是1.2.0。但这给了我以下错误...

    Connecting...
log4j:WARN No appenders could be found for logger (org.apache.hadoop.security.Groups).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Connected 
Creating Table...
Exception in thread "main" java.net.SocketTimeoutException: callTimeout=1200000, callDuration=3019412: 
    at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:159)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4117)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4110)
    at org.apache.hadoop.hbase.client.HBaseAdmin.createTableAsyncV2(HBaseAdmin.java:736)
    at org.apache.hadoop.hbase.client.HBaseAdmin.createTable(HBaseAdmin.java:657)
    at org.apache.hadoop.hbase.client.HBaseAdmin.createTable(HBaseAdmin.java:590)
    at crud.Driver.main(Driver.java:38)
Caused by: org.apache.hadoop.hbase.MasterNotRunningException: org.apache.hadoop.hbase.MasterNotRunningException: Can't get connection to ZooKeeper: KeeperErrorCode = ConnectionLoss for /hbase
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStub(ConnectionManager.java:1560)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(ConnectionManager.java:1580)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.getKeepAliveMasterService(ConnectionManager.java:1737)
    at org.apache.hadoop.hbase.client.MasterCallable.prepare(MasterCallable.java:38)
    at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:124)
    ... 6 more
Caused by: org.apache.hadoop.hbase.MasterNotRunningException: Can't get connection to ZooKeeper: KeeperErrorCode = ConnectionLoss for /hbase
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.checkIfBaseNodeAvailable(ConnectionManager.java:932)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.access$400(ConnectionManager.java:556)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStubNoRetries(ConnectionManager.java:1509)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStub(ConnectionManager.java:1551)
    ... 10 more
Caused by: org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /hbase
    at org.apache.zookeeper.KeeperException.create(KeeperException.java:99)
    at org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
    at org.apache.zookeeper.ZooKeeper.exists(ZooKeeper.java:1045)
    at org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper.exists(RecoverableZooKeeper.java:221)
    at org.apache.hadoop.hbase.zookeeper.ZKUtil.checkExists(ZKUtil.java:419)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.checkIfBaseNodeAvailable(ConnectionManager.java:921)
    ... 13 more
EC2上的

jps命令返回以下内容

10912 RunJar
17156 Jps
7814 HeadlampServer
9062 NameNode
7816 Main
9640 JobHistoryServer
1290 Main
9708 NodeManager
9805 ResourceManager
7824 AlertPublisher
7923 EventCatcherService
9044 SecondaryNameNode
9140 DataNode
9879 HRegionServer
11706 Bootstrap
7899 Main
10908 RunJar
13181 QuorumPeerMain
9855 HMaster

这是Java客户端代码。

package crud;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;


public class Driver {




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

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

        System.out.println("Connecting...");
        Connection con = ConnectionFactory.createConnection(conf);
        System.out.println("Connected \nCreating Table...");


        HTableDescriptor htable = new HTableDescriptor(TableName.valueOf("TbaleViaJar"));
        Admin admin = con.getAdmin();
        admin.createTable(htable);
        System.out.println("Table Created");

        con.close();
        System.out.println("Connection Closed.\nProgram Terminated");

    }


}

这些是pom.xml文件中添加的Maven依赖项

<dependencies>
    <!-- https://mvnrepository.com/artifact/org.apache.hbase/hbase-client -->
    <dependency>
        <groupId>org.apache.hbase</groupId>
        <artifactId>hbase-client</artifactId>
        <version>1.2.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.hbase</groupId>
        <artifactId>hbase-common</artifactId>
        <version>1.2.0</version>
    </dependency>
</dependencies>

0 个答案:

没有答案