纱线标准错误没有记录器附加程序,也没有标准输出



我在Apache Hadoop 2.6.0上运行一个简单的mapreduce程序wordcount。hadoop是分布式运行的(多个节点)。然而,我无法从纱线工作历史中看到任何错误和标准。(但我可以看到syslog)

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"one_answers"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上搜索过。有些人提到了容器-log4j。属性,但它们并不具体说明如何配置该文件以及将其放在何处。

需要注意的是,我也在Hortonworks数据平台2.2和Cloudera 5.4上尝试了这项工作。结果是一样的。我记得当我处理一些以前版本的hadoop (hadoop 1.x)时,我可以很容易地从同一个地方看到日志记录。我猜这是hadoop 2.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函数被调用")是我所期望的hadoop服务器日志。

所有用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。

相关内容

  • 没有找到相关文章

最新更新