使用logrotate管理VPS日志文件的方法
<p><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>我们可以根据日志文件的大小,也可以根据其天数来转储,这个过程一般通过 crontab程序来执行。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>logrotate 程序还可以用于压缩日志文件,以及发送日志到指定的E-mail 。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>logrotate 的配置文件是 /etc/logrotate.conf 主要参数如下表: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>下面的配置是deepvps使用的配置文件,大家可以作为参考。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>logrotate.conf </span></p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p class="right">
<span><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p class="msgborder" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
/home/www/logs/*.log { <br>
daily <br>
missingok <br>
compress <br>
delaycompress <br>
dateext <br>
create <br>
notifempty <br>
sharedscripts <br>
postrotate <br>
kill -HUP `cat /usr/local/nginx/logs/nginx.pid` <br>
endscript <br>
} </p>
<p>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
参数 功能<br>
daily——指定转储周期为每天<br>
missingok——指的是如果找不到这个log档案,就忽略过去<br>
compress——通过gzip 压缩转储以后的日志<br>
delaycompress 和compress一起使用时,转储的日志文件到下一次转储时才压缩<br>
notifempty——如果是空文件的话,不转储<br>
postrotate/endscript——在转储以后需要执行的命令可以放入这个对,这两个关键字必须单独成行</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
crontab:</p>
<blockquote style='margin: 0px auto 10px; padding: 4px 4px 4px 10px; outline: none; background: rgb(244, 249, 251); border-left: 4px solid rgb(116, 205, 230); width: 665px; font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>
<p>
59 23 * * * root logrotatef /usr/local/nginx/conf/logrotate.conf</p>
</blockquote>
頁:
[1]