2013-03-04 128 views
0

Hadoop和HDFS似乎是正確的,當我瀏覽到何處上傳hdfs文件?

http://127.0.01:50070/dfshealth.jsp運行了我,我收到這樣的輸出:

enter image description here

但是當我嘗試運行代碼

public class firstmapreducedriver { 

    public static void main(String[] args) { 
     JobClient client = new JobClient(); 
     JobConf conf = new JobConf(firstmapreducedriver.class); 

     // TODO: specify output types 
     conf.setOutputKeyClass(Text.class); 
     conf.setOutputValueClass(IntWritable.class); 

     // TODO: specify input and output DIRECTORIES (not files) 

     conf.setInputFormat(TextInputFormat.class); 
     conf.setOutputFormat(TextOutputFormat.class); 

     FileInputFormat.setInputPaths(conf, new Path("dfs")); 
     FileOutputFormat.setOutputPath(conf, new Path("Out")); 

     // TODO: specify a mapper 
     conf.setMapperClass(org.apache.hadoop.mapred.lib.IdentityMapper.class); 

     // TODO: specify a reducer 
     conf.setReducerClass(org.apache.hadoop.mapred.lib.IdentityReducer.class); 

     client.setConf(conf); 
     try { 
      JobClient.runJob(conf); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

} 

我收到此錯誤:

13/03/04 19:53:33 WARN conf.Configuration: DEPRECATED: hadoop-site.xml found in the classpath. Usage of hadoop-site.xml is deprecated. Instead use core-site.xml, mapred-site.xml and hdfs-site.xml to override properties of core-default.xml, mapred-default.xml and hdfs-default.xml respectively 
13/03/04 19:53:51 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same. 
13/03/04 19:53:51 INFO mapred.JobClient: Cleaning up the staging area hdfs://localhost:9100/tmp/hadoop-newuser/mapred/staging/newuser/.staging/job_201303041945_0001 
13/03/04 19:53:51 ERROR security.UserGroupInformation: PriviledgedActionException as:newuser cause:org.apache.hadoop.mapred.InvalidInputException: Input path does not exist: hdfs://localhost:9100/user/newuser/dfs 
org.apache.hadoop.mapred.InvalidInputException: Input path does not exist: hdfs://localhost:9100/user/newuser/dfs 
    at org.apache.hadoop.mapred.FileInputFormat.listStatus(FileInputFormat.java:197) 
    at org.apache.hadoop.mapred.FileInputFormat.getSplits(FileInputFormat.java:208) 
    at org.apache.hadoop.mapred.JobClient.writeOldSplits(JobClient.java:989) 
    at org.apache.hadoop.mapred.JobClient.writeSplits(JobClient.java:981) 
    at org.apache.hadoop.mapred.JobClient.access$600(JobClient.java:174) 
    at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:897) 
    at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:850) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at javax.security.auth.Subject.doAs(Subject.java:396) 
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1121) 
    at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:850) 
    at org.apache.hadoop.mapred.JobClient.submitJob(JobClient.java:824) 
    at org.apache.hadoop.mapred.JobClient.runJob(JobClient.java:1261) 
    at firstmapreducedriver.main(firstmapreducedriver.java:44) 

我在哪裏可以配置hdfs文件的位置,或者我需要在哪裏創建dir「dfs」以便找到它?

回答

1

在代碼中,你指定的目錄:

FileInputFormat.setInputPaths(conf, new Path("dfs")); 
    FileOutputFormat.setOutputPath(conf, new Path("Out")); 

任何相對路徑(一個不帶/開始)將有/user/$USER根。所以,你必須確保你的輸入路徑/user/newuser/dfs存在並且有數據在裏面。您可以執行以下操作製作目錄並存入文件:

hadoop fs -mkdir /user/newuser/dfs 
hadoop fs -copyFromLocal localFile.txt /user/newuser/dfs/