Hbase客户端无法与远程Hbase服务器连接

Ali*_*aza 14 java hadoop 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();
Run Code Online (Sandbox Code Playgroud)

它抛出一些例外:

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!
Run Code Online (Sandbox Code Playgroud)

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

kha*_*han 21

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

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

127.0.0.1 localhost
192.166.66.66 xyz.hbase.com hbase
Run Code Online (Sandbox Code Playgroud)

你必须通过删除localhost来改变它:

# 127.0.0.1 localhost # line commented out
192.166.66.66 xyz.hbase.com hbase localhost # note: localhost added here
Run Code Online (Sandbox Code Playgroud)

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

  • 更改后必须重新启动Hbase.'netstat -a | grep 6000'命令在这里很有用,因为它显示master绑定到本地接口. (2认同)
  • 有什么优雅的方法吗?我们可以在某些配置文件中指定xyz.hbase.com而不是更改hosts文件吗?谢谢。该解决方案实际上对我有用,但不那么优雅。 (2认同)