Hadoop 封存檔記錄指南

概述

對於具有大量 YARN 彙總記錄的叢集,將它們組合到 Hadoop 封存檔中以減少小檔案的數量,從而減輕 NameNode 的壓力會很有幫助。此工具提供了一個簡單的方法來執行此操作。Hadoop 封存檔中的彙總記錄仍可由工作記錄伺服器和 yarn logs 命令讀取。

有關 Hadoop 封存檔的更多資訊,請參閱 Hadoop 封存檔指南

如何封存記錄

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. 根據下列準則確定符合資格的應用程式清單
    • 尚未封存
    • 其彙總狀態已成功完成
    • 至少有 -minNumberLogFiles 個記錄檔
    • 其日誌檔大小總和小於 -maxTotalLogsSize 兆位元組
  2. 如果找到的應用程式多於 -maxEligibleApps 個,會捨棄最新的應用程式。它們可以在下次處理。
  3. 根據符合資格的應用程式產生 shell 指令碼
  4. 使用上述指令碼執行 Distributed Shell 程式。它將使用 -maxEligibleApps 個容器執行,每個容器處理一個應用程式,並使用 -memory 兆位元組的記憶體。每個容器針對單一應用程式執行 hadoop archives 指令,並使用產生的封存檔取代其彙總的日誌檔。

-noProxy 選項會讓工具將所有處理程序視為目前執行它的使用者,或在使用 DefaultContainerExecutor 時視為 YARN 使用者。未指定時,所有處理程序都將由擁有該應用程式的使用者執行;如果執行此指令的使用者無法偽裝成該使用者,則會失敗。如果您希望管理員使用者在未啟用偽裝的情況下處理所有彙總,這會很有用。使用 -noProxy 時,產生的 HAR 檔將由執行工具的使用者擁有,而不是原本擁有日誌的使用者。

-verbose 選項會讓工具列印更多關於其執行的詳細資訊。

執行工具的最終結果是,已處理應用程式的原始彙總日誌檔將被包含所有這些日誌的 Hadoop 封存檔取代。