Apache日志优化
2016-12-18 16:07
162 查看
日志优化一般两个方面,日志切割和不记录指定类型日志,下面分别解释实验这两类
Apache日志切割
这里的日志指的是访问日志,每次访问都会产生数条日志,如果不去管理,时间久了,日志文件会越来越大,难以查看。所以我们将日志按照我们的需求进行归档,比如每天一个新日志。利用apache自带的一个工具rotatelogs即可实现。
下面我们来配置一下,在对应的虚拟主机配置文件中加入
# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
ErrorLog " /usr/local/apache2/logs/test-error_log"
CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test-
access_%Y%m%d.log 86400" combined
说明:上面是两行,一定不要回车。Errorlog是错误日志,Customlog是访问日志。最前面的竖线即管道符,指把Customlog交给rtatelogs工具处理。-l的作用是校准时区为UTC,即北京时间。后面的86400,单位是秒,指一天。那么日志会每一天切割一次。最后的combined是日志格式,在httpd.conf有日志格式的定义。
# grep LogFormat /usr/local/apache2/conf/httpd.conf
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
Apache不记录指定文件类型日志
当一个站点的访问量很大时,访问日志会很多,但其实有一些访问日志并不需要记录,比如网站的一些图片,还有js、css等静态对象。
做下方的配置便可以实现上方的想法
# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
ErrorLog "/usr/local/apache/logs/test-error_%Y%m%d.log 86400"
SetEnvIf Request_URI ".*\.gif$" image-request
SetEnvIf Request_URI ".*\.jpg$" image-request
SetEnvIf Request_URI ".*\.png$" image-request
SetEnvIf Request_URI ".*\.bmp$" image-request
SetEnvIf Request_URI ".*\.swf$" image-request
SetEnvIf Request_URI ".*\.js$" image-request
SetEnvIf Request_URI ".*\.css$" image-request
CustomLog "|/usr/local/apache/bin/rotatelogs -l /usr/local/apache/logs/test-access_%Y%m%d.log 86400" combined env=!image-request
Apache日志切割
这里的日志指的是访问日志,每次访问都会产生数条日志,如果不去管理,时间久了,日志文件会越来越大,难以查看。所以我们将日志按照我们的需求进行归档,比如每天一个新日志。利用apache自带的一个工具rotatelogs即可实现。
下面我们来配置一下,在对应的虚拟主机配置文件中加入
# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
ErrorLog " /usr/local/apache2/logs/test-error_log"
CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test-
access_%Y%m%d.log 86400" combined
说明:上面是两行,一定不要回车。Errorlog是错误日志,Customlog是访问日志。最前面的竖线即管道符,指把Customlog交给rtatelogs工具处理。-l的作用是校准时区为UTC,即北京时间。后面的86400,单位是秒,指一天。那么日志会每一天切割一次。最后的combined是日志格式,在httpd.conf有日志格式的定义。
# grep LogFormat /usr/local/apache2/conf/httpd.conf
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
Apache不记录指定文件类型日志
当一个站点的访问量很大时,访问日志会很多,但其实有一些访问日志并不需要记录,比如网站的一些图片,还有js、css等静态对象。
做下方的配置便可以实现上方的想法
# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
ErrorLog "/usr/local/apache/logs/test-error_%Y%m%d.log 86400"
SetEnvIf Request_URI ".*\.gif$" image-request
SetEnvIf Request_URI ".*\.jpg$" image-request
SetEnvIf Request_URI ".*\.png$" image-request
SetEnvIf Request_URI ".*\.bmp$" image-request
SetEnvIf Request_URI ".*\.swf$" image-request
SetEnvIf Request_URI ".*\.js$" image-request
SetEnvIf Request_URI ".*\.css$" image-request
CustomLog "|/usr/local/apache/bin/rotatelogs -l /usr/local/apache/logs/test-access_%Y%m%d.log 86400" combined env=!image-request
相关文章推荐
- apache虚拟主机、日志轮询、日志统计、去版本优化
- Apache优化——日志管理
- apache的优化-日志轮询、错误页面重定向、压缩功能deflate、客户端缓存expire 推荐
- apache优化之防盗链,日志拆分,ab压力测试
- Apache优化——日志管理
- Apache access.log error.log日志文件太大优化方法
- apache中部署AWStats日志分析系统与优化(附安装包)
- 应用Apache的rewrite技术 实现面向搜索引擎优化
- Apache重负荷服务器应如何优化
- 转贴:Apache性能优化技巧
- [转]LAMP(Linux+Apache+MySQL+PHP)服务器的性能优化
- Apache性能优化技巧
- 怎样优化Apache服务器的性能
- APACHE优化之apache的内存使用
- 转贴:Apache重负荷服务器应如何优化
- 关于Apache的性能优化
- 设定日志格式:服务器为apache和其他时
- Apache 2.0性能优化—MPM的选择与配置
- Apache 2.0性能优化-MPM的选择与配置--From uudangdang.com
- 服务器优化――Sysctl, Apache, MySQL篇