JAVA程序鏈接hadoop HDFS服務報沒法鏈接。

    在虛擬機部署hadoop的HDFS系統,在centos系統中敲各類操做命令,對文件讀取、上傳、刪除等都沒什麼問題。但用JAVA寫了代碼去操做HDFS文件時,出現奇怪的現象:java

     代碼寫是寫到獲取fileSystem對象:node

Configuration configuration=new Configuration();
FileSystem fileSystem=FileSystem.get(configuration);

    報瞭如下異常現象:apache

Exception in thread "main" java.net.ConnectException: Call From DESKTOP-1A7JSVH/192.168.139.1 to hadoop.node.master:8020 failed on connection exception: java.net.ConnectException: Connection refused: no further information; For more details see:  http://wiki.apache.org/hadoop/ConnectionRefused
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.apache.hadoop.net.NetUtils.wrapWithMessage(NetUtils.java:783)
    at org.apache.hadoop.net.NetUtils.wrapException(NetUtils.java:730)
    at org.apache.hadoop.ipc.Client.call(Client.java:1415)
    at org.apache.hadoop.ipc.Client.call(Client.java:1364)
    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:206)
    at com.sun.proxy.$Proxy14.getBlockLocations(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:187)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102)
    at com.sun.proxy.$Proxy14.getBlockLocations(Unknown Source)
    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.getBlockLocations(ClientNamenodeProtocolTranslatorPB.java:225)
    at org.apache.hadoop.hdfs.DFSClient.callGetBlockLocations(DFSClient.java:1165)
    at org.apache.hadoop.hdfs.DFSClient.getLocatedBlocks(DFSClient.java:1155)
    at org.apache.hadoop.hdfs.DFSClient.getLocatedBlocks(DFSClient.java:1145)
    at org.apache.hadoop.hdfs.DFSInputStream.fetchLocatedBlocksAndGetLastBlockLength(DFSInputStream.java:268)
    at org.apache.hadoop.hdfs.DFSInputStream.openInfo(DFSInputStream.java:235)
    at org.apache.hadoop.hdfs.DFSInputStream.<init>(DFSInputStream.java:228)
    at org.apache.hadoop.hdfs.DFSClient.open(DFSClient.java:1318)
    at org.apache.hadoop.hdfs.DistributedFileSystem$3.doCall(DistributedFileSystem.java:293)
    at org.apache.hadoop.hdfs.DistributedFileSystem$3.doCall(DistributedFileSystem.java:289)
    at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)
    at org.apache.hadoop.hdfs.DistributedFileSystem.open(DistributedFileSystem.java:289)
    at org.apache.hadoop.fs.FileSystem.open(FileSystem.java:764)
    at com.my.hadoop.HadoopTest.main(HadoopTest.java:28)
Caused by: java.net.ConnectException: Connection refused: no further information
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)
    at org.apache.hadoop.net.SocketIOWithTimeout.connect(SocketIOWithTimeout.java:206)
    at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:529)
    at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:493)
    at org.apache.hadoop.ipc.Client$Connection.setupConnection(Client.java:606)
    at org.apache.hadoop.ipc.Client$Connection.setupIOstreams(Client.java:700)
    at org.apache.hadoop.ipc.Client$Connection.access$2800(Client.java:367)
    at org.apache.hadoop.ipc.Client.getConnection(Client.java:1463)
    at org.apache.hadoop.ipc.Client.call(Client.java:1382)
    ... 24 morevim

檢查過程以下:centos

       一開始覺得HDFS的8020服務端口,在虛擬機服務器上敲了netstat -ntlp | grep 8020,出現以下結果 :服務器

         tcp        0      0 127.0.0.1:8020          0.0.0.0:*               LISTEN      4753/java  tcp

       服務端口正常,防火牆也已經關閉,況且打開http://hadoop.node.master:50070顯示HDFS服務也正常,一時摸不着頭腦。oop

      最後,分析了一下netstat命令的結果,裏面顯示的是127.0.0.1,感受8020端口綁定的是本地端口,有多是這個緣由引發,因而,敲vim /etc/hosts命令,fetch

將127.0.0.1 hadoop.node.master改爲192.168.139.130 hadoop.node.master.net

而後重啓了namenode和datanode服務,而後運行上述java程序,竟然正常了。

相關文章
相關標籤/搜索