HADOOP-2.6.0中MapReduce job不工作



我正在尝试运行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

我遇到了这篇文章Wordcount程序卡在hadoop-2.3.0但是解决方案对我不起作用

终于解决了这个问题。我需要在yarn-site.xml

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

您使用的是Hadoop 2.6,使用的是mapred包。我认为新的包名包括mapreduce。请按照下面的示例运行正确的版本。您还可以使用link1和link2来理解

这两个 之间的区别。

相关内容

  • 没有找到相关文章

最新更新