gpt4 book ai didi

java - Hbase客户端无法连接到远程Hbase服务器

转载 作者:太空狗 更新时间:2023-10-29 23:04:25 25 4
gpt4 key购买 nike

我为远程服务器编写了以下 hbase 客户端类:

System.out.println("Hbase Demo Application ");

// CONFIGURATION

// ENSURE RUNNING
try {
HBaseConfiguration config = new HBaseConfiguration();
config.clear();
config.set("hbase.zookeeper.quorum", "192.168.15.20");
config.set("hbase.zookeeper.property.clientPort","2181");
config.set("hbase.master", "192.168.15.20:60000");
//HBaseConfiguration config = HBaseConfiguration.create();
//config.set("hbase.zookeeper.quorum", "localhost"); // Here we are running zookeeper locally
HBaseAdmin.checkHBaseAvailable(config);


System.out.println("HBase is running!");
// createTable(config);
//creating a new table
HTable table = new HTable(config, "mytable");
System.out.println("Table mytable obtained ");
addData(table);
} catch (MasterNotRunningException e) {
System.out.println("HBase is not running!");
System.exit(1);
}catch (Exception ce){ ce.printStackTrace();

它抛出一些异常:

Oct 17, 2011 1:43:54 PM org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation getMaster
INFO: getMaster attempt 0 of 1 failed; no more retrying.
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
at org.apache.hadoop.net.SocketIOWithTimeout.connect(SocketIOWithTimeout.java:206)
at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:404)
at org.apache.hadoop.hbase.ipc.HBaseClient$Connection.setupIOstreams(HBaseClient.java:328)
at org.apache.hadoop.hbase.ipc.HBaseClient.getConnection(HBaseClient.java:883)
at org.apache.hadoop.hbase.ipc.HBaseClient.call(HBaseClient.java:750)
at org.apache.hadoop.hbase.ipc.HBaseRPC$Invoker.invoke(HBaseRPC.java:257)
at $Proxy4.getProtocolVersion(Unknown Source)
at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:419)
at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:393)
at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:444)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getMaster(HConnectionManager.java:359)
at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:89)
at org.apache.hadoop.hbase.client.HBaseAdmin.checkHBaseAvailable(HBaseAdmin.java:1215)
at com.ifkaar.hbase.HBaseDemo.main(HBaseDemo.java:31)
HBase is not running!

你能告诉我为什么会抛出异常,代码有什么问题以及如何解决吗?

最佳答案

此问题是由于您的 HBase 服务器的主机文件引起的。
您只需要编辑 HBase 服务器的/etc/hosts 文件。
从该文件中删除 localhost 条目并将 localhost 条目放在 HBase 服务器 IP 前面。

例如,您的 HBase 服务器的 /etc/hosts 文件如下所示:

127.0.0.1 localhost
192.166.66.66 xyz.hbase.com hbase

你必须通过删除本地主机来改变它:

# 127.0.0.1 localhost # line commented out
192.166.66.66 xyz.hbase.com hbase localhost # note: localhost added here

这是因为当远程机器询问 HMaster 正在运行的 hbase 服务器机器时,它告诉它正在本地主机上运行。
因此,如果条目是 127.0.0.1,则 HBase 服务器返回此地址,远程计算机开始在自己的计算机(本地)上查找 HMaster。
当我们使用 HBase 服务器 IP 更改它时,一切正常:)

关于java - Hbase客户端无法连接到远程Hbase服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7791788/

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