實戰:logrotate 日誌輪轉及配置vim
1,編寫系統日誌的配置文件 /etc/rsyslog.confthis
2,寫入配置spa
[root@A logrotate.d]# cat /etc/rsyslog.conf.net
# rsyslog v5 configuration filerest
*.* /var/log/admin.log(全部的服務,全部級別的日誌所有寫入到此路徑下面)日誌
3,重啓rsyslog服務,檢查而且查看是否有日誌生成orm
[root@A logrotate.d]# ll /var/log/admin.logget
-rw-------. 1 root root 0 Sep 4 01:38 /var/log/admin.logit
[root@A logrotate.d]# /etc/init.d/rsyslog restartio
4,查看日誌輪轉配置文件。以及相關的格式
[root@A logrotate.d]# cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d (調用子配置文件,一般把日誌的策略放在此路徑下,方便管理)
5,在/etc/logrorate.d 路徑下爲系統日誌/var/log/admin.log 建立策略
vim /etc/logrorate.d/admin
[root@A logrotate.d]# cat admin
/var/log/admin.log {
daily 天天輪轉
rotate 3 保留3個備份
minsize 100k 大小至少100k纔開始輪轉
missingok 丟失不提示
compress 壓縮文件
create 0600 root root 建新文件並設權
dateext 日誌文件以日期命名
}
6,能夠強制檢測,輪轉策略是否生效
logrotate -f /etc/logrorate.d/admin
[root@A logrotate.d]# ll /var/log/admin*
-rw-------. 1 root root 0 Sep 4 01:38 /var/log/admin.log
-rw-------. 1 root root 469 Sep 4 01:38 /var/log/admin.log.1
-rw-------. 1 root root 187 Sep 4 01:38 /var/log/admin.log-20170904.gz