hadoop fs -put上传文件失败,WARN org.apache.hadoop.hdfs.server.datanode.DataNode: Problem connecting to server: master:8020

时间:2024-08-27 10:36:14

hadoop fs -put上传文件失败

报错信息:(test文件夹是已经成功建好的)

[root@master ~]# hadoop fs -put test1.txt /test
// :: WARN hdfs.DFSClient: DataStreamer Exception
org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /test/test1.txt._COPYING_ could only be replicated to nodes instead of minReplication (=). There are datanode(s) running and no node(s) are excluded in this operation.
at org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.chooseTarget4NewBlock(BlockManager.java:)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getNewBlockTargets(FSNamesystem.java:)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem.java:)
at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.addBlock(NameNodeRpcServer.java:)
at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.addBlock(ClientNamenodeProtocolServerSideTranslatorPB.java:)
at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$.callBlockingMethod(ClientNamenodeProtocolProtos.java)
at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:)
at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:)
at org.apache.hadoop.ipc.Server$Handler$.run(Server.java:)
at org.apache.hadoop.ipc.Server$Handler$.run(Server.java:)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:)
at org.apache.hadoop.ipc.Server$Handler.run(Server.java:) at org.apache.hadoop.ipc.Client.call(Client.java:)
at org.apache.hadoop.ipc.Client.call(Client.java:)
at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:)
at com.sun.proxy.$Proxy10.addBlock(Unknown Source)
at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.addBlock(ClientNamenodeProtocolTranslatorPB.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:)
at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:)
at com.sun.proxy.$Proxy11.addBlock(Unknown Source)
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.locateFollowingBlock(DFSOutputStream.java:)
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.nextBlockOutputStream(DFSOutputStream.java:)
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.run(DFSOutputStream.java:)
put: File /test/test1.txt._COPYING_ could only be replicated to nodes instead of minReplication (=). There are datanode(s) running and no node(s) are excluded in this operation.

Linux报的错误是datanode节点不存在,但是去slave机器上jps发现datanode运行的好好的。然后去网上查找资料,有博客说是因为没关闭防火墙,没有访问权限, 好嘛,又去关防火墙,结果命令又不存在,因为实验室分配的机器太老了(好像是Red Hat4.x Linux3.x版本的),又吭哧吭哧装了半天命令,再查看防火墙,是关闭的啊,我真的是头疼。

hadoop fs -put上传文件失败,WARN org.apache.hadoop.hdfs.server.datanode.DataNode: Problem connecting to server: master:8020

然后接着找其他解决方案吧,参考资料2说可能是format次数太多,导致每次的spaceId不一致,现在想来,我确实是format了很多次,那就先来试试。

首先停止所有服务 stop-all.sh。

然后删除 core-site.xml 中hadoop.tmp.dir对应的文件夹下所有数据,注意:不是把这个文件夹也删掉! sudo rm -rf /root/software/hadooptmp

在之后重新格式化namenode,在bin目录下 hdfs namenode -format

重新启动hadoop集群,start-all.sh

再来试试,还是不行。。

最后还是老老实实看datanode的logs,发现是无法连接上master的8020端口。

hadoop fs -put上传文件失败,WARN org.apache.hadoop.hdfs.server.datanode.DataNode: Problem connecting to server: master:8020

在同学的提醒下,我发现之前的hostname与ip的映射只在mater上做了,slave机器没有做,这也就造成了datanode无法连接到master,太太蠢了简直。

这也是给自己提个醒,不能太依赖网上的资料,普遍真理结合具体实际才可以顺利解决问题=_=

参考资料:

1、Failed to execute operation: No such file or directory(systemctl enable iptables.service)

2、File /input/data.txt._COPYING_ could only be replicated to 0 nodes instead of minReplication (=1)