使用logrotate轮询nginx和apache日志

使用logrotate轮询日志很方便,配置也很简单。
配置nginx
1、建立/etc/logrotate.d/nginx文件
vi /etc/logrotate.d/nginx
2、写入如下内容:

/var/log/nginx/*log {
    daily
    rotate 10
    missingok
    notifempty
    compress
    sharedscripts
    postrotate
        [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
    endscript
}

注释:
/var/log/nginx/*log:需要轮询日志路径
daily:每天轮询
rotate 10:保留最多10次滚动的日志
missingok:如果日志丢失,不报错继续滚动下一个日志
notifempty:当日志为空时不进行滚动
compress:旧日志默认用gzip压缩
/var/run/nginx.pid:nginx主进程pid

配置radiusd

/var/local/var/log/radius/*log {
    daily 
    missingok
    rotate 120
    compress
    delaycompress
    notifempty 
      create 666 radiusd radiusd 
      prerotate 
            /usr/bin/pkill -9 radiusd 
      endscript 
      sharedscripts 
      postrotate 
           /usr/local/sbin/radiusd -Xx > /usr/local/var/log/radius/radius.log&   
      endscript 
} 

配置apache

/var/log/httpd/*log {
    missingok
    notifempty
    sharedscripts
    postrotate
        /sbin/service httpd reload > /dev/null 2>/dev/null || true
    endscript
} 

你可能感兴趣的:(使用logrotate轮询nginx和apache日志)