zoukankan      html  css  js  c++  java
  • CentOS中设置Apache服务器网站访问日志[每天的日志]

    在阿里云的linux 服务器下Apache的日志默认设置是七天更新一次, 并且所在的目录无法通过FTP浏览器查看, 这样让小白操作起来非常麻烦

    可以使用rotatelogs来设置服务器的网站访问日志按天记录,每天生成一个单独的文件, 这样非常方便查看

    以我使用的CentOS为例, 首先要检测是否带有rotatelogs.

    如果没有安装,则需要我们安装rotatelogs, 运行命令:

    yum install rotatelogs
    

    修改apache的配置文件,按天记录网站的访问日志

    打开apache的配置文件:vi /etc/httpd/conf/httpd.conf, 编辑:

    #ErrorLog logs/error_log #注释掉这行,加上下面这行
    ErrorLog "|rotatelogs /home/lao8.org/log/error_log%Y_%m_%d.log 86400 480"  #设置好日志保存目录每天生成错误日志
    #CustomLog logs/access_log common #注释加上下面这样
    CustomLog "|rotatelogs  /home/lao8.org/log//access_log%Y_%m_%d.log 86400 480" combined #每天生成访问日志
    

    保存并重启apache (运行命令 service httpd restart)


    备注:

    1. Rotatelogs的用法:

    rotatelogs [ -l ] logfile [ rotationtime [ offset ]] | [ filesizeM ]
    

    选项:

    -l    使用本地时间代替GMT时间作为时间基准。注意:在一个改变GMT偏移量(比如夏令时)的环境中使用-l会导致不可预料的结果。
    
    logfile    它加上基准名就是日志文件名。如果logfile中包含"%",则它会被视为用于strftime()的格式字符串;否则它会被自动加上以秒为单位的".nnnnnnnnnn"后缀。这两种格式都表示新的日志开始使用的时间。
        
    rotationtime    日志文件滚动的以秒为单位的间隔时间。
        
    offset    相对于UTC的时差的分钟数。如果省略,则假定为"0"并使用UTC时间。比如,要指定UTC时差为"-5小时"的地区的当地时间,则此参数应为"-300"。
       
    filesizeM    指定以filesizeM文件大小滚动,而不是按照时间或时差滚动。
    

    2. Rotatelogs 失败不生效的原因和解决办法:

    rotatelogs 截断日志,进行配置。但是保存之后,服务器restart 始终无法重启成功。

    日志文件:

    (2)No such file or directory: AH00089: Couldn't start ErrorLog process ' rotatelogs /var/www/html/logs/error/%Y/%m/%d_error.log 86400 480'.  
    AH00015: Unable to open logs  
    (2)No such file or directory: AH00089: Couldn't start ErrorLog process ' rotatelogs /var/www/html/logs/error/%Y/%m/%d_error.log 86400 480'.  
    AH00015: Unable to open logs  
      
      
    Could not open log file '/home/google.com/logs/access/2014/access__20141019.log' (No such file or directory)  
    AH00106: piped log program '/usr/sbin/rotatelogs /home/google.com/logs/access/%Y/access__%Y%m%d.log 86400 480' failed unexpectedly  
    Could not open log file '/home/google.com/logs/access/2014/access__20141019.log' (No such file or directory)  
    AH00106: piped log program '/usr/sbin/rotatelogs /home/google.com/logs/access/%Y/access__%Y%m%d.log 86400 480' failed unexpectedly  
    Could not open log file '/home/google.com/logs/access/2014/access__20141019.log' (No such file or directory)  
    AH00106: piped log program '/usr/sbin/rotatelogs /home/google.com/logs/access/%Y/access__%Y%m%d.log 86400 480' failed unexpectedly  
    Could not open log file '/home/google.com/logs/access/2014/access__20141019.log' (No such file or directory)  
    AH00106: piped log program '/usr/sbin/rotatelogs /home/google.com/logs/access/%Y/access__%Y%m%d.log 86400 480' failed unexpectedly  
    

    解决办法:

    1)rotatelogs 不能直接写 rotatelogs,必须写完整地址 /usr/sbin/rotatelogs

    2)rotatelogs 无创建目录的权限,所以最好不要给 格式化的地址加文件夹。

    正确的写法:

    CustomLog "| /usr/sbin/rotatelogs /var/www/html/logs/access_%Y%m%d.log 86400 480 " combined
    
  • 相关阅读:
    [帮助文档] [SageMath Thematic Tutorial] Chapter 10 使用Sagemath进行数值计算
    [转]dd命令、cp命令详解+dd命令、cp命令对比 delong
    MBR内容解析
    记一个编译错误:命名冲突、宏定义、头文件包含顺序
    防止STL容器迭代器失效
    日历时间
    观点
    编码规范
    《转》impress.js页面PPT
    <转>Spring Test 整合 JUnit 4 使用总结
  • 原文地址:https://www.cnblogs.com/cnlihao/p/7072932.html
Copyright © 2011-2022 走看看