一、概述
本文基于0.19.1分析得出,有一些是alibaba hadoop优化的部分。本文不涉及jobtracker及nodename元数据的部分,本文主要讲述一个任务在计算阶段大致产生的一些日志,及日志的一些问题。
[dragon.caol@hd19-vm1 logs]$ tree . |-- hadoop-dragon.caol-datanode-hd19-vm1.yunti.yh.aliyun.com.log |-- hadoop-dragon.caol-datanode-hd19-vm1.yunti.yh.aliyun.com.out |-- hadoop-dragon.caol-jobtracker-hd19-vm1.yunti.yh.aliyun.com.log |-- hadoop-dragon.caol-jobtracker-hd19-vm1.yunti.yh.aliyun.com.out |-- hadoop-dragon.caol-namenode-hd19-vm1.yunti.yh.aliyun.com.log |-- hadoop-dragon.caol-namenode-hd19-vm1.yunti.yh.aliyun.com.out |-- hadoop-dragon.caol-secondarynamenode-hd19-vm1.yunti.yh.aliyun.com.log |-- hadoop-dragon.caol-secondarynamenode-hd19-vm1.yunti.yh.aliyun.com.out |-- hadoop-dragon.caol-tasktracker-hd19-vm1.yunti.yh.aliyun.com.log |-- hadoop-dragon.caol-tasktracker-hd19-vm1.yunti.yh.aliyun.com.out |-- history `-- userlogs `-- toBeDeleted 3 directories, 10 files此时注意点,
307 HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.log.dir=$HADOOP_LOG_DIR" 308 HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.log.file=$HADOOP_LOGFILE" 309 HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.home.dir=$HADOOP_HOME" 310 HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.id.str=$HADOOP_IDENT_STRING" 311 HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.root.logger=${HADOOP_ROOT_LOGGER:-INFO,console}" 312 HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.root.logger.appender=${HADOOP_ROOT_LOGGER_APPENDER:-console}" 313 HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.root.logger.level=${HADOOP_ROOT_LOGGER_LEVEL:-info}"启动后 jobtracker的jvm参数为:
5537 JobTracker -Xmx1000m -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote -Xdebug -Xrunjdwp:transport=dt_socket,address=1314,server=y,suspend=n -Dhadoop.log.dir=/home/dragon.caol/hadoop-0.19.1-dc/bin/../logs -Dhadoop.log.file=hadoop-dragon.caol-jobtracker-hd19-vm1.yunti.yh.aliyun.com.log -Dhadoop.home.dir=/home/dragon.caol/hadoop-0.19.1-dc/bin/.. -Dhadoop.id.str=dragon.caol -Dhadoop.root.logger=INFO,RFA -Dhadoop.root.logger.appender=RFA -Dhadoop.root.logger.level=info -Djava.library.path=/home/dragon.caol/hadoop-0.19.1-dc/bin/../lib/native/Linux-amd64-64用此些配置共同来拼装log4j的配置。
[dragon.caol@hd19-vm1 logs]$ tree . |-- hadoop-dragon.caol-datanode-hd19-vm1.yunti.yh.aliyun.com.log |-- hadoop-dragon.caol-datanode-hd19-vm1.yunti.yh.aliyun.com.out |-- hadoop-dragon.caol-jobtracker-hd19-vm1.yunti.yh.aliyun.com.log |-- hadoop-dragon.caol-jobtracker-hd19-vm1.yunti.yh.aliyun.com.out |-- hadoop-dragon.caol-namenode-hd19-vm1.yunti.yh.aliyun.com.log |-- hadoop-dragon.caol-namenode-hd19-vm1.yunti.yh.aliyun.com.out |-- hadoop-dragon.caol-secondarynamenode-hd19-vm1.yunti.yh.aliyun.com.log |-- hadoop-dragon.caol-secondarynamenode-hd19-vm1.yunti.yh.aliyun.com.out |-- hadoop-dragon.caol-tasktracker-hd19-vm1.yunti.yh.aliyun.com.log |-- hadoop-dragon.caol-tasktracker-hd19-vm1.yunti.yh.aliyun.com.out |-- history | |-- h1_1348474254849_job_201209241610_0001_conf.xml | `-- h1_1348474254849_job_201209241610_0001_dragon.caol_word+count |-- history.idx |-- job_201209241610_0001_conf.xml `-- userlogs |-- job_201209241610_0001 | |-- attempt_201209241610_0001_m_000000_0 | | |-- log.index | | |-- stderr | | |-- stdout | | `-- syslog | |-- attempt_201209241610_0001_m_000001_0 | | |-- log.index | | |-- stderr | | |-- stdout | | `-- syslog | |-- attempt_201209241610_0001_m_000002_0 | | |-- log.index | | |-- stderr | | |-- stdout | | `-- syslog | `-- attempt_201209241610_0001_r_000000_0 | |-- log.index | |-- stderr | |-- stdout | `-- syslog `-- toBeDeleted 8 directories, 30 files我们看出在 history、userlogs有子文件了,且多出了 history.idx、job_201209241610_0001_conf.xml文件。此些文件其实是框架在不同的时期产生的。有的是索引文件,基本是为了供页面查询的。在一段时间后会删除。
import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; /** * limit writing data. if writing data size has reached limit,system writes log * message and throws IOException * * @author dragon.caol * @date 2012-09-21 * */ public class LimitOutputSteam extends FilterOutputStream { private long remaining; private String msg; private boolean limit = Boolean.FALSE; private boolean isRestriction = Boolean.FALSE; public LimitOutputSteam(OutputStream out, long maxSize) { super(out); if (maxSize > 0) { this.isRestriction = Boolean.TRUE; this.remaining = maxSize; this.msg = "\nException:Written to stdout or stderr cann't exceed " + ((float) maxSize / 1024) + "kb. \n"; } } public void write(int b) throws IOException { if (isRestriction) { if (!limit) { if (remaining-- > 0) { super.write(b); } else { for (int i = 0; i < msg.length(); i++) { super.write(msg.getBytes()[i]); } this.limit = Boolean.TRUE; throw new LimitOutputSteamException(msg); } } } else { super.write(b); } } }三、HDFS中的JobHistroy日志