구성표에 대한 파일 시스템 없음 : 파일
나는 NaiveBayesClassifer
이 오류가 발생하여 hadoop을 사용하여 간단한 실행을 시도하고 있습니다.
Exception in thread "main" java.io.IOException: No FileSystem for scheme: file
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:1375)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:66)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1390)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:196)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:95)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:180)
at org.apache.hadoop.fs.Path.getFileSystem(Path.java:175)
at org.apache.mahout.classifier.naivebayes.NaiveBayesModel.materialize(NaiveBayesModel.java:100)
코드 :
Configuration configuration = new Configuration();
NaiveBayesModel model = NaiveBayesModel.materialize(new Path(modelPath), configuration);// error in this line..
modelPath
NaiveBayes.bin
파일을 가리키고 구성 개체가 인쇄 중입니다.Configuration: core-default.xml, core-site.xml
항아리 때문이라고 생각합니다. 아이디어가 있습니까?
이것은 maven-assembly
플러그인이 문제를 일으키는 전형적인 경우입니다 .
이것이 우리에게 일어난 이유
서로 다른 JAR ( hadoop-commons
for LocalFileSystem
, hadoop-hdfs
for DistributedFileSystem
)에는 각각 org.apache.hadoop.fs.FileSystem
해당 META-INFO/services
디렉토리 에서 호출되는 서로 다른 파일이 포함되어 있습니다 . 이 파일은 선언하려는 파일 시스템 구현의 표준 클래스 이름을 나열합니다 (를 통해 구현 된 서비스 공급자 인터페이스라고합니다 . 2622 행java.util.ServiceLoader
참조 ).org.apache.hadoop.FileSystem
를 사용하면 maven-assembly-plugin
모든 JAR을 하나로 병합하고 모두 META-INFO/services/org.apache.hadoop.fs.FileSystem
서로 덮어 씁니다. 이러한 파일 중 하나만 남아 있습니다 (마지막으로 추가 된 파일). 이 경우 FileSystem
에서 목록 hadoop-commons
에서 목록 덮어 쓰기는 hadoop-hdfs
, 그래서 DistributedFileSystem
더 이상 선언되지 않았다.
해결 방법
Hadoop 구성을로드 한 후 FileSystem
관련 작업을 수행하기 직전에 다음 과 같이 호출합니다.
hadoopConfig.set("fs.hdfs.impl",
org.apache.hadoop.hdfs.DistributedFileSystem.class.getName()
);
hadoopConfig.set("fs.file.impl",
org.apache.hadoop.fs.LocalFileSystem.class.getName()
);
업데이트 : 올바른 수정
모든 서비스 선언 의 병합 된 버전을 사용하는 +krookedking
구성 기반 방법이 있다는 점에 주목했습니다 . 파일에 다음 플러그인을 추가 하십시오.maven-assembly
FileSystem
pom.xml
<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>
shade 플러그인을 사용하는 경우, david_p의 조언에 따라 ServicesResourceTransformer를 플러그인 구성에 추가하여 음영 처리 된 jar의 서비스를 병합 할 수 있습니다.
<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>
그러면 모든 org.apache.hadoop.fs.FileSystem 서비스가 하나의 파일에 병합됩니다.
기록을 위해 이것은 hadoop 2.4.0에서 여전히 발생합니다. 너무 답답해 ...
이 링크의 지침을 따를 수있었습니다 : http://grokbase.com/t/cloudera/scm-users/1288xszz7r/no-filesystem-for-scheme-hdfs
core-site.xml에 다음을 추가했는데 제대로 작동했습니다.
<property>
<name>fs.file.impl</name>
<value>org.apache.hadoop.fs.LocalFileSystem</value>
<description>The FileSystem for file: uris.</description>
</property>
<property>
<name>fs.hdfs.impl</name>
<value>org.apache.hadoop.hdfs.DistributedFileSystem</value>
<description>The FileSystem for hdfs: uris.</description>
</property>
Spark 2.0.2로 알아내는 데 나이가 들었지만 여기에 내 비트가 있습니다.
val sparkBuilder = SparkSession.builder
.appName("app_name")
.master("local")
// Various Params
.getOrCreate()
val hadoopConfig: Configuration = sparkBuilder.sparkContext.hadoopConfiguration
hadoopConfig.set("fs.hdfs.impl", classOf[org.apache.hadoop.hdfs.DistributedFileSystem].getName)
hadoopConfig.set("fs.file.impl", classOf[org.apache.hadoop.fs.LocalFileSystem].getName)
그리고 내 관련 부분 build.sbt
:
scalaVersion := "2.11.8"
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.0.2"
도움이 되었기를 바랍니다.
감사합니다 david_p, scala
conf.set("fs.hdfs.impl", classOf[org.apache.hadoop.hdfs.DistributedFileSystem].getName);
conf.set("fs.file.impl", classOf[org.apache.hadoop.fs.LocalFileSystem].getName);
또는
<property>
<name>fs.hdfs.impl</name>
<value>org.apache.hadoop.hdfs.DistributedFileSystem</value>
</property>
maven의 경우 hadoop-hdfs (아래 링크 참조)에 대한 maven 종속성을 추가하면 문제가 해결됩니다.
http://mvnrepository.com/artifact/org.apache.hadoop/hadoop-hdfs/2.7.1
hadoop의 mvn 및 cloudera 배포를 사용하고 있다고 가정합니다. 나는 cdh4.6을 사용하고 있으며 이러한 종속성을 추가하면 저에게 효과적이었습니다. hadoop 및 mvn 종속성의 버전을 확인해야한다고 생각합니다.
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>2.0.0-mr1-cdh4.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.0.0-cdh4.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>2.0.0-cdh4.6.0</version>
</dependency>
cloudera mvn 저장소를 추가하는 것을 잊지 마십시오.
<repository>
<id>cloudera</id>
<url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
</repository>
sbt 어셈블리를 사용하여 프로젝트를 패키징합니다. 나는 또한이 문제를 만난다. 내 솔루션이 여기 있습니다. 1 단계 : build.sbt에 META-INF 병합 전략 추가
case PathList("META-INF", "MANIFEST.MF") => MergeStrategy.discard
case PathList("META-INF", ps @ _*) => MergeStrategy.first
2 단계 : build.sbt에 hadoop-hdfs lib 추가
"org.apache.hadoop" % "hadoop-hdfs" % "2.4.0"
Step3 : 깨끗한 sbt; sbt 어셈블리
위의 정보가 도움이되기를 바랍니다.
maven을 사용하여 샘플을 빌드한다고 가정합니다.
Please check content of the JAR you're trying to run. Especially META-INFO/services
directory, file org.apache.hadoop.fs.FileSystem
. There should be list of filsystem implementation classes. Check line org.apache.hadoop.hdfs.DistributedFileSystem
is present in the list for HDFS and org.apache.hadoop.fs.LocalFileSystem
for local file scheme.
If this is the case, you have to override referred resource during the build.
Other possibility is you simply don't have hadoop-hdfs.jar
in your classpath but this has low probability. Usually if you have correct hadoop-client
dependency it is not an option.
Another possible cause (though the OPs question doesn't itself suffer from this) is if you create a configuration instance that does not load the defaults:
Configuration config = new Configuration(false);
If you don't load the defaults then you won't get the default settings for things like the FileSystem
implementations which leads to identical errors like this when trying to access HDFS. Switching to the parameterless constructor of passing in true
to load defaults may resolve this.
Additionally if you are adding custom configuration locations (e.g. on the file system) to the Configuration
object be careful of which overload of addResource()
you use. For example if you use addResource(String)
then Hadoop assumes that the string is a class path resource, if you need to specify a local file try the following:
File configFile = new File("example/config.xml");
config.addResource(new Path("file://" + configFile.getAbsolutePath()));
It took me sometime to figure out fix from given answers, due to my newbieness. This is what I came up with, if anyone else needs help from the very beginning:
import org.apache.spark.SparkContext
import org.apache.spark.SparkConf
object MyObject {
def main(args: Array[String]): Unit = {
val mySparkConf = new SparkConf().setAppName("SparkApp").setMaster("local[*]").set("spark.executor.memory","5g");
val sc = new SparkContext(mySparkConf)
val conf = sc.hadoopConfiguration
conf.set("fs.hdfs.impl", classOf[org.apache.hadoop.hdfs.DistributedFileSystem].getName)
conf.set("fs.file.impl", classOf[org.apache.hadoop.fs.LocalFileSystem].getName)
I am using Spark 2.1
And I have this part in my build.sbt
assemblyMergeStrategy in assembly := {
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case x => MergeStrategy.first
}
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://nameNode:9000");
FileSystem fs = FileSystem.get(conf);
set fs.defaultFS works for me! Hadoop-2.8.1
For SBT use below mergeStrategy in build.sbt
mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) => {
case PathList("META-INF", "services", "org.apache.hadoop.fs.FileSystem") => MergeStrategy.filterDistinctLines
case s => old(s)
}
}
If you are using sbt:
//hadoop
lazy val HADOOP_VERSION = "2.8.0"
lazy val dependenceList = Seq(
//hadoop
//The order is important: "hadoop-hdfs" and then "hadoop-common"
"org.apache.hadoop" % "hadoop-hdfs" % HADOOP_VERSION
,"org.apache.hadoop" % "hadoop-common" % HADOOP_VERSION
)
I faced the same problem. I found two solutions: (1) Editing the jar file manually:
Open the jar file with WinRar (or similar tools). Go to Meta-info > services , and edit "org.apache.hadoop.fs.FileSystem" by appending:
org.apache.hadoop.fs.LocalFileSystem
(2) Changing the order of my dependencies as follow
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
Use this plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</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>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>allinone</shadedClassifierName>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
</artifactSet>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>reference.conf</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer">
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
I also came across similar issue. Added core-site.xml and hdfs-site.xml as resources of conf (object)
Configuration conf = new Configuration(true);
conf.addResource(new Path("<path to>/core-site.xml"));
conf.addResource(new Path("<path to>/hdfs-site.xml"));
Also edited version conflicts in pom.xml. (e.g. If configured version of hadoop is 2.8.1, but in pom.xml file, dependancies has version 2.7.1, then change that to 2.8.1) Run Maven install again.
This solved error for me.
참고URL : https://stackoverflow.com/questions/17265002/hadoop-no-filesystem-for-scheme-file
'development' 카테고리의 다른 글
orderby 필터가 문자열 배열에서 작동하도록 만드는 방법은 무엇입니까? (0) | 2020.09.17 |
---|---|
동일한 임의의 numpy 배열을 일관되게 생성 (0) | 2020.09.17 |
Java에서 Log4J 출력 비활성화 (0) | 2020.09.17 |
iPhone 애플리케이션의 수명주기는 무엇입니까? (0) | 2020.09.17 |
막대 그래프에서 Y 축 수치를 백분율로 변경하려면 어떻게해야합니까? (0) | 2020.09.17 |