logrotate按時間切割supervisor日志


需要分別配置logrotate和supervisor

1. 配置logrotate

[root@node1 logrotate.d]# cat /etc/logrotate.d/netqps 
/root/netqps/files/*log {  #指定要切割日志的路徑,並指定日志結尾,便於匹配
    rotate 100    #最多保存100個歸檔日志
    missingok     #允許要切割的日志不存在
    copytruncate  #必須  在切割日志時先備份日志,然后再清空日志文件,這樣可以保證日志inode不變,不用重啟程序
    notifempty    #如果日志為空文件,不切割
    dateext       #使用日期做日志結尾
    dateformat  .%Y%m%d_%H_%m_%s  #日期結尾的格式
    delaycompress #延遲壓縮,最近切割出來的日志不會被壓縮,等下一次切割的時候再壓縮
    compress      #需要壓縮
    compresscmd /usr/bin/lzop #指定壓縮命令 
    compressext .lzo #指定壓縮文件的結尾,這里以.lzo結尾
}

2. 配置supervisor管理程序的配置

[root@node1 logrotate.d]# cat /etc/supervisor/conf.d/netqps.conf 

[program:netqps]
command=tcpdump -i enp3s0f0 dst port 53
directory=/root/netqps
stdout_logfile=/root/netqps/files/nan_jing_01_query.log
stdout_logfile_maxbytes=0  # 這四個參數表示 不讓supervisor對日志進行分割,也不進行日志備份
stderr_logfile_maxbytes=0  #
stdout_logfile_backups=0   #
stderr_logfile_backups=0   #
redirect_stderr=true
autorestart=true
startsecs=10                 
startretries=3               
stopasgroup=true          
killasgroup=true      

3. 添加定時任務

0 */1 * * * /usr/sbin/logrotate -vf /etc/logrotate.d/netqps  >> /root/netqps/backup.log  #每小時切割一次

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM