疑問:今天發(fā)現(xiàn)生產(chǎn)服務(wù)器的nginx access.log會(huì)按天自動(dòng)切割并壓縮,感到奇怪祟霍,我并沒有跑日志切割的腳本
仔細(xì)檢查后發(fā)現(xiàn)是因?yàn)榉?wù)器啟動(dòng)了一個(gè)日志切割的服務(wù),logrotate
查詢資料發(fā)現(xiàn)如果是yum方式安裝的nginx香到,系統(tǒng)默認(rèn)會(huì)自動(dòng)通過logrotate這個(gè)日志管理軟件挑童,按天進(jìn)行分割。
查看 logrotate 在服務(wù)器中的文件位置
[root@centos7-node1 ~]# rpm -ql logrotate
/etc/cron.daily/logrotate
/etc/logrotate.conf
/etc/logrotate.d
/etc/rwtab.d/logrotate
/usr/sbin/logrotate
/usr/share/doc/logrotate-3.8.6
/usr/share/doc/logrotate-3.8.6/CHANGES
/usr/share/doc/logrotate-3.8.6/COPYING
/usr/share/man/man5/logrotate.conf.5.gz
/usr/share/man/man8/logrotate.8.gz
/var/lib/logrotate
/var/lib/logrotate/logrotate.status
logrotate的配置文件:
/etc/logrotate.conf
/etc/logrotate.d
查看/etc/logrotate.d的文件糕非,有一個(gè)Nginx的配置
[root@centos7-node1 logrotate.d]# ls
bootlog chrony nginx syslog wpa_supplicant yum
日志分割是通過如下配置完成的
[root@centos7-node1 logrotate.d]# cat nginx
/var/log/nginx/*.log {
daily
missingok
rotate 52
compress
delaycompress
notifempty
create 640 nginx adm
sharedscripts
postrotate
if [ -f /var/run/nginx.pid ]; then
kill -USR1 `cat /var/run/nginx.pid`
fi
endscript
}