IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Nginx 日志自动切割

    mrasong发表于 2016-12-23 23:54:39
    love 0
    cd  /etc/logrotate.d 
    
    vi /etc/logrotate.d/nginx 
    
    /home/wwwlogs/*.log {
        missingok
        dateext
        notifempty
        daily
        rotate 7
        sharedscripts
        postrotate
        if [ -f /usr/local/nginx/logs/nginx.pid ]; then
            kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
        fi
        endscript
    }
    
    :wq!  #保存退出
    
    mkdir -p  /usr/local/nginx/logs/nginx_logs/
    chmod +x  /etc/logrotate.d/nginx  #添加执行权限
    /usr/sbin/logrotate -vf  /etc/logrotate.d/nginx
    
    crontab  -e  #添加以下代码
    0 0 * * * /usr/sbin/logrotate -vf /etc/logrotate.d/nginx  #每天凌晨定时执行脚本
    


沪ICP备19023445号-2号
友情链接