当前位置: 首页 > 知识库问答 >
问题:

hadoop map reduce中的文件系统访问异常

郜杰
2023-03-14

我已经在Ubuntu14.04上配置了Hadoop2.6.0。我正在运行wordcount map reduce程序,最初是为了了解map reduce作业。我在访问文件系统时遇到了一些问题。我将Hadoop主目录放在/opt/hadoop2.6.0中。

>

  • 驱动程序

        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "word count");
        job.setJarByClass(WordCount.class);
        job.setMapperClass(TokenizerMapper.class);
        job.setCombinerClass(IntSumReducer.class);
        job.setReducerClass(IntSumReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        // configuration should contain reference to your namenode
         FileSystem hdfs =FileSystem.get(new Configuration()); 
        Path workingDir=hdfs.getWorkingDirectory();
    
        Path newFolderPath= new Path("/output");
    
        newFolderPath=Path.mergePaths(workingDir, newFolderPath);
    
        if(hdfs.exists(newFolderPath))
    
        {
    
            hdfs.delete(newFolderPath, true); //Delete existing Directory
    
        }
        hdfs.mkdirs(newFolderPath); 
        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job,newFolderPath );
        System.exit(job.waitForCompletion(true) ? 0 : 1); //line no. 76
        // job.submit();
    
    <configuration>
        <property>
            <name>fs.defaultFS</name>
            <value>hdfs://localhost:9000</value>
        </property>
        <property>
            <name>hadoop.tmp.dir</name> 
            <value>/app/hadoop/tmp</value> 
        </property>
    </configuration>
    

    hdfs-site.xml

    <configuration>
        <property>
            <name>dfs.replication</name>
            <value>1</value>
        </property>
        <property>
            <name>dfs.namenode.name.dir</name>
            <value>/opt/hadoop-2.6.0/dfs/name</value>
        </property>
        <property>
            <name>dfs.datanode.data.dir</name>
            <value>/opt/hadoop-2.6.0/dfs/data</value>
        </property>
        <property>
            <name>dfs.permissions.enabled</name>
            <value>false</value>
        </property>
        <property>
            <name>dfs.http.address</name>
            <value>localhost:50070</value>
        </property>
        <property>
            <name>dfs.webhdfs.enabled</name>
            <value>true</value>
        </property>
    </configuration>
    

    yarn-site.xml

    <configuration>
    
      <!-- Site specific YARN configuration properties --> <property>
            <name>yarn.nodemanager.aux-services</name>  
            <value>mapreduce_shuffle</value> </property> <property>      
            <name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>   
              <value>org.apache.hadoop.mapred.ShuffleHandler</value> </property>
     <property>
             <name>yarn.application.classpath</name>
             <value>
                  %HADOOP_HOME%\etc\hadoop,
                  %HADOOP_HOME%\share\hadoop\common\*,
                  %HADOOP_HOME%\share\hadoop\common\lib\*,
                  %HADOOP_HOME%\share\hadoop\hdfs\*,
                  %HADOOP_HOME%\share\hadoop\hdfs\lib\*,
                  %HADOOP_HOME%\share\hadoop\mapreduce\*,
                  %HADOOP_HOME%\share\hadoop\mapreduce\lib\*,
                  %HADOOP_HOME%\share\hadoop\yarn\*,
                  %HADOOP_HOME%\share\hadoop\yarn\lib\*
             </value> 
        </property> 
    

    运行map reduce Jar:

     hadoop jar /home/ifs-admin/wordcount.jar  WordCount /user/ifs/input 
    
        15/08/23 12:12:25 INFO Configuration.deprecation: session.id is deprecated. Instead, use dfs.metrics.session-id
        15/08/23 12:12:25 INFO jvm.JvmMetrics: Initializing JVM Metrics with processName=JobTracker, sessionId=
        Exception in thread "main" org.apache.hadoop.mapred.FileAlreadyExistsException: Output directory
        hdfs://localhost:9000/user/ifs-admin/output already exists
        at org.apache.hadoop.mapreduce.lib.output.FileOutputFormat.checkOutputSpecs(FileOutputFormat.java:146)
        at org.apache.hadoop.mapreduce.JobSubmitter.checkSpecs(JobSubmitter.java:562)
        at org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:432)
        at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1296)
        at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1293)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAs(Subject.java:415)
        at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1628)
        at org.apache.hadoop.mapreduce.Job.submit(Job.java:1293)
        at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:1314)
        at WordCount.main(WordCount.java:76)
        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.hadoop.util.RunJar.run(RunJar.java:221)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
    
       Exception in thread "main" ENOENT: No such file or directory
        at org.apache.hadoop.io.nativeio.NativeIO$POSIX.chmodImpl(Native Method)
        at org.apache.hadoop.io.nativeio.NativeIO$POSIX.chmod(NativeIO.java:230)
        at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:652)
        at org.apache.hadoop.fs.FilterFileSystem.setPermission(FilterFileSystem.java:490)
        at org.apache.hadoop.fs.FileSystem.mkdirs(FileSystem.java:599)
        at org.apache.hadoop.mapreduce.JobSubmitter.copyAndConfigureFiles(JobSubmitter.java:182)
        at org.apache.hadoop.mapreduce.JobSubmitter.copyAndConfigureFiles(JobSubmitter.java:390)
        at org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:483)
        at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1296)
        at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1293)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAs(Subject.java:415)
        at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1628)
        at org.apache.hadoop.mapreduce.Job.submit(Job.java:1293)
        at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:1314)
        at WordCount.main(WordCount.java:68)
        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.hadoop.util.RunJar.run(RunJar.java:221)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
    
  • 共有1个答案

    谢修真
    2023-03-14

    请尝试以下代码注-不要创建目录,hadoop将自动执行此操作

    FileSystem hdfs = FileSystem.get(new URI("hdfs://localhost:9000"),
                conf); 
        Path workingDir=hdfs.getWorkingDirectory();
    
        Path newFolderPath= new Path("/output");
        newFolderPath=Path.mergePaths(workingDir, newFolderPath);
        if(hdfs.exists(newFolderPath))
    
        {
            hdfs.delete(newFolderPath); //Delete existing Directory
    
        }
        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job,newFolderPath );
        System.exit(job.waitForCompletion(true) ? 0 : 1); //line no. 76
        // job.submit();
    
     类似资料:
    • 问题内容: 对于基于Windows / Linux的浏览器,我可以使用Java插件来访问文件系统。由于IOS不支持Java,是否有其他替代方法可以完成它? 问题答案: 不,你不能。无法在iOS野生动物园中上传或下载文件。在iCab中,您可以通过上传,但不能访问文件系统。从浏览器访问整个文件系统将带来安全隐患。而且Java插件无法访问整个文件系统。

    • 问题内容: 我很确定答案是 否定的 ,因此使用了Google Gears,adobe AIR等。 如果我是对的,那么如何工作?它是持久性的,并使用javascript编写。它也只是一个没有外部(服务器端)依赖关系的HTML文件。WTF?它在哪里/如何存储其状态? 问题答案: Tiddlywiki有几种保存数据的方法,具体取决于所使用的浏览器。如您所见。 如果启用了ActiveX,它将使用Scrip

    • 通用文件系统访问接口 文件和目录相关用户库函数 Lab8中部分用户库函数与文件系统有关,我们先讨论对单个文件进行操作的系统调用,然后讨论对目录和文件系统进行操作的系统调用。 在文件操作方面,最基本的相关函数是open、close、read、write。在读写一个文件之前,首先要用open系统调用将其打开。open的第一个参数指定文件的路径名,可使用绝对路径名;第二个参数指定打开的方式,可设置为O_

    • 我正在开发一个文件存储应用程序,需要读取 sd 存储和内部手机存储的内容。我已经签出了 react-native-fs 和 react-native-fetch-blob,但这两个应用程序都只允许我访问我的应用程序的存储。如何读取手机上的其他文件?

    • 我需要访问非运行docker容器的文件系统。实现这一目标的最佳方式是什么? 谢谢

    • 在parseConfiguration方法中我们通过propertiesElement和settingsAsProperties两个方法已经完成了对mybatis属性配置的解析和准备工作。 //issue #117 read properties first // 加载资源配置文件,并覆盖对应的属性[properties节点] propertiesElement(root.evalNode("