您的位置:首页 > 运维架构 > Apache

LAMP - Apache日志切割

2016-08-06 21:34 204 查看
网站会随着访问量的增大,而造成记录的日志变得越来越大,如果置之不理,总有一天会撑爆磁盘。
所以我们应该每天定时去切割日志,比如一个月之后,再去删除过时的日志,以保证日志文件不会无穷无尽的占用磁盘的资源。

配置:需进入apache的虚拟主机配置文件中,修改ErrorLog & CustomeLog 两行的字段,利用bin目录下的rotatelogs执行文件来进行切割

<VirtualHost *:80>
DocumentRoot "/data/www"
ServerName www.test.com
ServerAlias www.aaa.com www.bbb.com www.ccc.com
ErrorLog "logs/test.com-error_log"
CustomLog "|/usr/local/apache/bin/rotatelogs -l /usr/local/apache/logs/test.com-access_%Y%m%d_log 86400" combined

说明:%Y%m%d 定义日志是按照每天的日期来命名的,86400是指过了86400秒(一天)再进行切割
combined 代表记录日志的格式,具体可以在httpd.conf这个配置文件里查看
<IfModule log_config_module>
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux apache lamp