2015-03-19 45 views
0

我寫了一個很短的程序來連接到HbaseJava:連接到Hbase時出現異常0.94.1

import org.apache.hadoop.conf.Configuration; 
import org.apache.hadoop.hbase.ClusterStatus; 
import org.apache.hadoop.hbase.HBaseConfiguration; 
import org.apache.hadoop.hbase.client.HBaseAdmin; 
public class HbaseMonitor { 
     public static void main(String args[]){ 
       Configuration conf = new Configuration(); 
       try{ 
         HBaseAdmin hbaseAdmin = new HBaseAdmin(conf); 
         ClusterStatus clusterStatus = hbaseAdmin.getClusterStatus(); 
         System.out.println("Has regions: "+clusterStatus.getRegionsCount()); 
       } 
       catch(Exception ex){ 
         ex.printStackTrace(); 
       } 
     } 
} 

使用在lib目錄HBase的可用同樣的罐子編譯它,如下圖所示:

javac -cp /usr/lib/hbase/hbase-0.94.1-Intel.jar:/usr/lib/hadoop/hadoop-core-1.0.3-Intel.jar:/usr/lib/hbase/lib/commons-logging-1.1.1.jar:/usr/lib/hbase/lib/zookeeper.jar:/usr/lib/hbase/lib/commons-configuration-1.6.jar:/usr/lib/hbase/lib/commons-lang-2.5.jar:/usr/lib/hbase/lib/slf4j-api-1.4.3.jar:/usr/lib/hbase/lib/slf4j-log4j12-1.4.3.jar:/usr/lib/hbase/lib/log4j-1.2.16.jar:/usr/lib/hbase/lib/guava-11.0.2.jar:/usr/lib/hbase/lib/protobuf-java-2.4.0a.jar:. HbaseMonitor.java 

當我運行它,我得到以下異常:

15/03/19 17:47:07 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=180000 watcher=hconnection 
15/03/19 17:47:07 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is [email protected] 
15/03/19 17:47:07 INFO zookeeper.ClientCnxn: Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (Unable to locate a login configuration) 
15/03/19 17:47:07 INFO zookeeper.ClientCnxn: Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session 
15/03/19 17:47:07 INFO zookeeper.ClientCnxn: Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x4c31791de7041e, negotiated timeout = 180000 
15/03/19 17:47:07 INFO client.HConnectionManager$HConnectionImplementation: getMaster attempt 0 of 10 failed; retrying after sleep of 1006 
java.io.IOException: Call to ostrich-node1/192.168.151.50:60000 failed on local exception: java.io.EOFException 
    at org.apache.hadoop.hbase.ipc.HBaseClient.wrapException(HBaseClient.java:1110) 
    at org.apache.hadoop.hbase.ipc.HBaseClient.call(HBaseClient.java:1079) 
    at org.apache.hadoop.hbase.ipc.WritableRpcEngine$Invoker.invoke(WritableRpcEngine.java:150) 
    at com.sun.proxy.$Proxy5.getProtocolVersion(Unknown Source) 
    at org.apache.hadoop.hbase.ipc.WritableRpcEngine.getProxy(WritableRpcEngine.java:183) 
    at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:335) 
    at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:312) 
    at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:364) 
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getMaster(HConnectionManager.java:710) 
    at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:141) 
    at HbaseMonitor.main(HbaseMonitor.java:17) 
Caused by: java.io.EOFException 
    at java.io.DataInputStream.readInt(DataInputStream.java:375) 
    at org.apache.hadoop.hbase.ipc.HBaseClient$Connection.receiveResponse(HBaseClient.java:605) 
    at org.apache.hadoop.hbase.ipc.HBaseClient$Connection.run(HBaseClient.java:538) 

的Telnet到hbase-master工作正常:

[[email protected] test]# telnet ostrich-node1 60000 
Trying 192.168.151.50... 
Connected to ostrich-node1. 
Escape character is '^]'. 

遠程登錄本地主機的清楚地顯示,則客戶端可以連接到HBase的:

[[email protected] test]# telnet localhost 2181 
Trying ::1... 
Connected to localhost. 
Escape character is '^]'. 
^CConnection closed by foreign host. 

主日誌下面對於上述異常警告(hbase-hbase-master-ostrich-node1.log)顯示器:

2015-03-19 17:47:07,711 WARN org.apache.hadoop.ipc.SecureServer: Incorrect header or version mismatch from 192.168.151.50:57502 got version 3 expected version 4 

從上述警告,一個可能會說我用於hbasehadoop-core.jar與用於hadoop的那個不同。是的。所以,我更換了罐子,但不幸的是錯誤沒有消失。

請注意,我已經在安裝了hbase的同一臺機器上執行了我的程序。

HBase的版本:

[[email protected] logs]# hbase version 
15/03/19 17:59:17 INFO util.VersionInfo: HBase 0.94.1-Intel 

的Hadoop版本:

[[email protected] logs]# hadoop version 
Hadoop 1.0.3-Intel 

HBase的殼工作:

[[email protected] logs]# hbase shell 
HBase Shell; enter 'help<RETURN>' for list of supported commands. 
Type "exit<RETURN>" to leave the HBase Shell 
Version 0.94.1-Intel, r17177, Wed Sep 18 14:52:53 CST 2013 

hbase(main):001:0> list 
TABLE                                                  
ATTR                                                  
RECO                                                  
SUBSCRIBER                                                 
SUBSCRIBER2                                                 
TPETEST                                                  
test                                                  
6 row(s) in 1.0700 seconds 

那麼,什麼可能是問題? 請幫忙。

回答

0

這爲我工作做以下的事情:

  1. 添加HBASE_CONF的路徑在到底classpath,如下圖所示(右鍵單擊在形象和在新標籤中打開它,如果它們太小理解):

enter image description here

注意:在我的hbase主節點中,HBASE_CONF =/usr/lib/hbase/conf。

  • 不幸的是,但真實的,用在稍微修改的程序depreacted方法:
  • enter image description here

    注:HBaseConfiguration()已被棄用,但適用於HBase的-0.94。 1(英特爾)。

    和下方的輸出被示出:

    enter image description here

    對不起,代碼熒光筆是不工作的大型代碼。因此,我用 圖像來正確顯示它們。