logrotate linux 系统日志管理
logrotate简介
logrotate [-dv] [-f|--force] [-s|--state statefile] config_file ..
# logrotate --help
Usage: logrotate [OPTION...] <configfile>
-d, --debug Don't do anything, just test (implies -v) 不做实际处理,仅调试
-f, --force Force file rotation 强制执行,忽视参数要求
-m, --mail=command Command to send mail (instead of `/bin/mail') 发送mail
-s, --state=statefile Path of state file 查看状态文件
-v, --verbose Display messages during rotation 轮替一次,并显示轮替过程信息
--version Display version information 显示logrotate版本
-?, --help Show this help message
--usage Display brief usage message
/etc/logrotate.conf
/etc/logrotate.d
/etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly 每周轮替一次
weekly
rotate 4
create
dateext
#compress
include /etc/logrotate.d
/var/log/wtmp { #轮替对象为/var/log/中的wtmp文件
monthly #每个月轮替一次
create 0664 root utmp #创建新的日志文件 权限 所属用户 所属组
minsize 1M #日志大小大于1M后才能参与轮替
rotate 1 #保留一个轮替日志文件
}
missingok #如果日志文件不存在,继续进行下一个操作,不报错
monthly
create 0600 root utmp
rotate 1
}
/etc/logrotate.d
/etc/logrotate.d如上面说到的,在logrotate配置中扮演一个目录的角色,通过logrotate.conf中的配置include /etc/logrotate.d将/etc/logrotate.d目录包含进来,即将该目录下的文件内容加入到轮替任务中。
这里先简单介绍一下该目录下的文件内容及其格式,后面再对具体案例进行分析。
格式
日志文件路径 ...{ #多个文件绝对路径路径可以用空格、换行分隔,
参数配置
}
/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler #作用域:/var/log/目录下的cron、maillog、messages、secure和spooler文件
{
missingok
sharedscripts #作用域下文件存在至少有一个满足轮替条件的时候,完成轮替后执行一次postrotate内的脚本。
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}
描述
daily
每天轮替一次
weekly
每周轮替一次
monthly
每月轮替一次
yearly
每年轮替一次
rotate
保留几个轮替日志文件
ifempty
不论日志是否空,都进行轮替
notifempty
若日志为空,则不进行轮替
create
旧日志文件轮替后创建新的日志文件
size
日志达到多少后进行rotate
minsize
文件容量一定要超过多少后才进行rotate
nocompress
轮替但不进行压缩
compress
压缩轮替文件
dateext
轮替旧日志文件时,文件名添加-%Y %m %d形式日期,可用dateformat选项扩展配置。
nodateext
旧日志文件不使用dateext扩展名,后面序数自增如"*.log.1"
dateformat
只允许%Y %m %d和%s指定符。注意:系统时钟需要设置到2001-09-09之后,%s才可以正确工作
sharedscripts
作用域下文件存在至少有一个满足轮替条件的时候,执行一次prerotate脚本和postrotate脚本。
prerotate/endscript
在轮替之前执行之间的命令,prerotate与endscript成对出现。
postrotate/endscript
在轮替之后执行之间的命令,postrotate与endscript成对出现。
olddir
将轮替的文件移至指定目录下
missingok
如果日志文件不存在,继续进行下一个操作,不报错
#/etc/logrotate.d/test
/test/log/*.log{
daily
rotate 2
size 1M
create
compress
missingok
dateext
olddir /test/rotate
}
例行性工作的简单配置使用
cron执行时会读取/etc/cron.d这个目录的所有文件,按照文件中的设置来定时执行任务。该目录下新增的文件后,无需再重启crond服务。这里只简单地介绍该种定时任务配置。
#格式
*(分钟) *(小时) *(天) *(月) *(周几) 用户 命令
# 若分钟位值为 *,表示0-59之间的任意有效值;
# 若分钟位值为 1,表示每小时的第1分钟;
# 若分钟位值为 */5,表示每5分钟
# 若分钟位值为10,20 表示每小时的第10分钟和第20分钟
# 若分钟位值为10-12 表示每小时的第10、11、12分钟
* */1 * * * root /usr/sbin/logrotate -v /etc/logrotate.d/test
monthly
rotate 12
create
dateext
include /etc/logrotate.d
/var/log/wtmp {
monthly
create 0664 root utmp
rotate 12
}
monthly
create 0600 root utmp
rotate 12
}
monthly
create 0600 root utmp
rotate 12
}
monthly
create 0600 root utmp
rotate 12
}
monthly
create 0600 root utmp
rotate 12
}
# system-specific logs may be also be configured here.
#/etc/logrotate.d/log_cron (文件名log_cron)
* * * * 1 /usr/sbin/logrotate -fv /etc/logrotate.d/log_cron
monthly
dateext
create 0664 root utmp
rotate 12
}
monthly
dateext
create 0600 root utmp
rotate 12
}
monthly
dateext
create 0600 root utmp
rotate 12
}
monthly
dateext
create 0600 root utmp
rotate 12
}
monthly
dateext
create 0600 root utmp
rotate 12
}
logrotate linux 系统日志管理的更多相关文章
- :Linux 系统日志管理 日志转储
Linux日志服务器设置 使用“@IP:端口”或“@@IP:端口”的格式可以把日志发送到远程主机上. 假设需要管理几十台服务器,每天的重要工作就是查看这些服务器的日志,可是每台服务器单独登录,并且查看 ...
- Linux 系统日志管理 rsyslogd配置文件
rsyslogd配置文件 rsyslogd 服务是依赖其配置文件 /etc/rsyslog.conf 来确定哪个服务的什么等级的日志信息会被记录在哪个位置的.也就是说,日志服务的配置文件中主要定义了 ...
- Linux 系统日志管理
Linux rsyslogd服务及启动方法 在 CentOS 6.x 中,日志服务已经由 rsyslogd 取代了原先的 syslogd.Red Hat 公司认为 syslogd 已经不能满足工作中的 ...
- Linux系统日志管理
1.系统常用的日志(日志是用来记录重大事件的工具) /var/log/message 系统信息日志,包含错误信息等 /var/log/secure 系统登录日志 /var/l ...
- 【CentOS】Linux日常管理
/////////////////////////目录///////////////////////////////////////// 一.日常监控指标相关 1.监控系统状态命令 2.查看系统进程 ...
- Linux系统日志及日志分析
Linux系统日志及日志分析 Linux系统拥有非常灵活和强大的日志功能,可以保存几乎所有的操作记录,并可以从中检索出我们需要的信息. 大部分Linux发行版默认的日志守护进程为 syslog,位 ...
- rsync 通过服务的方式同步 linux系统日志 screen工具
rsync 通过服务的方式同步 俩台机器传文件IP地址交叉编写. 主机1: 要编辑配置文件 /etc/rsyncd.conf rsyncd.conf样例 port=873 ...
- rsync通过服务同步、Linux系统日志、screen工具 使用介绍
第8周5月15日任务 课程内容: 10.32/10.33 rsync通过服务同步10.34 linux系统日志10.35 screen工具 扩展1. Linux日志文件总管logrotate http ...
- Linux CentOS7 rsync通过服务同步、linux系统日志、screen工具
一.rsync通过服务同步 rsyncd.conf配置文件详解 port:指定在哪个端口启动rsyncd服务,默认是873端口. log file:指定日志文件. pid file:指定pid文件,这 ...
- linux 内存管理——内核的shmall 和shmmax 参数
内核的 shmall 和 shmmax 参数 SHMMAX= 配置了最大的内存segment的大小 ------>这个设置的比SGA_MAX_SIZE大比较好. SHMMIN= 最小的内存seg ...
随机推荐
- 吴恩达老师机器学习课程chapter09——异常检测
吴恩达老师机器学习课程chapter09--异常检测 本文是非计算机专业新手的自学笔记,高手勿喷. 本文仅作速查备忘之用,对应吴恩达(AndrewNg)老师的机器学期课程第十五章. 目录 吴恩达老师机 ...
- 从COM域名即将涨价看如何控制域名成本问题
我们很多站长在上周的时候应该陆续有收到各大域名注册商的推送邮件,将会在今年9月1日开始COM域名会涨价,当然涨价的福利也不是很大.标价大约是会到每个每年增加至9.99美元.可能我们有一些网友要说,有些 ...
- Flink Application Development DataStream API Execution Mode (Batch/Streaming)- Flink应用程序开发DataStream API执行模式(批/流)
目录 什么时候可以/应该使用BATCH执行模式? 配置BATCH执行模式 执行行为 任务调度和网络随机shuffle 流执行模式 批处理执行模式 状态后端/状态 处理顺序 Event Time/水印( ...
- Finance财务软件(权限管理专题)
我们支持按模块对用户授权 如上所示,我们对用户test进行授权.test登录系统后将看不到未授权的菜单:
- Unity中的深度测试相关知识与问题
https://www.jianshu.com/p/f420b55edd0b?utm_campaign=hugo
- view 相关代码片段笔记
代码中动态创建view,并把AttributeSet加入到当前自定义的view中,动态创建属性相关 //https://blog.csdn.net/chenhuakang/article/detail ...
- libmodbus 源码分析转
记录一下,这位大神分析的很到位,值得膜拜! < libmodbus协议栈1--Linux下详细移植步骤(配置.生成) > < libmodbus协议栈2-- Linux下 modbu ...
- CORE8051-APB总线
1 APB总线 core8051s内核支持APB3总线,APB writebuffer 为{XWB3, XWB2, XWB1, ACC}; 写访问 对FC00以上地址写值,即表示APB写操作,值为(X ...
- webstrom配置ES6 file watch没有生效
参考了文章https://www.cnblogs.com/kiimi/p/8663467.html设置后,依然没有看到编译后的文件,然后设置了输出文件夹为当前项目,再重启webstrom就看到了--
- 01、kafka常用命令
001.kafka版本 kafka_2.13-3.0.0 kafka_2.12-2.8.0 002.模拟给topic名称是 yikuang 的发一条数据(hello world) ./kafka-co ...