利用Hadoop自带example实现wordCount
Posted boqianliu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了利用Hadoop自带example实现wordCount相关的知识,希望对你有一定的参考价值。
上次虽然把环境搭好了,但是实际运行起来一堆错误,下面简述一下踩的坑。
1、hadoop fs -put上传文件失败
报错信息:(test文件夹是已经成功建好的)
[[email protected] ~]# hadoop fs -put test1.txt /test 18/12/27 03:50:53 WARN hdfs.DFSClient: DataStreamer Exception org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /test/test1.txt._COPYING_ could only be replicated to 0 nodes instead of minReplication (=1). There are 0 datanode(s) running and no node(s) are excluded in this operation. at org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.chooseTarget4NewBlock(BlockManager.java:1620) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getNewBlockTargets(FSNamesystem.java:3135) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem.java:3059) at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.addBlock(NameNodeRpcServer.java:725) at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.addBlock(ClientNamenodeProtocolServerSideTranslatorPB.java:493) at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java) at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:616) at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:982) at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2217) at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2213) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:415) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1762) at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2211) at org.apache.hadoop.ipc.Client.call(Client.java:1476) at org.apache.hadoop.ipc.Client.call(Client.java:1413) at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:229) at com.sun.proxy.$Proxy10.addBlock(Unknown Source) at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.addBlock(ClientNamenodeProtocolTranslatorPB.java:418) 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:191) at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102) at com.sun.proxy.$Proxy11.addBlock(Unknown Source) at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.locateFollowingBlock(DFSOutputStream.java:1603) at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.nextBlockOutputStream(DFSOutputStream.java:1388) at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.run(DFSOutputStream.java:554) put: File /test/test1.txt._COPYING_ could only be replicated to 0 nodes instead of minReplication (=1). There are 0 datanode(s) running and no node(s) are excluded in this operation.
Linux报的错误是datanode节点不存在,但是去slave机器上jps发现datanode运行的好好的。然后去网上查找资料,有博客说是因为没关闭防火墙,没有访问权限, 好嘛,又去关防火墙,结果命令又不存在,因为实验室分配的机器太老了(好像是Red Hat4.x Linux3.x版本的),又吭哧吭哧装了半天命令,再查看防火墙,是关闭的啊,我真的是头疼。
然后接着找其他解决方案吧,参考资料3说可能是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
再来试试,还是不行。。
2、
参考资料:
1、Ubuntu16.04 上运行 Hadoop2.7.3 自带example wordCount摸索记录
2、Failed to execute operation: No such file or directory(systemctl enable iptables.service)
3、File /input/data.txt._COPYING_ could only be replicated to 0 nodes instead of minReplication (=1)
以上是关于利用Hadoop自带example实现wordCount的主要内容,如果未能解决你的问题,请参考以下文章