纱线stderr没有记录器appender和没有stdout

时间:2015-09-08 23:02:04

标签: hadoop mapreduce cloudera yarn hortonworks-data-platform

我正在运行一个简单的mapreduce程序wordcount agian Apache Hadoop 2.6.0。 hadoop分布式运行(几个节点)。但是,我无法从纱线工作历史中看到任何stderr和stdout。 (但我可以看到系统日志)

wordcount程序非常简单,仅用于演示目的。

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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 final Log LOG = LogFactory.getLog(WordCount.class);

  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 {
      LOG.info("LOG - map function invoked");
      System.out.println("stdout - map function invoded");
      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();
      conf.set("mapreduce.job.jar","/space/tmp/jar/wordCount.jar");
      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("hdfs://localhost:9000/user/jsun/input"));              
      FileOutputFormat.setOutputPath(job, new Path("hdfs://localhost:9000/user/jsun/output"));

      System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
  }

注意在Mapper类的map函数中,我添加了两个语句:

LOG.info("LOG - map function invoked");
System.out.println("stdout - map function invoded");

这两个语句用于测试我是否可以看到来自hadoop服务器的日志记录。我可以成功运行该程序。但是如果我去localhost:8088查看应用程序历史记录然后“登录”,我在“stdout”和“stderr”中看不到任何内容:

log4j:WARN No appenders could be found for logger (org.apache.hadoop.ipc.Server).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

我认为需要一些配置才能获得这些输出,但不确定缺少哪一条信息。我在线搜索以及在stackoverflow中搜索。有些人提到了container-log4j.properties,但它们没有具体说明如何配置该文件以及放置位置。

有一点需要注意的是,我还尝试使用Hortonworks Data Platform 2.2和Cloudera 5.4。结果是一样的。我记得当我处理一些先前版本的hadoop(hadoop 1.x)时,我可以很容易地看到来自同一地方的记录。所以我想这是hadoop 2.x中的新功能

=======

作为比较,如果我让apache hadoop以本地模式运行(意味着LocalJobRunner),我可以在控制台中看到一些loggings,如下所示:

[2015-09-08 15:57:25,992]org.apache.hadoop.mapred.MapTask$MapOutputBuffer.init(MapTask.java:998) INFO:kvstart = 26214396; length = 6553600
[2015-09-08 15:57:25,996]org.apache.hadoop.mapred.MapTask.createSortingCollector(MapTask.java:402) INFO:Map output collector class = org.apache.hadoop.mapred.MapTask$MapOutputBuffer
[2015-09-08 15:57:26,064]WordCount$TokenizerMapper.map(WordCount.java:28) INFO:LOG - map function invoked
stdout - map function invoded
[2015-09-08 15:57:26,075]org.apache.hadoop.mapred.LocalJobRunner$Job.statusUpdate(LocalJobRunner.java:591) INFO:
[2015-09-08 15:57:26,077]org.apache.hadoop.mapred.MapTask$MapOutputBuffer.flush(MapTask.java:1457) INFO:Starting flush of map output
[2015-09-08 15:57:26,077]org.apache.hadoop.mapred.MapTask$MapOutputBuffer.flush(MapTask.java:1475) INFO:Spilling map output

这些记录(“调用map函数”)是我在hadoop服务器日志记录中的预期。

1 个答案:

答案 0 :(得分:1)

在Map-Reduce程序中编写的所有sysout都无法在控制台上看到。这是因为map-reduce在群集中的多个并行副本中运行,因此没有一个带输出的控制台的概念。

但是,可以在作业日志中看到map和reduce阶段的System.out.println()。访问日志的简便方法是

open the jobtracker web console - http://localhost:50030/jobtracker.jsp
click on the completed job
click on map or reduce task
click on tasknumber
Go to task logs
Check stdout logs.

请注意,如果您无法找到网址,只需查看控制台日志中的jobtracker网址。