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 ...
随机推荐
- redis 和docker等名词了解
redis redis产生 redis是MySQL数据库经常直接面对大量的读写访问,面对比较复杂的数据据操作,会导致数据库I/O反映缓慢或者奔溃: 有人研究学习CPU从内寸直接读取数据,把MYSQL经 ...
- fftw安装
1. 下载fftw 2.tar -zxvf fftw.tar.gz 3. ./configure --prefix=path --enable-sse2 --enable-avx --enable-f ...
- Python学习笔记调试之取得反向跟踪的字符串
随笔记录方便自己和同路人查阅. #------------------------------------------------我是可耻的分割线--------------------------- ...
- Oracle 会话锁死
需要管理员用户下执行(sys/sysdba) --先查锁 select * from v$lock where lmode > 0 and type in ('TM','TX'); --查用户名 ...
- vue-quill-editor 图片上传处理
<template> <div class="quill-editor"> <!-- 图片上传组件辅助--> <el-upload cla ...
- continue练习
using System; namespace continue_的练习 { class Program { static void Main(string[] args) { int sum = 0 ...
- Python 集合常用方法
数据类型:int/str/bool/list/dict/tuple/float/set (set类型天生去重) 一.集合的定义 s = set() #定义空集合 s = {'a','b','c' ...
- MySQL 常用命令(1)------连接、添加用户与授权
一.连接MySQL 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MYSQL 进入目录mysql\bin,再键入命令mysql -u root -p,回车后提示你输密码 ...
- 045_List view button
http://www.interactiveties.com/b_execute_javascript_button.php https://developer.salesforce.com/foru ...
- OSS管理文件(Node.js)
let OSS = require('ali-oss'); let config = { region: 'oss-cn-hangzhou', //你的Region 注意 这个只要 空间名 不要 ht ...