【问题标题】:java.io.IOException: No FileSystem for scheme : hdfsjava.io.IOException:方案没有文件系统:hdfs
【发布时间】:2016-03-06 15:07:39
【问题描述】:

我正在使用 Cloudera Quickstart VM CDH5.3.0(就包裹捆绑而言)和带有 $SPARK_HOME=/opt/cloudera/parcels/CDH-5.3.0-1.cdh5.3.0.p0.30/lib/spark 的 Spark 1.2.0 并使用命令提交 Spark 应用程序

./bin/spark-submit --class <Spark_App_Main_Class_Name> --master spark://localhost.localdomain:7077 --deploy-mode client --executor-memory 4G ../apps/<Spark_App_Target_Jar_Name>.jar

Spark_App_Main_Class_Name.scala

import org.apache.spark.SparkContext
import org.apache.spark.SparkConf
import org.apache.spark.mllib.util.MLUtils


object Spark_App_Main_Class_Name {

    def main(args: Array[String]) {
        val hConf = new SparkConf()
            .set("fs.hdfs.impl", classOf[org.apache.hadoop.hdfs.DistributedFileSystem].getName)
            .set("fs.file.impl", classOf[org.apache.hadoop.fs.LocalFileSystem].getName)
        val sc = new SparkContext(hConf)
        val data = MLUtils.loadLibSVMFile(sc, "hdfs://localhost.localdomain:8020/analytics/data/mllib/sample_libsvm_data.txt")
        ...
    }

}

但是在客户端模式下 spark-submitting 应用程序时,我得到了org.apache.hadoop.hdfs.DistributedFileSystemClassNotFoundException

[cloudera@localhost bin]$ ./spark-submit --class Spark_App_Main_Class_Name --master spark://localhost.localdomain:7077 --deploy-mode client --executor-memory 4G ../apps/Spark_App_Target_Jar_Name.jar
15/11/30 09:46:34 INFO SparkContext: Spark configuration:
spark.app.name=Spark_App_Main_Class_Name
spark.driver.extraLibraryPath=/opt/cloudera/parcels/CDH-5.3.0-1.cdh5.3.0.p0.30/lib/hadoop/lib/native
spark.eventLog.dir=hdfs://localhost.localdomain:8020/user/spark/applicationHistory
spark.eventLog.enabled=true
spark.executor.extraLibraryPath=/opt/cloudera/parcels/CDH-5.3.0-1.cdh5.3.0.p0.30/lib/hadoop/lib/native
spark.executor.memory=4G
spark.jars=file:/opt/cloudera/parcels/CDH-5.3.0-1.cdh5.3.0.p0.30/lib/spark/bin/../apps/Spark_App_Target_Jar_Name.jar
spark.logConf=true
spark.master=spark://localhost.localdomain:7077
spark.yarn.historyServer.address=http://localhost.localdomain:18088
15/11/30 09:46:34 WARN Utils: Your hostname, localhost.localdomain resolves to a loopback address: 127.0.0.1; using 10.113.234.150 instead (on interface eth12)
15/11/30 09:46:34 WARN Utils: Set SPARK_LOCAL_IP if you need to bind to another address
15/11/30 09:46:34 INFO SecurityManager: Changing view acls to: cloudera
15/11/30 09:46:34 INFO SecurityManager: Changing modify acls to: cloudera
15/11/30 09:46:34 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users with view permissions: Set(cloudera); users with modify permissions: Set(cloudera)
15/11/30 09:46:35 INFO Slf4jLogger: Slf4jLogger started
15/11/30 09:46:35 INFO Remoting: Starting remoting
15/11/30 09:46:35 INFO Remoting: Remoting started; listening on addresses :[akka.tcp://sparkDriver@10.113.234.150:59473]
15/11/30 09:46:35 INFO Remoting: Remoting now listens on addresses: [akka.tcp://sparkDriver@10.113.234.150:59473]
15/11/30 09:46:35 INFO Utils: Successfully started service 'sparkDriver' on port 59473.
15/11/30 09:46:36 INFO SparkEnv: Registering MapOutputTracker
15/11/30 09:46:36 INFO SparkEnv: Registering BlockManagerMaster
15/11/30 09:46:36 INFO DiskBlockManager: Created local directory at /tmp/spark-local-20151130094636-8c3d
15/11/30 09:46:36 INFO MemoryStore: MemoryStore started with capacity 267.3 MB
15/11/30 09:46:38 INFO HttpFileServer: HTTP File server directory is /tmp/spark-7d1f2861-a568-4919-8f7e-9a9fe6aab2b4
15/11/30 09:46:38 INFO HttpServer: Starting HTTP Server
15/11/30 09:46:38 INFO Utils: Successfully started service 'HTTP file server' on port 50003.
15/11/30 09:46:38 INFO Utils: Successfully started service 'SparkUI' on port 4040.
15/11/30 09:46:38 INFO SparkUI: Started SparkUI at http://10.113.234.150:4040
15/11/30 09:46:39 INFO SparkContext: Added JAR file:/opt/cloudera/parcels/CDH-5.3.0-1.cdh5.3.0.p0.30/lib/spark/bin/../apps/Spark_App_Target_Jar_Name.jar at http://10.113.234.150:50003/jars/Spark_App_Target_Jar_Name.jar with timestamp 1448894799228
15/11/30 09:46:39 INFO AppClient$ClientActor: Connecting to master spark://localhost.localdomain:7077...
15/11/30 09:46:40 INFO SparkDeploySchedulerBackend: Connected to Spark cluster with app ID app-20151130094640-0000
15/11/30 09:46:41 INFO NettyBlockTransferService: Server created on 56458
15/11/30 09:46:41 INFO BlockManagerMaster: Trying to register BlockManager
15/11/30 09:46:41 INFO BlockManagerMasterActor: Registering block manager 10.113.234.150:56458 with 267.3 MB RAM, BlockManagerId(<driver>, 10.113.234.150, 56458)
15/11/30 09:46:41 INFO BlockManagerMaster: Registered BlockManager
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: Class org.apache.hadoop.hdfs.DistributedFileSystem not found
    at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:2047)
    at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:2578)
    at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2591)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:367)
    at org.apache.spark.util.FileLogger.<init>(FileLogger.scala:90)
    at org.apache.spark.scheduler.EventLoggingListener.<init>(EventLoggingListener.scala:63)
    at org.apache.spark.SparkContext.<init>(SparkContext.scala:352)
    at org.apache.spark.SparkContext.<init>(SparkContext.scala:92)
    at Spark_App_Main_Class_Name$.main(Spark_App_Main_Class_Name.scala:22)
    at Spark_App_Main_Class_Name.main(Spark_App_Main_Class_Name.scala)
    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.spark.deploy.SparkSubmit$.launch(SparkSubmit.scala:358)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:75)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.ClassNotFoundException: Class org.apache.hadoop.hdfs.DistributedFileSystem not found
    at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:1953)
    at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:2045)
    ... 16 more

Spark 应用程序似乎无法映射 HDFS,因为最初我遇到了错误:

Exception in thread "main" java.io.IOException: No FileSystem for scheme: hdfs
    at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:2584)
    at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2591)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:367)
    at org.apache.spark.util.FileLogger.<init>(FileLogger.scala:90)
    at org.apache.spark.scheduler.EventLoggingListener.<init>(EventLoggingListener.scala:63)
    at org.apache.spark.SparkContext.<init>(SparkContext.scala:352)
    at org.apache.spark.SparkContext.<init>(SparkContext.scala:92)
    at LogisticRegressionwithBFGS$.main(LogisticRegressionwithBFGS.scala:21)
    at LogisticRegressionwithBFGS.main(LogisticRegressionwithBFGS.scala)
    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.spark.deploy.SparkSubmit$.launch(SparkSubmit.scala:358)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:75)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala) 

我跟着 hadoop No FileSystem for scheme: file 将“fs.hdfs.impl”和“fs.file.impl”添加到 Spark 配置设置中

【问题讨论】:

    标签: scala hadoop apache-spark hdfs apache-spark-mllib


    【解决方案1】:

    您的类路径中需要有 hadoop-hdfs-2.x jars (maven link)。 在提交您的应用程序时,请使用 spark-submit 的 --jar 选项提及其他 jar 位置。

    另一方面,理想情况下,您应该迁移到具有 spark1.5 的 CDH5.5。

    【讨论】:

    • 在 spark-submitting 但给出 java.lang.ClassNotFoundException 时添加了带有 --jars 选项的 hadoop-hdfs jar:
    • ./spark-submit --class Spark_App_Main_Class_Name --master spark://localhost.localdomain:7077 --deploy-mode client --executor-memory 4G --jars /opt/cloudera/parcels /CDH/lib/hadoop-hdfs/*.jar ../apps/Spark_App_Target_Jar_Name.jar 解决了 ClassNotFoundException 但在 Spark Master WebUI 下看不到任何已完成的应用程序
    【解决方案2】:

    我在从 IDE 运行 Spark 代码并访问远程 HDFS 时遇到了同样的问题。
    所以我设置了以下配置,它得到了解决。

    JavaSparkContext jsc=new JavaSparkContext(conf);
    Configuration hadoopConfig = jsc.hadoopConfiguration();
    hadoopConfig.set("fs.hdfs.impl",org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
    hadoopConfig.set("fs.file.impl",org.apache.hadoop.fs.LocalFileSystem.class.getName());
    

    【讨论】:

    • 请在您的答案中添加一些上下文。解释它是如何解决问题的。您的帖子可能会被否决和/或关闭
    • 并且至少修复缩进
    【解决方案3】:

    经过一些详细的搜索,我已经解决了这个问题,并做了不同的试验方法。基本上,问题似乎是由于 hadoop-hdfs jar 不可用,但是在提交 spark 应用程序时,即使使用 maven-assembly-pluginmaven-jar-plugin/maven-dependency-plugin

    也找不到依赖的 jar

    maven-jar-plugin/maven-dependency-plugin组合中,正在创建主类jar和依赖jar,但仍然为依赖jar提供--jar选项导致同样的错误如下

    ./spark-submit --class Spark_App_Main_Class_Name --master spark://localhost.localdomain:7077 --deploy-mode client --executor-memory 4G --jars ../apps/Spark_App_Target_Jar_Name-dep.jar ../apps/Spark_App_Target_Jar_Name.jar
    

    按照“krookedking”在hadoop-no-filesystem-for-scheme-file 中的建议使用maven-shade-plugin 似乎解决了正确的问题,因为创建包含主类和所有依赖类的单个jar 文件消除了类路径问题。

    我的最终工作 spark-submit 命令如下:

    ./spark-submit --class Spark_App_Main_Class_Name --master spark://localhost.localdomain:7077 --deploy-mode client --executor-memory 4G ../apps/Spark_App_Target_Jar_Name.jar
    

    我的项目pom.xml中的maven-shade-plugin如下:

    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.2</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
          </plugin>
    

    注意:过滤器中的excludes可以去掉

    java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
    

    【讨论】:

      猜你喜欢
      • 2021-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      相关资源
      最近更新 更多