在windows上用eclipse遠程運行hadoop上的wordcount程序出現的問題,求解決

WordCount源代碼如下:


  1. package org.apache.hadoop.examples;

  2. import java.io.IOException;
  3. import java.util.StringTokenizer;

  4. import org.apache.hadoop.conf.Configuration;
  5. import org.apache.hadoop.fs.Path;
  6. import org.apache.hadoop.io.IntWritable;
  7. import org.apache.hadoop.io.Text;
  8. import org.apache.hadoop.mapreduce.Job;
  9. import org.apache.hadoop.mapreduce.Mapper;
  10. import org.apache.hadoop.mapreduce.Reducer;
  11. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  12. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  13. import org.apache.hadoop.util.GenericOptionsParser;

  14. public class WordCount {

  15.   public static class TokenizerMapper 
  16.        extends Mapper<Object, Text, Text, IntWritable>{
  17.     
  18.     private final static IntWritable one = new IntWritable(1);
  19.     private Text word = new Text();
  20.       
  21.     public void map(Object key, Text value, Context context
  22.                     ) throws IOException, InterruptedException {
  23.       StringTokenizer itr = new StringTokenizer(value.toString());
  24.       while (itr.hasMoreTokens()) {
  25.         word.set(itr.nextToken());
  26.         context.write(word, one);
  27.       }
  28.     }
  29.   }
  30.   
  31.   public static class IntSumReducer 
  32.        extends Reducer<Text,IntWritable,Text,IntWritable> {
  33.     private IntWritable result = new IntWritable();

  34.     public void reduce(Text key, Iterable<IntWritable> values, 
  35.                        Context context
  36.                        ) throws IOException, InterruptedException {
  37.       int sum = 0;
  38.       for (IntWritable val : values) {
  39.         sum += val.get();
  40.       }
  41.       result.set(sum);
  42.       context.write(key, result);
  43.     }
  44.   }

  45.   public static void main(String[] args) throws Exception {
  46.     Configuration conf = new Configuration();
  47.     conf.set("mapred.job.tracker", "192.168.80.100:9001");
  48.     String[] ars=new String[]{"in","newout"};
  49.     String[] otherArgs = new GenericOptionsParser(conf, ars).getRemainingArgs();
  50.     if (otherArgs.length != 2) {
  51.       System.err.println("Usage: wordcount <in> <out>");
  52.       System.exit(2);
  53.     }
  54.     Job job = new Job(conf, "wordcount");
  55.     job.setJarByClass(WordCount.class);
  56.     job.setMapperClass(TokenizerMapper.class);
  57.     job.setCombinerClass(IntSumReducer.class);
  58.     job.setReducerClass(IntSumReducer.class);
  59.     job.setOutputKeyClass(Text.class);
  60.     job.setOutputValueClass(IntWritable.class);
  61.     FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
  62.     FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
  63.     System.exit(job.waitForCompletion(true) ? 0 : 1);
  64.   }
  65. }

運行run on hadoop後報錯內容如下:

13/12/22 18:49:11 WARN mapred.JobClient: No job jar file set.  User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
13/12/22 18:49:11 INFO mapred.JobClient: Cleaning up the staging area hdfs://hadoop001:9000/usr/local/hadoop/tmp/mapred/staging/root/.staging/job_201312221708_0002
13/12/22 18:49:11 ERROR security.UserGroupInformation: PriviledgedActionException as:root cause:org.apache.hadoop.mapreduce.lib.input.InvalidInputException: Input path does not exist: file:/E:/hadoop/eclipse/workspace/WordCount/in
Exception in thread "main" org.apache.hadoop.mapreduce.lib.input.InvalidInputException: Input path does not exist: file:/E:/hadoop/eclipse/workspace/WordCount/in
at org.apache.hadoop.mapreduce.lib.input.FileInputFormat.listStatus(FileInputFormat.java:235)
at org.apache.hadoop.mapreduce.lib.input.FileInputFormat.getSplits(FileInputFormat.java:252)
at org.apache.hadoop.mapred.JobClient.writeNewSplits(JobClient.java:1024)
at org.apache.hadoop.mapred.JobClient.writeSplits(JobClient.java:1041)
at org.apache.hadoop.mapred.JobClient.access$700(JobClient.java:179)
at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:959)
at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:912)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Unknown Source)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1149)
at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:912)
at org.apache.hadoop.mapreduce.Job.submit(Job.java:500)
at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:530)
at org.apache.hadoop.examples.WordCount.main(WordCount.java:69)


解決辦法:

搗鼓了一整天終於找到解決的辦法了,原來是我之前參考的《hadoop集羣第七期》http://www.cnblogs.com/xia520pi/archive/2012/05/20/2510723.html

注意第52和53行,然後運行的時候老是出錯,如前面所述的錯誤,然後百度了半天才知道是hadoop-core-1.1.2.jar這個包的問題,org.apache.hadoop.fs裏面的一個類名爲

FileUtl.class中的一個方法checkReturnValue搞的鬼,這個方法是檢查Windows下文件權限問題,在Linux下可以正常運行,不存在這樣的問題。

因此將此方法註釋掉就OK了,但是爲了方便,還是從網上重新找了hadoop-core-1.1.2.jar下載下來,將原先的hadoop-core-1.1.2.jar替換掉,然後再在eclipse裏面運行

wordcount.java就成功了。

紀念一下:


總結:網上別人寫的東西有好有壞,得學會親自動手解決。這裏我留下代碼修改後的hadoop-core-1.1.2.jar的下載地址,有需要的童鞋可以下載替換原先的jar包試試,嘿嘿!

http://download.csdn.net/detail/qq_417174491/6755193

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章