当前位置:网站首页>【yarn】Yarn container 日志清理
【yarn】Yarn container 日志清理
2022-07-06 09:15:00 【kiraraLou】
前言
今天整理一下 yarn Container
的日志清理机制。
一、container 日志目录结构
Yarn container
的日志目录结构如下图所示。
NodeManager
会在所有目录上为同一个应用程序建立相同的目录结构,并采用轮询的调度方式将这些目录分配给不同Container使用。每个Container将输出三类日志:
stdout
:使用标准输出函数打印的日志,比如Java中的System.out.print
输出的内容。stderr
:标准错误输出产生的日志信息。syslog
:使用log4j打印的日志信息,这是最常用的打印日志方式,默认情况下,YARN采用了这种方式打印日志,换句话说,通常情况下,只有这个文件中有内容,其他两个文件为空。
这个配置为 yarn.nodemanager.log-dirs
。
二、日志清理机制
由于NodeManager
将所有Container
的运行日志保存到本地磁盘上,因此,随着时间的积累,日志必将越来越多。为了避免大量Container
日志“撑爆”磁盘空间,NodeManager
将定期清理日志文件,该功能由组件LogHandler
(当前存在两种实现:NonAggregatingLogHandler
和LogAggregationService
)完成。
总起来说,NodeManager
提供了定期删除(由NonAggregatingLogHandler
实现)和日志聚集转存(由LogAggregation-Service
实现)两种日志清理机制,默认情况下,采用的是定期删除机制。
1. 定期删除
NodeManager
允许一个应用程序日志在磁盘上的保留时间为yarn.nodemanager.log.retain-seconds
(单位是秒,默认为3×60×60,即3小时),一旦超过该时间,NodeManager
会将该应用程序所有日志从磁盘上删除。
2. 日志聚集转存
除定期删除外,NodeManager
还提供了另一种日志处理方式——日志聚集转存[插图],管理员可通过将配置参数yarn.log-aggregation-enable
置为true
启用该功能。
该机制将HDFS作为日志聚集仓库,它将应用程序产生的日志上传到HDFS上,以便统一管理和维护。该机制由两阶段组成:文件上传和文件生命周期管理。
(1) 文件上传
当一个应用程序运行结束时,它产生的所有日志将被统一上传到HDFS上的${remoteRootLogDir}/${user}/${suffix}/${appid}
${remoteRootLogDir}
值由参数yarn.nodemanager.remote-app-log-dir
指定,默认是/tmp/logs
${user}
为应用程序拥有者${suffix}
值由参数yarn.nodemanager.remote-app-log-dir-suffix
指定,默认是"logs"${appid}
为应用程序ID
且同一个节点中所有日志保存到该目录中的同一个文件,这些文件以节点ID命名。
日志结构图如下图所示。
一旦日志全部上传到HDFS后,本地磁盘上的日志文件将被删除。此外,为了减少不必要的日志上传,NodeManager
允许用户指定要上传的日志类型。当前支持的日志类型有三种:
ALL_CONTAINERS
(上传所有Container
日志)APPLICATION_MASTER_ONLY
(仅上传ApplicationMaster
产生的日志)AM_AND_FAILED_CONTAINERS_ONLY
(上传ApplicationMaster
和运行失败的Container
产生的日志),默认情况下采用ALL_CONTAINERS
。
(2) 文件生命周期管理
转存到HDFS上的日志的生命周期不再由NodeManager
负责,而是由JobHistory
服务管理。比如对于MapReduce
计算框架而言,它专有的JobHistory
负责定期清理MapReduce
作业转存到HDFS
上的日志,每个日志文件最多存留时间为yarn.log-aggregation.retain-seconds
(单位是秒,默认为3×60×60,即3小时)。
用户可通过两种方式查看应用程序日志,一种是通过NodeManager的Web界面;另一种是通过Shell命令查看。
查看一个应用程序产生的所有日志,命令如下:
bin/yarn logs -applicationId application_130332321231_0001
查看一个Container 产生的日志,命令如下:
bin/yarn logs -applicationId application_130332321231_0001 -containerId container_130332321231_0002 -nodeAddress 127.0.0.1_45454
总结
Yarn Container
有本地删除和日志聚合转存删除两种机制。Yarn Contaioner
本地日志是由yarn.nodemanager.log.retain-seconds
控制。yarn.log-aggregation-enable
是开启日志聚合转存。- 转存后的日志由
yarn.log-aggregation.retain-seconds
控制。
边栏推荐
- Codeforces Round #771 (Div. 2)
- [download app for free]ineukernel OCR image data recognition and acquisition principle and product application
- Test objects involved in safety test
- [Blue Bridge Cup 2017 preliminary] grid division
- 數據庫高級學習筆記--SQL語句
- Library function -- (continuous update)
- 软件测试与质量学习笔记3--白盒测试
- Remember the interview algorithm of a company: find the number of times a number appears in an ordered array
- L2-004 is this a binary search tree? (25 points)
- Solution of deleting path variable by mistake
猜你喜欢
Vs2019 use wizard to generate an MFC Application
Solve the problem of installing failed building wheel for pilot
PHP - whether the setting error displays -php xxx When PHP executes, there is no code exception prompt
QT creator create button
Request object and response object analysis
打开浏览器的同时会在主页外同时打开芒果TV,抖音等网站
Windows下安装MongDB教程、Redis教程
vs2019 桌面程序快速入门
机器学习--人口普查数据分析
MySQL and C language connection (vs2019 version)
随机推荐
小L的试卷
[BSidesCF_2020]Had_a_bad_day
Number game
Some notes of MySQL
JDBC原理
天梯赛练习集题解LV1(all)
[Bluebridge cup 2020 preliminary] horizontal segmentation
报错解决 —— io.UnsupportedOperation: can‘t do nonzero end-relative seeks
Codeforces Round #753 (Div. 3)
QT creator shape
Classes in C #
Request object and response object analysis
neo4j安装教程
Machine learning notes week02 convolutional neural network
{一周总结}带你走进js知识的海洋
Learning question 1:127.0.0.1 refused our visit
L2-007 family real estate (25 points)
AcWing 1298. Solution to Cao Chong's pig raising problem
Image recognition - pyteseract TesseractNotFoundError: tesseract is not installed or it‘s not in your path
Project practice - background employee information management (add, delete, modify, check, login and exit)