Hbase客户端无法连接远程Hbase服务器 [英] Hbase client do not able to connect with remote Hbase server

查看:374
本文介绍了Hbase客户端无法连接远程Hbase服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  System.out.println(Hbase Demo Application ); 

// CONFIGURATION

//确保正在运行
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); //这里我们在本地运行zookeeper
HBaseAdmin.checkHBaseAvailable(config);


System.out.println(HBase is running!);
// createTable(config);
//创建一个新表
HTable表= new HTable(config,mytable);
System.out.println(Table mytable obtain);
addData(table);
} catch(MasterNotRunningException e){
System.out.println(HBase is not running!);
System.exit(1);
} catch(Exception ce){ce.printStackTrace();

抛出一些异常:

  2011年10月17日下午1:43:54 org.apache.hadoop.hbase.client.HConnectionManager $ HConnectionImplementation getMaster 
INFO:getMaster尝试0之1失败;没有更多的重试。
java.net.ConnectException:连接被拒绝
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没有运行!

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

解决方案

由于您的Hbase服务器的主机文件而出现此问题。你只需要编辑你的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#行注释掉
192.166.66.66 xyz.hbase.com hbase localhost#note:localhost在这里添加

这是因为当远程机器向hbase服务器机器询问HMaster正在运行的位置时,它告诉它在本机上运行在本地主机上。所以如果我们继续输入127.0.01,那么hbase服务器返回这个地址,并且远程机器开始在它自己的机器上找到HMaster。当我们改变并将它放在hbase ip的前面时,那么一切都将是完美的:)

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.

解决方案

This problem is occuring due to you 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:

127.0.0.1 localhost
192.166.66.66 xyz.hbase.com hbase

You have to change it like this by removing localhost:

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

This is because when remote machine asks hbase server machine that where HMaster is running, it tells that it is running on localhost mean on this machine. So if we continue to place the entry of 127.0.01 then hbase server returns this adress and remote machine start to find HMaster on its own machine. and when we change and placed it infront of hbase ip then everything would be perfect :)

这篇关于Hbase客户端无法连接远程Hbase服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆