Hbase客户端无法连接到远程Hbase服务器
我为远程服务器编写了以下 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!
你能告诉我为什么它抛出异常,代码有什么问题以及如何解决它。
i have written a following hbase client class for remote server:
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();
it is throwing some exception:
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!
can you tell me why is it throwing an exception, what is wrong with code and how to solve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
此问题是由于 HBase 服务器的主机文件导致的。
您只需要编辑 HBase 服务器的 /etc/hosts 文件。
从该文件中删除 localhost 条目,并将 localhost 条目放在 HBase 服务器 IP 前面。
例如,您的 HBase 服务器的
/etc/hosts
文件如下所示:您必须通过删除 localhost 来更改它:
这是因为当远程计算机询问 HBase 服务器计算机在哪里运行 HMaster 时,它会告诉它正在本地主机上运行。
因此,如果条目是 127.0.0.1,则 HBase 服务器返回此地址,并且远程计算机开始在其自己的计算机(本地)上查找 HMaster。
当我们使用 HBase 服务器 IP 更改它时,一切都会正常:)
This problem is occuring due to your HBase server's hosts file.
You just need to edit you HBase server's /etc/hosts file.
Remove the localhost entry from that file and put the localhost entry in front of HBase server IP.
For example, your HBase server's
/etc/hosts
files seems like this:You have to change it like this by removing localhost:
This is because when remote machine asks hbase server machine where HMaster is running, it tells that it is running on localhost.
So if the entry is 127.0.0.1 then HBase server returns this address and remote machine start to find HMaster on its own machine (locally).
When we change that with the HBase Server IP then everything works fine :)
我同意.. HBase 对 /etc/hosts 配置非常敏感.. 我必须正确设置 hbase-site.xml 中的 zeekeeper 绑定属性才能使上述 Java 代码正常工作...例如:我必须按如下方式设置:
远程 GUI 将为您提供绑定域的清晰图片。例如,“GUI Web 控制台”中的 [HBase Master] 属性应该是这样的: www.remoterg12.net:60010 (不应该是 localhost:60010 )...是的!!,我确实必须正确地使用 /etc/hosts,因为我不想弄乱现有的 Apache配置:-)
I agree.. The HBase is very sensitive to /etc/hosts configurations.. I had to set the zeekeeper bindings property in the hbase-site.xml correctly in order for the above mentioned Java code to work...For example: I had to set it as follows:
The Remote GUI will give you a clear picture of the Binding Domains.. For example, the [HBase Master] property in the "GUI Web console" should be something like this: www.remoterg12.net:60010 (It should NOT be localhost:60010 )... AND YES!!, I did have to play around with the /etc/hosts just right as I didn't want to mess up the existing Apache configs :-)
同样的问题可以通过编辑hbase目录下的conf/regionservers文件添加Hbase服务器(远程)来解决。然后无需更改etc/hosts文件
编辑
conf/regionservers
后将如下所示:例如
The same problem can be solve by editing the
conf/regionservers
file in hbase directory to add the Hbase server (Remote) in it . Then no need to change the etc/hosts fileAfter editing
conf/regionservers
will look like:eg
HBase 1.1.3 存在完全相同的问题。
同一网络上的 2 个虚拟机 (Ubuntu)。日志显示客户端可以访问 Zookeeper,但不能访问 HBase 服务器。
TL;DR:删除服务器上的
/etc/hosts
中的以下行 (server_hostame):并使用
127.xyz
添加这一行(本地)网络上服务器的 ip:我在客户端和服务器端尝试了很多组合。在独立模式下,我认为没有更好的方法。
对此并不感到自豪。不得不搞乱网络配置,甚至不提供能够远程连接到服务器的 HBase shell 客户端,这是一种耻辱(欢迎来到 Java 的幻想世界......)
在服务器端,将文件留在服务器端>conf/hbase-site.xml 空。您不需要在此处放置 Zookeeper 配置,默认值即可。
与
etc/regionservers
相同。将其保留为默认条目 (localhost),因为我认为在独立模式下它并不真正关心(并且我尝试将server_hostname
放入其中,当然这并不作品)。在客户端,如果您想使用它进行解析,它必须通过主机名知道服务器,因此再次在服务器的
/etc/hosts
客户端文件中添加一个条目。作为奖励,我为您提供了我的
sbt
配置和一些完整客户端的工作代码,因为 HBase 团队似乎在过去 4 年里花费了 Vegas 的文档预算(再次欢迎 Java/Scala 的“商业就绪”世界)。build.sbt:
some_client_code.scala:
Exact same problem here with HBase 1.1.3.
2 virtuals machines (Ubuntu) on the same network. The logs show that the client can reach Zookeeper but not the HBase server.
TL;DR: remove the following line in
/etc/hosts
on the server (server_hostame):And add this one with
127.x.y.z
the ip of your server on the (local) network:I tried a lot of combinations on the client and server sides. In standalone mode I don't think there is a better approach.
Not really proud of that. It is a shame to have to mess with the network configuration and to not even provide a HBase shell client able to connect remotely to a server (welcome to the Java world of illusions...)
On the server side, leave the files
conf/hbase-site.xml
empty. You don't need to put a Zookeeper configuration in here, defaults are fine.Same for
etc/regionservers
. Leave it with the default entry (localhost) because I don't think in standalone mode it really cares (and I tried to putserver_hostname
in it and of course this does not works).On the client side, It must know the server by hostname if you want to resolve with it so again add an entry in your
/etc/hosts
client file for the server.As a bonus I give you my
sbt
configuration and some complete working code for the client since the HBase team seems to have spent the documentation budget at Vegas for the last 4 years (again, welcome the «Business ready» world of Java/Scala).build.sbt:
some_client_code.scala:
我知道现在回答这个问题已经太晚了,但我想分享我解决类似问题的方法。
我遇到了同样的问题,我尝试从 java 程序设置 Zookeeper 仲裁,也尝试通过 CLI 但没有一个起作用。
我正在使用 CDH 5.7.7 和 HBase 版本 1.1.0
最后,我不得不将一些配置导出到 Hadoop 类路径来解决该问题。这是我导出的配置。
希望这有帮助。
I know it is too late to answer this question but I want to share my way of resolving a similar issue.
I had the same issue and I tried to set the zookeeper quorum from the java program and also tried via the CLI but none of them worked.
I am using CDH 5.7.7 with HBase version 1.1.0
Finally I had to export few configs to the Hadoop classpath to fix the issue. Here is config that I have exported.
Hope this helps.