无法通过Java

时间:2016-11-14 12:09:48

标签: java hadoop hbase

我正在尝试从Java连接到Hbase。 Hbase -Version 1.0.0 但我无法连接它。请告诉我,因为我是Hbase的新手,我缺少了什么。 这是我的代码

public class HbaseAddRetrieveData{
    public static void main(String[] args) throws IOException {
        TableName tableName = TableName.valueOf("stock-prices");


    Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.master","LocalHost:60000");
    conf.set("hbase.zookeeper.property.clientPort", "2181");
    conf.set("hbase.zookeeper.quorum", "LocalHost");
    conf.set("zookeeper.znode.parent", "/hbase-unsecure");
    System.out.println("Config set");
    Connection conn = ConnectionFactory.createConnection(conf);
    System.out.println("Connection");
    Admin admin = conn.getAdmin();
    if (!admin.tableExists(tableName)) {
        System.out.println("In admin");
        admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor("cf")));
    }

    Table table = conn.getTable(tableName);
    Put p = new Put(Bytes.toBytes("AAPL10232015"));
    p.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("close"), Bytes.toBytes(119));
    table.put(p);

    Result r = table.get(new Get(Bytes.toBytes("AAPL10232015")));
    System.out.println(r);
}

以下是我面临的错误:

Exception in thread "main" org.apache.hadoop.hbase.client.RetriesExhaustedException: Can't get the locations
at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.getRegionLocations(RpcRetryingCallerWithReadReplicas.java:305)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:131)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:56)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:200)
at org.apache.hadoop.hbase.client.ClientScanner.call(ClientScanner.java:287)
at org.apache.hadoop.hbase.client.ClientScanner.nextScanner(ClientScanner.java:267)
at org.apache.hadoop.hbase.client.ClientScanner.initializeScannerInConstruction(ClientScanner.java:139)
at org.apache.hadoop.hbase.client.ClientScanner.<init>(ClientScanner.java:134)
at org.apache.hadoop.hbase.client.HTable.getScanner(HTable.java:823)
at org.apache.hadoop.hbase.MetaTableAccessor.fullScan(MetaTableAccessor.java:601)
at org.apache.hadoop.hbase.MetaTableAccessor.tableExists(MetaTableAccessor.java:365)
at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:281)
at com.tcs.healthcare.HbaseRetrieveData.main(HbaseRetrieveData.java:32)

请指导我完成这个

1 个答案:

答案 0 :(得分:1)

将localhost中的L更改为l和&#39; H&#39;到了&#39; h&#39;

Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.master","localhost:60000");
    conf.set("hbase.zookeeper.property.clientPort", "2181");
    conf.set("hbase.zookeeper.quorum", "localhost");
    conf.set("zookeeper.znode.parent", "/hbase-unsecure");

如果您使用的是远程机器,那么conf.set(&#34; hbase.master&#34;,&#34; remotehost:60000&#34;);即使它不工作,然后检查类路径中的所有罐子(远程)

如果您使用的是maven,则可以指向群集中的jar。

你可以去集群并检查下面的命令,以了解远程机器中的jar版本。

`hbase classpath`

您的客户端计算机中应该存在相同版本的jar。对于远程机器中的ex hbasex.jar,您使用的是hbasey.jar,然后它就不会连接。

此外,请从客户端计算机检查您是否能够ping服务器/群集。通常会有防火墙限制。