Rootop 服务器运维与web架构

apache 日志分割

| 暂无评论

代码:

<VirtualHost *:80>
ServerName www.rootop.org
ServerAdmin venus@networkquestios.org
DocumentRoot /var/www/nq/wp
errorlog “|/usr/sbin/rotatelogs /var/log/httpd/nq/nqblog/error/wp%Y%m%d_error_log 86400 480”
customlog “|/usr/sbin/rotatelogs /var/log/httpd/nq/nqblog/access/wp%Y%m%d_access_log 86400 480” common
DirectoryIndex index.php index.html index.htm
</VirtualHost>

rotatelogs 是apache 自带的日志分割工具,%y%m%d用当前日期命名, 每86400 秒生成一个新的日志,就是24小时。common是日志的格式,可参考配置文件中其它格式自行选择。

参考资料:

CustomLog “| /usr/sbin/rotatelogs  /data/httpd_log/daphne_access/%Y_%m_%d_access_log 86400 480” common
ErrorLog “|  /usr/sbin/rotatelogs  /data/httpd_log/daphne_error/%Y_%m_%d_error_log 86400 480”

参数:86400、 480

如果不设置480这个参数,将导致日志记录时间和服务器时间相差8小时,原因是rotatelogs有一个offset参数,表示相对于UTC的时差分钟数,中国是第八时区,相差480分钟。86400是表示1天。
%A 星期名全称(本地的)
%a 3个字符的星期名(本地的)
%B 月份名的全称(本地的)
%b 3个字符的月份名(本地的)
%c 日期和时间(本地的)
%d 2位数的一个月中的日期数
%H 2位数的小时数(24小时制)
%I 2位数的小时数(12小时制)
%j 3位数的一年中的日期数
%M 2位数的分钟数
%m 2位数的月份数
%p am/pm 12小时制的上下午(本地的)
%S 2位数的秒数
%U 2位数的一年中的星期数(星期天为一周的第一天)
%W 2位数的一年中的星期数(星期一为一周的第一天)
%w 1位数的星期几(星期天为一周的第一天)
%X 时间 (本地的)
%x 日期 (本地的)
%Y 4位数的年份

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/373.html

作者:Venus

服务器运维与性能优化

发表回复