gpt4 book ai didi

java - 如何使用来自不同网络的 Java 库(org.apache.hadoop.hbase.client)连接 Hbase?

转载 作者:行者123 更新时间:2023-12-02 21:37:12 27 4
gpt4 key购买 nike

我有一个使用内部网络的 Hadoop 集群(IP 范围为 192.168.0.0/24),我想使用 java 库(org.apache.hadoop.hbase.client)连接 hbase
来自使用不同网络的 Windows 7 上的开发计算机(ip 是外部网络 203.252.x.x),但是,我无法连接 hbase。

我有个问题。

  • 我的代码错了吗??
  • 是否可以使用 Java 库(org.apache.hadoop.hbase.client),我应该使用节俭协议(protocol)吗? (我不想用 Thrift)

  • 你有什么主意吗?或评论?

    谢谢

    这是我连接 Hbase 的代码。
     public class TestBase {
    public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, ServiceException, IOException {

    Configuration configuration = HBaseConfiguration.create();

    configuration.set("hbase.master", "203.252.x.x"); // master info
    configuration.set("hbase.master.port", "6000");
    configuration.set("hbase.zookeeper.quorum", "203.252.x.x");
    configuration.set("hbase.zookeeper.property.clientPort", "2181");
    configuration.set("zookeeper.znode.parent", "/hbase-unsecure");

    HBaseAdmin.checkHBaseAvailable(configuration);

    HTable table = null;
    table = new HTable(configuration, "weatherData");

    Scan scan = new Scan();

    scan.setTimeRange(1L, 1435633313526L);
    ResultScanner scanner = null;
    scanner = table.getScanner(scan);

    for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
    System.out.println(Bytes.toString(rr.getRow())
    + " => "
    + Bytes.toString(rr.getValue(Bytes.toBytes("temp"),
    Bytes.toBytes("max"))));
    }
    table.close();
    scanner.close();
    }
    }

    那是 Eclipse 中的错误代码
    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.
    Exception in thread "main" org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.net.UnknownHostException: unknown host: datanode2
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStub(ConnectionManager.java:1661)
    at enter code hereorg.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(ConnectionManager.java:1687)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.getKeepAliveMasterService(ConnectionManager.java:1904)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.isMasterRunning(ConnectionManager.java:932)
    at enter code hereorg.apache.hadoop.hbase.client.HBaseAdmin.checkHBaseAvailable(HBaseAdmin.java:2409)
    at TestBase.main(TestBase.java:28)
    Caused by: com.google.protobuf.ServiceException: java.net.UnknownHostException: unknown host: datanode2
    at org.apache.hadoop.hbase.ipc.RpcClient.callBlockingMethod(RpcClient.java:1739)
    at org.apache.hadoop.hbase.ipc.RpcClient$BlockingRpcChannelImplementation.callBlockingMethod(RpcClient.java:1777)
    at org.apache.hadoop.hbase.protobuf.generated.MasterProtos$MasterService$BlockingStub.isMasterRunning(MasterProtos.java:42561)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.isMasterRunning(ConnectionManager.java:1698)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStubNoRetries(ConnectionManager.java:1607)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStub(ConnectionManager.java:1633)
    ... 5 more
    Caused by: java.net.UnknownHostException: unknown host: datanode2
    at org.apache.hadoop.hbase.ipc.RpcClient$Connection.<init>(RpcClient.java:501)
    at org.apache.hadoop.hbase.ipc.RpcClient.createConnection(RpcClient.java:325)
    at org.apache.hadoop.hbase.ipc.RpcClient.getConnection(RpcClient.java:1614)
    at org.apache.hadoop.hbase.ipc.RpcClient.call(RpcClient.java:1494)
    at org.apache.hadoop.hbase.ipc.RpcClient.callBlockingMethod(RpcClient.java:1724)
    ... 10 more

    最佳答案

    HBase Master DNS 名称映射到 hbase.master 的 ip 地址可能存在问题。确保您设置了 DNS 服务器,否则您可以尝试在我的 GNU/Linux 机器上找到与此类似的东西。比如在尝试连接主节点的机器上配置“/etc/hostname”:设置HBase Master节点的名称)和“/etc/hosts”。

    希望你能以某种方式在你的 Windows 机器上设置它。

    这是 GNU/Linux 方式的有用链接:

    http://sujee.net/2012/03/08/getting-dns-right-for-hadoop-hbase-clusters/#.XULnEZNKhTZ

    关于java - 如何使用来自不同网络的 Java 库(org.apache.hadoop.hbase.client)连接 Hbase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31241662/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com