zoukankan      html  css  js  c++  java
  • LAMP 2.0Apache日志切割

    每次访问网站就会产生若干条日志,当然前提是已经配置了日志。

    配置日志的文件在

    vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 

    把注释掉的这两行打开

    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common

    common是日志的格式,把日志的格式改成combined

       ErrorLog "logs/dummy-host.example.com-error_log"
       CustomLog "logs/dummy-host.example.com-access_log" combined

    日志的位置 logs是针对/usr/locol/apache2来说的。生成的文件是后面的两个名字。可以更名。

       ErrorLog "logs/denny.com-error_log"
       CustomLog "logs/denny.com-access_log" combined

    检查文件是否正确

    apachectl -t

    重新加载或者重启

    /usr/local/apache2/bin/apachectl restart
    /usr/local/apache2/bin/apachectl graceful

    去论坛刷新几次,看看是否生成日志文件。

    cd /usr/local/apache2/logs/
    ls

    生成了访问日志denny.com-access_log和错误日志denny.com-error_log

    查看访问日志。

    cat denny.com-access_log

    复制其中一条信息

    192.168.1.114 - - [08/Dec/2015:23:21:27 +0800] "GET /forum.php?mod=ajax&action=forumchecknew&fid=2&time=1449587726&inajax=yes HTTP/1.1" 200 64 "http://www.houchangfu.com/forum.php?mod=forumdisplay&fid=2" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)"

    格式是

    LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined

    h来源IP 。l和u不存在用-号表示。u用户,t时间,r动作,Referer来源地址。User-Agent来源浏览器。

    为了防止日志无限增长,要把每天的日志切割,以日期重命名,然后超过30天的删掉。

    打开配置文件

    vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 

    修改

    CustomLog "logs/denny.com-access_log" combined

    CustomLog "|/usr/local/apache2/bin/rotatelogs -l  /usr/local/apache2/logs/denny.com-access_%Y%m%d_log 86400" combined

    用apache2的命令,-l切割,日志存放路径写据对路径,时间格式 86400秒等于1天。

    查看文件格式,重启。

    apachectl -t
    /usr/local/apache2/bin/apachectl restart

    刷新论坛然后ls查看

     ls /usr/local/apache2/logs/
    denny.com-access_20151208_log
  • 相关阅读:
    Sign in with the app-specific password you generated. If you forgot the app-specific password or need to create a new one, go to appleid.apple.com
    Java Web项目搭建过程记录(struts2)
    微信小程序之菜鸟入门教学(二)
    微信小程序之菜鸟选手入门教学(一)
    html 表单input录入内容校验
    VUE中使用driver.js实现先手引导
    BScroll使用
    VUE使用screenfull实现全屏
    VUE打印功能
    VUE中使用XLSX实现导出excel表格
  • 原文地址:https://www.cnblogs.com/wangshaojun/p/5031102.html
Copyright © 2011-2022 走看看