apache日志介绍:
通用日志格式: CommonLogFormat
组合日志格式: CombinedLogFormat
例如:
<VirtualHost *:80>
ServerAdmin tan.tianyik.com
DocumentRoot "/var/html/bbs"
ServerName bbs.tianyik.com
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common(或者combined)
</VirtualHost>
日志轮询:不希望日志越来越大
工具:
rotatelogs 自带的
cronolog 常用的
日志切割
使用cronolog工具轮询案例:
下载
wget http://down1.chinaunix.net/distfiles/cronolog-1.6.2.tar.gz
解压
tar xvf cronolog-1.6.2.tar.gz
编译安装
./configure
make
make install
修改vhost配置文件:
vi /application/apache/conf/extra/httpd-vhosts.conf 修改如下:
<VirtualHost *:80>
ServerAdmin tan.tianyik.com
DocumentRoot "/var/html/www"
ServerName www.tianyik.com
ServerAlias tianyik.com
ErrorLog "logs/dummy-host.example.com-error_log"
ErrorLog "logs/www-error_log"
CustomLog "|/usr/local/sbin/cronolog /app/logs/access_www_%Y%m%d.log" combined
</VirtualHost>
检查语法:/application/apache/bin/apachectl -t
平滑重启:/application/apache/bin/apachectl graceful
刷新网页www.tianyik.com
查看效果:
cat /app/logs/access_www_20160307.log
192.168.31.140 - - [07/Mar/2016:15:16:22 +0800] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0"
192.168.31.140 - - [07/Mar/2016:15:16:22 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0"
192.168.31.140 - - [07/Mar/2016:15:16:22 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0"