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.(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! 

你能告诉我为什么它会抛出exception,代码有什么问题以及如何解决它。

由于您使用Hbase服务器的hosts文件,因此会出现此问题。 您只需要编辑hbase服务器的/ etc / hosts文件。 从该文件中删除localhost条目,并将localhost条目放在hbase server ip之前。

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

 127.0.0.1 localhost 192.166.66.66 xyz.hbase.com hbase 

您必须通过删除localhost来更改它:

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

这是因为当远程机器向hbase服务器机器询问HMaster正在运行的位置时,它会告诉它在本机上的localhost上运行。 因此,如果我们继续输入127.0.01的条目,那么hbase服务器将返回此地址,并且远程计算机开始在其自己的计算机上查找HMaster。 当我们改变并将其置于hbase ip之前,那么一切都将是完美的:)

我同意.. HBase对/ etc / hosts配置非常敏感。我必须正确设置hbase-site.xml中的zeekeeper bindings属性才能使上面提到的Java代码工作…例如:I不得不设置如下:

 {property} {name}hbase.zookeeper.quorum{/name} {value}www.remoterg12.net{/value} {!-- this is the externally accessible domain --} {/property} {property} {name}hbase.zookeeper.property.clientPort{/name} {value}2181{/value} {!-- everything needs to be externally accessible --} {/property} {property} {name}hbase.master.info.port{/name} {!-- http://www.remoterg12.net:60010/ --} {value}60010{/value} {/property} {property} {name}hbase.master.info.bindAddress{/name} {value}www.remoterg12.net{/value} {!-- Use this to access the GUI console, --} {/property} 

远程GUI将为您提供绑定域的清晰图片。例如,“GUI Web控制台”中的[HBase Master]属性应该是这样的:www.remoterg12.net:60010(它不应该是localhost :60010)…和是!!,我确实必须正确使用/ etc / hosts,因为我不想搞乱现有的Apache配置:-)

通过编辑hbase目录中的conf/regionservers文件以在其中添加Hbase服务器(Remote),可以解决同样的问题。 然后无需更改etc / hosts文件

编辑conf/regionservers会看起来像:

 localhost ip address of the remote hbase server 

例如

 localhost 10.132.258.366 

与HBase 1.1.3完全相同的问题。 2个虚拟机(Ubuntu)在同一网络上。 日志显示客户端可以访问Zookeeper但不能访问HBase服务器。

TL; DR:删除服务器上/etc/hosts中的以下行( server_hostame ):

 127.0.1.1 server_hostname server_hostname 

并在(本地)网络上添加127.xyz服务器的ip:

 192.xyz server_hostname 

我在客户端和服务器端尝试了很多组合。 在独立模式下,我认为没有更好的方法。 并不为此感到骄傲。 遗憾的是必须弄乱网络配置,甚至不能提供能够远程连接到服务器的HBase shell客户端(欢迎来到Java世界的幻想……)

在服务器端,将文件conf/hbase-site.xml空。 你不需要在这里放置Zookeeper配置,默认设置很好。 对于etc/regionservers 。 保留它与默认条目( localhost ),因为我不认为它在真正关心的独立模式(我试图将server_hostname放在其中,当然这不起作用)。

在客户端,如果要使用它解析,它必须通过主机名知道服务器,因此请在/etc/hosts客户端文件中为服务器添加一个条目。

作为奖励,我向您提供了我的sbt配置和一些完整的客户端代码,因为HBase团队似乎已经花费了过去4年在Vegas的文档预算(再次欢迎«Business ready»Java / Scala世界) 。

build.sbt

 libraryDependencies ++= Seq( ... "org.apache.hadoop" % "hadoop-core" % "1.2.1", "org.apache.hbase" % "hbase" % "1.1.2", "org.apache.hbase" % "hbase-client" % "1.1.2", ) 

some_client_code.scala

 import org.apache.hadoop.hbase.HBaseConfiguration import org.apache.hadoop.hbase.client.{HTable, Put, HBaseAdmin} import org.apache.hadoop.hbase.util.Bytes val hbaseConf = HBaseConfiguration.create() hbaseConf.set("hbase.zookeeper.quorum", "server_hostname") HBaseAdmin.checkHBaseAvailable(hbaseConf) val table = new HTable(hbaseConf, "my_hbase_table") val put = new Put(Bytes.toBytes("row_key")) put.add(Bytes.toBytes("cf"), Bytes.toBytes("colId1"), Bytes.toBytes("foo")) 

我知道回答这个问题为时已晚,但我想分享一下解决类似问题的方法。

我有同样的问题,我试图从java程序设置zookeeper仲裁,并尝试通过CLI,但没有一个工作。

我使用CDH 5.7.7与HBase版本1.1.0最后我不得不将几个配置导出到Hadoop类路径来解决问题。 这是我导出的配置。

 export HADOOP_CLASSPATH=/etc/hadoop/conf:/usr/share/cmf/lib/cdh5/hbase-protocol-0.98.1-cdh5.5.0.jar:/etc/hbase/conf:/driven/conf 

希望这可以帮助。