awstats日志分析

一.AWStats简介

AWStats是使用Perl语言开发的一款开源日志分析系统。它不仅可以用来分析Apache网站服务器的访问日志,也可以用来分析Samba、Vsftpd、IIS等服务的日志文件。结合crond等计划任务服务,可以对不断增长的日志内容定期进行分析。

AWStats提供一系列的perl脚本实现:服务配置,日志读取,报表生成等功能。而功能实现的过程是:

  • 将apache的访问情况记录到日志中,AWStats每次执行更新时读取这些日志
  • 分析日志数据,将结果存储到数据库中
  • AWStats提供一个cgi程序通过web页面来显示数据库中所统计的数据。

二.安装

1.安装perl环境包

perl -version   //检查perl版本号
yum -y install perl*   //yum安装即可

2.安装httpd

yum -y install httpd

3.安装awstats软件包

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

三.配置httpd服务器

  • 启动httpd服务

    httpd软件安装完成主配置文件在:/etc/httpd/conf/httpd.conf,对其进行简单配置,包括修改监听地址(Listen 10.0.90.172:8080)修改完成之后启动服务

    systemctl start httpd.service   //启动服务
    systemctl status httpd.service  //查看服务状态
    
  • 在站点目录下创建测试首页。

    cd /var/www/html/
    echo "HTTPD TEST" > index.html
    
  • 关闭防火墙

    systemctl disable firewalld.service
    systemctl stop firewalld.service
    setenforce 0
    

四.配置AWStats日志分析系统

AWStats系统支持统计多个网站的日志文件,通常以网站名称来区别不同的站点。因此,在执行分析前要为每个Web站点建立站点统计配置文件,借助于AWStats系统提供的awstats_configure.pl 脚本可以简化创建过程。

cd /usr/local/awstats/tools/
perl awstats_configure.pl     //执行脚本创建配置文件

如下:

  • 配置httpd.conf路径
  • y
  • 要统计访问量的域名
  • 存储的配置文件路径(按照默认的),会在/etc/awstats下生成相应的conf文件

如果要监控多个网站,那么就生成多个域名,perl awstats_configure.pl走多遍,该命令执行后,会生成一个网址,该网址就是之后要访问的

  • 因为在Apache2.4以上的版本中重新定义了访问权限,所需需将在httpd主配置文件中自动生成的awstats访问权限进行简单修改,在配置文件末尾。

    Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"
    Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
    Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"
    ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/" #已存在
    
    <Directory "/usr/local/awstats/wwwroot">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
    Require all granted    //添加该句
    </Directory>
    
  • 重启httpd服务

    systemctl restart httpd.service
    
  • 修改站点统计配置文件

    cd /etc/awstats
    vim awstats.www.benet.com.conf
    //分析/data/log下的(logresolvemerge.pl可以读取压缩文件)
    LogFile="/usr/local/awstats/tools/logresolvemerge.pl /data/log/10_journals.log* |" 
    //该目录实际上没有,需要手动创建
    DirData="/var/lib/awstats"            
    //日志格式(如果一个nginx日志有多个域名需要解析,需要配置virtualname,注意awstats是根据域名来进行解析的,如果virtualname找不到,多个域名网站解析出来的数据一样)
    LogFormat = "%virtualname %host - %logname %time1 %methodurl %code %bytesd %refererquot %uaquot %otherquot" 
    
  • nginx配置文件nginx.conf日志格式

    log_format  global_main  '$http_host $remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
    

五.执行日志分析

执行之后会将日志同步,刷新网站才能看到

perl /usr/local/awstats/tools/awstats_updateall.pl now

#或使用单个域名进行解析(/etc/awstats下如有awstats.csdata.conf文件)
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=csdata.org

六.创建计划任务

crontab -e
*/5 * * * *  /usr/local/awstats/tools/awstats_updateall.pl now  //表示每隔五分钟更新
systemctl start crond      //启动服务
systemctl enable crond     //将服务加入系统启动项
/var/spool/mail/root   //执行计划任务会在该目录下有新邮件提醒

七.总结

  1. 通过nginx访问httpd所在的平台

    我们一般在ip1的机器上设置nginx
    
     server {
            server_name kmf1.ac.cn www.csdata1.org;       #中国科学数据
            location /awstats/ {    #访问日志统计
                proxy_pass http://xx:8080/awstats/;
                proxy_redirect off;
                proxy_buffering off;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP  $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            }
            location /awstatsicons/ {    #访问日志统计
                proxy_pass http://xx:8080/awstatsicons/;
                proxy_redirect off;
                proxy_buffering off;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP  $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            }
    然后在ip2 10.0.90.172:8080上部署上面的httpd和AWStats,当访问ip1机器上的kmf1.ac.cn/awstats/,ip2的机器上会有访问记录产生,执行日志分析命令,然后访问http://10.0.90.172:8080/awstats/awstats.pl?config=kmf1.ac.cn会看到相应的记录
         
    
  2. awstats分析本机所在的nginx日志(一般是ip1的机器同步到ip2的机器上,此时不通过httpd访问,httpd只是为了awstats的启动)

posted @ 2023-02-26 16:49  MISF  阅读(255)  评论(0编辑  收藏  举报
     JS过度和变形效果演示   
  
    html5.png