zoukankan      html  css  js  c++  java
  • web服务器学习3---httpd 2.4.29日志处理

    .rotarelogs分割工具

    如果有虚拟主机在虚拟主机配置文件中配置,否则在主配置文件中修改.

    1.1修改配置文件

    vi /usr/local/httpd/conf/conf.d/vhosts.conf      //在虚拟主机配置文件中修改

    <VirtualHost 192.168.80.180:80>
    ServerAdmin admin@test1.com
    DocumentRoot /var/test1/
    ServerName www.test1.com
    CustomLog "|/usr/local/httpd/bin/rotatelogs -l logs/www.test1.com_Custom_%Y%m%d.log 86400" common

    ErrorLog "|/usr/local/httpd/bin/rotatelogs -l logs/test1_error_%Y%m%d.log 86400"
    </VirtualHost>

    systemctl restart httpd

    通过管道把日志交给rotatelogs工具 -l指使用本地时间 ,86400表示日志分隔的间隔为1天,单位是秒;

    %Y%m%d表示获取年月日;

    common 和 conbined是日志固定格式;

    1.2实验截图:

    2.cronolog分割(第三方)

     2.1手动安装编译工具

    tar xf cronolog-1.6.2.tar.gz -C /opt/
    cd /opt/cronolog-1.6.2/
    ./configure
    make && make install

    which cronolog

    2.2修改配置文件

    vi /usr/local/httpd/conf/conf.d/vhosts.conf      //与自带的log分割工具一样的设置,只是使用工具的路径不同

    <VirtualHost 192.168.80.180:80>
    ServerAdmin admin@test1.com
    DocumentRoot /var/test1/
    ServerName www.test1.com
    CustomLog "| /usr/local/sbin/cronolog -l logs/www.test1.com_Custom_%Y%m%d.log 86400" combined
    ErrorLog "| /usr/local/sbin/cronolog -l logs/test1_error_%Y%m%d.log 86400"
    </VirtualHost>

    httpd -t

    systemctl restart httpd

    2.3实验截图

     

    log格式原因不支持末尾以时间的方式命名log.

    3 AWStats日志分析

    关注两点:1.log文件位置;

         2.log文件是否生成并选择正确;

     预置条件

    apachectl -D DUMP_MODULES | grep cgi //确认加载了cgi模块

    ls /usr/local/httpd/modules/ | grep cgi //确认是否编译过cgi模块

    vi /usr/local/httpd/conf/httpd.conf //手动加载
    LoadModule cgid_module modules/mod_cgid.so
    LoadModule cgi_module modules/mod_cgi.so

    1.安装及配置

    tar xzvf awstats-7.6.tar.gz
    mv awstats-7.6 /usr/local/awstats

    cd /usr/local/awstats/tools/

    ./awstats_configure.pl               //自动配置脚本,根据提示填写

    http配置文件路径 /usr/local/httpd/conf/httpd.conf

    转换日志格式

    在配置最后会提示日志访问网页,需要记录下,如下:

    http://192.168.80.180/awstats/awstats.pl?config=www.test1.com 

    2.修改awstats配置文件

    vi /etc/awstats/awstats.www.test1.com.conf

    LogFile="/usr/local/httpd/logs/test1.com-access_log"       //修改日志文件位置,第50行,统计log数据一定要写对。

    DirData="/var/lib/awstats"                                                  //220行 手动建立每次抓取的数据存放位置

    mkdir /var/lib/awstats

    3.访问网页,手动采集数据

    cd /usr/local/awstats/tools/
    chmod +x awstats_updateall.pl
    ./awstats_updateall.pl now         //读取访问log,获取数据

     cd /var/lib/awstats                    //查看是否采集到数据

     4.访问页面及优化

    在访问AWStats系统时,需要指定目录,脚本位置,统计目标等信息,不便于记忆。为了简化操作,在web根目录下建立一个自动跳转的html网页.

     vi /usr/local/httpd/conf/conf.d/vhosts.conf              //设置网页所在目录的访问权限,实际是设置虚拟目录访问权限,设置权限

    <Directory "/usr/local/awstats/wwwroot">   
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
    AuthName "www.test1.com"
    AuthType Basic
    AuthUserFile /usr/local/httpd/user
    require valid-user
    Require all granted
    </Directory>

    vi /var/test1/index.html                                            //优化访问页面

    <html>
    <head>
    <meta http-equiv=refresh content="0;url=http://www.test1.com/awstats/awstats.pl?config=www.test1.com">
    </head>
    <body></body>
    </html>

    访问页面:

     5.自动采集--计划任务

    crontab -e

    */5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now

     crontab -l

    service crond status

    systemctl enable crond

    systemctl list-unit-files | grep crond

  • 相关阅读:
    查看pip install *.whl 支持的文件版本
    spark Infinate 的处理
    nc 文件的nan识别
    mysql 存中文失败问题
    tensorflow 安装
    数据库存含中文的json 时避免存成中文的ascii
    python 继承中的__init__
    python mysql数据库中 json的存储
    python 版本配置问题
    python dict 实现swich
  • 原文地址:https://www.cnblogs.com/youxxn/p/8686332.html
Copyright © 2011-2022 走看看