3tr21 发表于 2014-11-11 09:30:13

apache 日志轮询+cronolog

1、apache日志有两种,分别为:
    通用日志格式:(ComminLog Format)比较简单
    组合日志格式: (CombinedLOG Format)工作中习惯使用,比较复杂
2、查看的位置:
    vi httpd.conf
<IfModule logio_module>
    196 <IfModule log_config_module>
    197   #
    198   # The following directives define some format nicknames for use with
    199   # a CustomLog directive (see below).
    200   #
    201   LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    202   LogFormat "%h %l %u %t \"%r\" %>s %b" common
    203
    204   <IfModule logio_module>
    205       # You need to enable mod_logio.c to use %I and %O
    206       LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    207   </IfModule>
3、使用方法,把调用的名字写上即可,格式可以修改(查官方文档):
   vi extra/httpd-vhosts.conf
   27 <VirtualHost *:80>
   28   ServerAdmin lingchaoxx@live.com
   29   DocumentRoot "/var/html/www"
   30   ServerName www.etiantian.org
   31   ServerAlias etiantian.org
   32   ErrorLog "logs/www-error_log"
   33   CustomLog "logs/www-access_log" common
   34 </VirtualHost>
4、使用日志轮询工具cronolog ;网址:http://cronolog.org/
    安装:
    tar xf cronolog-1.6.2.tar.gz
    ./configure
    make
    make install
    查看生成的工具:
    ll /usr/local/sbin/cronolog
    -rwxr-xr-x 1 root root 40446 11月4 04:40 /usr/local/sbin/cronolog
5、推荐写法(下边的是按天轮询的,):
    CustomLog "|/usr/local/sbin/cronolog /app/logs/access_name_%Y%m%d.log"combined
   
    需要注意路径要全路径,以及日志的格式等。

6、使用方法:
    在配置文件中../extra/httpd-vhosts.conf 添加即可,为了不出现意外最好把原来使用日志轮询注释掉或者干脆删掉;
   
    <VirtualHost *:80>
    ServerAdmin lingchaoxx@live.com
    DocumentRoot "/var/html/www"
    ServerName www.etiantian.org
    ServerAlias etiantian.org
    ErrorLog "logs/www-error_log"
    CustomLog "logs/www-access_log" common
    #此处添加即可!!!

    </VirtualHost>
7、检查语法,重启完毕!

页: [1]
查看完整版本: apache 日志轮询+cronolog