zoukankan      html  css  js  c++  java
  • MapReduce 踩坑

    一、场景

    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

  • 相关阅读:
    git安装和简单配置
    IDEA调试服务器上部署的程序
    fastjson的@JSONField注解的一点问题
    Spring quartz定时任务service注入问题
    MySql 插入数据库报错 Incorrect string value: 'xF0xA0x86xA2'
    Window启动Zookeeper报错java.lang.NumberFormatException: For input string:
    wget命令下载文件
    遇见的面试题
    使用jackson来进行数组格式的json字符串转换成List。
    边距重叠的三种情况
  • 原文地址:https://www.cnblogs.com/PigeonNoir/p/9213388.html
Copyright © 2011-2022 走看看