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 ...
随机推荐
- vue项目运行出现warnings potentially fixable with the `--fix` option的报错问题
vue-cil3 运行报错 warnings potentially fixable with the `--fix` option. 解决办法:"lint": "vue ...
- JavaScript逗号运算符的用法
var a = 3, b b = (a++, a) 与 var a = 3, b b = a++ 区别
- concat()函数
该函数可以将多个字符串连成一个字符串.使用语法concat(str1, str2, ...)返回结果参数拼接成的字符串,如果有任何一个参数为null,则返回值为null例子1.从person表查出数据 ...
- Kubernetes之Pod详解
1.Pod生命周期 pod创建 1. API Server 在接收到创建pod的请求之后,会根据用户提交的参数值来创建一个运行时的pod对象. 2. 根据 API Server 请求的上下文的元数据来 ...
- zabbix 监控域名到期时间
cat userparameter_http.conf UserParameter=http_discovery,/usr/bin/python /etc/zabbix/scripts/base/ht ...
- Word04 公司战略规划文档office真题
1.课程的讲解之前,先来对题目进行分析,首先需要在考生文件夹下,将Wrod素材.docx文件另存为Word.docx,后续操作均基于此文件,否则不得分. 2.这一步非常的简单,打开下载素材文件,在 ...
- Mysql数据库基础第二章:(五)分组查询
Mysql数据库基础系列 软件下载地址 提取码:7v7u 数据下载地址 提取码:e6p9 mysql数据库基础第一章:(一)数据库基本概念 mysql数据库基础第一章:(二)mysql环境搭建 mys ...
- antd DatePicker限制日期的选择
import React from 'react'; import ReactDOM from 'react-dom'; import {Input,DatePicker,Form,Col,Butto ...
- wxPython绘图API
简单介绍一个Pthon的绘图库wxPython. GDI+(图形绘制接口),CoreGraphics和Cairo库形成wxPython绘图API的框架.wx.GraphicsContext是主要绘制对 ...
- 关于promise经典面试题
这里涉及到同步和异步的问题