MapReduce 作业在 HADOOP-2.6.0 中不起作用

MapReduce job not working in HADOOP-2.6.0

我正在尝试 运行 wordcount 示例

这是代码

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

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class WordCount {

  public static class TokenizerMapper
       extends Mapper<Object, Text, Text, IntWritable>{

    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();

    public void map(Object key, Text value, Context context
                    ) throws IOException, InterruptedException {
      StringTokenizer itr = new StringTokenizer(value.toString());
      while (itr.hasMoreTokens()) {
        word.set(itr.nextToken());
        context.write(word, one);
      }
    }
  }

  public static class IntSumReducer
       extends Reducer<Text,IntWritable,Text,IntWritable> {
    private IntWritable result = new IntWritable();

    public void reduce(Text key, Iterable<IntWritable> values,
                       Context context
                       ) throws IOException, InterruptedException {
      int sum = 0;
      for (IntWritable val : values) {
        sum += val.get();
      }
      result.set(sum);
      context.write(key, result);
    }
  }

  public static void main(String[] args) throws Exception {
    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);
    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
  }
}

我看到了

    15/06/05 02:32:04 INFO client.RMProxy: Connecting to ResourceManager at /0.0.0.0:8032
15/06/05 02:32:04 WARN mapreduce.JobSubmitter: Hadoop command-line option parsing not performed. Implement the Tool interface and execute your application with ToolRunner to remedy this.
15/06/05 02:32:04 INFO input.FileInputFormat: Total input paths to process : 2
15/06/05 02:32:05 INFO mapreduce.JobSubmitter: number of splits:2
15/06/05 02:32:05 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1433448750700_0003
15/06/05 02:32:05 INFO impl.YarnClientImpl: Submitted application application_1433448750700_0003
15/06/05 02:32:05 INFO mapreduce.Job: The url to track the job: http://localhost:8088/proxy/application_1433448750700_0003/
15/06/05 02:32:05 INFO mapreduce.Job: Running job: job_1433448750700_0003

我遇到了这个 post Wordcount program is stuck in hadoop-2.3.0 但是解决方案对我不起作用

您正在使用 Hadoop 2.6 并使用 mapred 包。我认为新的包名称包括 mapreduce。请按照示例here to run correct version. Also you can use link1 and link2了解两者的区别

最后,我解决了这个问题。我需要在 yarn-site.xml

中添加以下 属性
 <property>
        <name>yarn.resourcemanager.hostname</name>
        <value>Hostname-of-your-RM</value>
        <description>The hostname of the RM.</description>
    </property>

这应该可以解决您的问题。