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

  • 相关阅读:
    ActiveMQ 5.x 消息队列
    Spring Boot 整合 ElasticSearch 框架
    Spring Boot 整合 Logback 日志框架
    Spring Boot 整合定时任务和异步任务处理
    Spring 中使用 Java 5.0 Executor
    二级指针三种内存模型综合训练
    08-图8 How Long Does It Take (25 分)
    08-图9 关键活动 (30 分)
    08-图7 公路村村通 (30 分)
    C函数之index、strtoul
  • 原文地址:https://www.cnblogs.com/PigeonNoir/p/9213388.html
Copyright © 2011-2022 走看看