MapReduce 踩坑 - hadoop No FileSystem for scheme: file/hdfs
一、場景
hadoop-3.0.2 + hbase-2.0.0
一個mapreduce任務,在IDEA下本地提交到hadoop集群可以正常運行。
現在需要將IDEA本地項目通過maven打成jar包,從而能夠在windows/Linux命令行下,通過Java -jar方式運行。
?
二、狀況
報錯可能1:Exception in thread "main" java.io.IOException: No FileSystem for scheme: file
報錯可能2:Exception in thread "main" java.io.IOException: No FileSystem for scheme: hdfs
?
三、分析
- 主要是maven的maven-assembly帶來的問題。
- 問題產生原因:
- LocalFileSystem 所在的包 hadoop-commons 和 DistributedFileSystem 所在的包 hadoop-hdfs,這兩者在他們各自的 META-INFO/services下,都包含了不同但重名的文件叫做?org.apache.hadoop.fs.FileSystem。(這個FileSystem文件中,都列出了實現filesystem需要聲明的規范類名。)
- 當使用maven-assembly-plugin時,maven會將所有的jar包都merge為一個jar。因此。所有META-INFO/services/org.apache.hadoop.fs.FileSystem 會相互覆蓋,最終只留一個(the last one)。在這里,hadoop-commons 中的 FileSystem 會 overwrite 掉 hadoop-hdfs 中的 FileSystem, 因此 DistributedFileSystem 的聲明就會失效!
?
四、解決方案 - 基于mapreduce
在提交mapreduce之前,顯式指定 LocalFileSystem 或/和 DistributedFileSystem 的類,以確保它們的聲明生效。?
conf.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());conf.set("fs.file.impl",org.apache.hadoop.fs.LocalFileSystem.class.getName());五、解決方案 - 基于 maven-assembly
在pom.xml中,使用如下的maven-assembly。使用merge了所有FileSystem的合并版本,而不是互相overwrite的。
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-shade-plugin</artifactId><version>2.3</version><executions><execution><phase>package</phase><goals><goal>shade</goal></goals><configuration><transformers><transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/></transformers></configuration></execution></executions> </plugin>六、參考
https://stackoverflow.com/questions/17265002/hadoop-no-filesystem-for-scheme-file
轉載于:https://www.cnblogs.com/PigeonNoir/p/9213388.html
總結
以上是生活随笔為你收集整理的MapReduce 踩坑 - hadoop No FileSystem for scheme: file/hdfs的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 深入学习Redis(1):Redis内存
- 下一篇: 【译】Immutable.js : 操作