Hadoop归档日志指南

概述

对于拥有大量YARN聚合日志的集群,将它们合并成hadoop归档文件有助于减少小文件数量,从而减轻NameNode的压力。该工具提供了一种简便的方法来实现这一点。hadoop归档中的聚合日志仍然可以被作业历史服务器和yarn logs命令读取。

有关hadoop归档的更多信息,请参阅Hadoop Archives Guide

如何归档日志

usage: mapred archive-logs
-force                         Force recreating the working directory if
                               an existing one is found. This should
                               only be used if you know that another
                               instance is not currently running
-help                          Prints this message
-maxEligibleApps <n>           The maximum number of eligible apps to
                               process (default: -1 (all))
-maxTotalLogsSize <megabytes>  The maximum total logs size (in
                               megabytes) required to be eligible
                               (default: 1024)
-memory <megabytes>            The amount of memory (in megabytes) for
                               each container (default: 1024)
-minNumberLogFiles <n>         The minimum number of log files required
                               to be eligible (default: 20)
-noProxy                       When specified, all processing will be
                               done as the user running this command (or
                               the YARN user if DefaultContainerExecutor
                               is in use). When not specified, all
                               processing will be done as the user who
                               owns that application; if the user
                               running this command is not allowed to
                               impersonate that user, it will fail
-verbose                       Print more details.

该工具仅支持在集群上一次运行一个实例,以防止冲突。它通过检查HDFS中yarn.nodemanager.remote-app-log-dir路径下是否存在名为archive-logs-work的目录来实现(默认路径:/tmp/logs/archive-logs-work)。如果由于某些原因该目录未被正确清理,导致工具拒绝运行,您可以使用-force选项强制运行。

-help 选项会打印出使用信息。

该工具通过执行以下流程工作:

  1. Determine the list of eligible applications, based on the following criteria:
    • 尚未归档
    • 其聚合状态已成功完成
    • 至少有 -minNumberLogFiles 个日志文件
    • 其日志文件总大小小于 -maxTotalLogsSize 兆字节
  2. 如果找到超过-maxEligibleApps个应用程序,最新的应用程序将被丢弃。它们可以在下次处理。
  3. 基于符合条件的应用程序生成一个shell脚本
  4. 分布式Shell程序使用上述脚本运行。它将使用-maxEligibleApps个容器运行,每个容器处理一个应用程序,并分配-memory兆字节内存。每个容器为单个应用程序运行hadoop archives命令,并用生成的归档文件替换其聚合日志文件。

-noProxy选项使工具以当前运行它的用户身份处理所有内容,如果使用DefaultContainerExecutor则以YARN用户身份处理。未指定时,所有处理将由拥有该应用程序的用户完成;如果运行此命令的用户不允许模拟该用户,则会失败。如果您希望管理员用户在不启用模拟的情况下处理所有聚合,这将非常有用。使用-noProxy时,生成的HAR文件将归运行该工具的用户所有,而非原始日志所有者。

-verbose 选项会让工具打印更多关于其操作的详细信息。

运行该工具的最终结果是,已处理应用程序的原始聚合日志文件将被包含所有这些日志的hadoop存档所替代。