yarn stderr没有记录器附加器也没有stdout

gkn4icbw  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(496)

我正在运行一个简单的mapreduce程序wordcount agian apache hadoop 2.6.0。hadoop是分布式运行的(几个节点)。然而,我无法从工作经历中看到任何标准和标准(但我可以看到系统日志)
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 to 查看应用程序历史记录,然后查看“日志”,我在“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数据平台2.2和cloudera 5.4。结果是一样的。我记得当我处理一些以前版本的hadoop(hadoop1.x)时,我可以很容易地从同一个地方看到日志。所以我猜这是Hadoop2.x中的新东西

作为比较,如果我让apache hadoop在本地模式下运行(意味着localjobrunner),我可以在控制台中看到如下日志:

[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 function is invoked”)正是我在hadoop服务器日志中所期望的。

3pmvbmvn

3pmvbmvn1#

所有在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.

请注意,如果您找不到url,只需查看jobtracker url的控制台日志。

相关问题