日誌輪滾實戰舉例
[root@server123 ~]# cd /etc/logrotate.d/
[root@server123 logrotate.d]# vim secure
/usr/local/secure {
sharedscripts 開始
prerotate 輪滾之前做的事
/usr/bin/chattr -a /usr/local/secure 減掉a屬性
endscript 結束
missingok 丟失無所謂,繼續輪滾
notifempty 空日誌文件,不輪滾
daily 一天一輪滾
create 輪滾之後創建空的日誌文件
rotate 4 保留四個舊的日誌文件
compress 壓縮日誌
sharedscripts 開始
postrotate 輪滾之後做的事
/bin/kill -HUP `cat /var/run/syslogd.pid` 重新讀取rsyslogd的進程
/usr/bin/chattr +a /usr/local/secure 把a屬性加上
endscript 結束
}
[root@server123 logrotate.d]# vim /etc/rsyslog.conf
authpriv.* /var/log/secure
authpriv.* /usr/local/secure
服務重啓
[root@server123 logrotate.d]# /etc/init.d/rsyslog restart
[root@server123 logrotate.d]# ll /usr/local
secure
[root@server123 local]# chattr +a secure
[root@server123 local]# ll secure
-rw-------. 1 root root 814 Oct 21 15:35 secure
[root@server123 local]# lsattr secure
-----a-------e- secure
手動的輪滾
[root@server123 local]# logrotate -vf /etc/logrotate.d/secure
[root@server123local]# ll secure*
-rw-------. 1 root root 323 Oct 21 16:31 secure
-rw-------. 1 root root 258 Oct 21 16:30 secure.1.gz
[root@server254 local]# ll secure*
-rw-------. 1 root root 0 Oct 21 16:31 secure
-rw-------. 1 root root 188 Oct 21 16:31 secure.1.gz
-rw-------. 1 root root 258 Oct 21 16:30 secure.2.gz