1.系統是預設安裝的,查看系統是否安裝logrotate centos rpm -ql logrotate /etc/cron.daily/logrotate /etc/logrotate.conf /etc/logrotate.d /etc/rwtab.d/logrotate /usr/sbin/ ...
1.系統是預設安裝的,查看系統是否安裝logrotate
centos
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
ubuntu
logrotate --version
logrotate 3.14.0
Default mail command: /usr/bin/mail
Default compress command: /bin/gzip
Default uncompress command: /bin/gunzip
Default compress extension: .gz
Default state file path: /var/lib/logrotate/status
ACL support: yes
SELinux support: yes
2.docker配置日誌截取
創建文件
/etc/docker/daemon.json
內容
{
"log-driver": "json-file",
"log-opts": {
"max-size": "500m",
"max-file": "3"
}
}
max-size 指定日誌文件大小上限
max-file 指定日誌文件個數
systemctl daemon-reload
systemctl restart docker.service
3.創建logrotate 配置文件,系統會自動創建 crontab 任務自動執行
/etc/logrotate.d/nginx
/work/nginx/logs/*log {
su root root
create 0644 root root
daily #每天執行一次
rotate 365 #保留365個日誌文件
missingok #如果日誌丟失,不報錯繼續滾動下一個日誌
notifempty #當日誌文件為空時不生成新的文件
compress #壓縮
sharedscripts #統一執行一次腳本postrotate
postrotate #運行腳本
docker exec nginx nginx -s reload;
endscript
}
手動測試logrotate
logrotate -d -f /etc/logrotate.d/nginx
-d, --debug :debug模式,測試配置文件是否有錯誤。
-f, --force :強制轉儲文件。
4.推薦博客:
https://www.cnblogs.com/kevingrace/p/6307298.html