Apache——AWStats日志分析

AWStats日志分析系统

在httpd服务器的访问日志文件access_log中,记录了大量的客户机访问信息,通过分析这些信息,可以及时了解Web站点的文芳情况,如每天或特定时间段的访问IP数量、点击量最大的页面等。

AWStats日志分析系统
  • Peri语言开发的一款开源日志分析系统
  • 可用来分析Apache、Samba、 Vsftpd、 IIS等服务 器的访问日志
  • 信息结合crond等计划任务服务,可对日志内容定期进行分析

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-BBiR8X1R-1576479079701)(1576473361861.png)]

日志统计实验

实验环境:

1、开启两个终端,一个作为统计服务端,一个作为客户访问端

2、安装软件AWStats,软件连接:

3、安装httpd及bind,启用Apache及DNS

#首先,先安装httpd及bing

[root@localhost ~]# yum install httpd bind -y

#配置DNS

[root@localhost ~]# vim /etc/named.conf       //修改主配置文件,监听及允许主机全设为any
…………省略
options {
        listen-on port 53 { any; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        recursing-file  "/var/named/data/named.recursing";
        secroots-file   "/var/named/data/named.secroots";
        allow-query     { any; };
…………省略

[root@localhost ~]# vim /etc/named.rfc1912.zones    //修改区域配置文件,配置域名及定义区域数据配置文件
…………省略
zone "kgc.com" IN {
        type master;
        file "kgc.com.zone";
        allow-update { none; };
};
zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
…………省略
[root@localhost ~]# cd /var/named/
[root@localhost named]# ls
data  dynamic  named.ca  named.empty  named.localhost  named.loopback  slaves
[root@localhost named]# cp -p named.localhost kgc.com.zone     //创建区域数据配置文件并进行配置
[root@localhost named]# vim kgc.com.zone 
$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        A       127.0.0.1
www IN  A       192.168.17.128                   //修改域名解析地址

[root@localhost named]# systemctl start named     //开启服务
[root@localhost named]# systemctl stop firewalld.service     //关闭防火墙
[root@localhost named]# setenforce 0

#配置Apache

[root@localhost named]# vim /etc/httpd/conf/httpd.conf      //修改主配置文件
ServerName www.kgc.com:80                         //更改域名
Listen 192.168.17.128:80                         //更改监听地址
[root@localhost named]# systemctl start httpd     //开启服务

#挂载,如果没有办法使用cifs,需要yum install 安装cifs

[root@localhost named]# mkdir /abc
[root@localhost named]# mount.cifs //192.168.17.1/share /abc
Password for root@//192.168.17.1/share:  
[root@localhost named]# cd /abc
[root@localhost abc]# ls
apr-1.6.2.tar.gz       cronolog-1.6.2-14.el7.x86_64.rpm  httpd-2.4.29.tar.bz2  LAMP.txt
apr-util-1.6.0.tar.gz  Discuz_X2.5_SC_UTF8.zip           httpd-2.4.2.tar.gz    mysql-5.6.26.tar.gz
awstats-7.6.tar.gz     extundelete-0.2.4.tar.bz2         john-1.8.0.tar.gz     php-5.6.11.tar.bz2

#解压

[root@localhost abc]# tar zxvf awstats-7.6.tar.gz -C /usr/local/

#切换至压缩路径,将目录重命名,去掉版本号

[root@localhost abc]# cd /usr/local/
[root@localhost local]# ls
awstats-7.6  bin  etc  games  include  lib  lib64  libexec  sbin  share  src
[root@localhost local]# mv awstats-7.6/ awstats
[root@localhost local]# ls
awstats  bin  etc  games  include  lib  lib64  libexec  sbin  share  src

#为要统计的站点建立配置文件,进行安装

[root@localhost local]# cd awstats/                  //切换至统计站点的安装路径进行安装
[root@localhost awstats]# ls
docs  README.md  tools  wwwroot
[root@localhost awstats]# cd tools/
[root@localhost tools]# ls
awstats_buildstaticpages.pl  awstats_exportlib.pl  dolibarr            httpd_conf          maillogconvert.pl  urlaliasbuilder.pl  xslt
awstats_configure.pl         awstats_updateall.pl  geoip_generator.pl  logresolvemerge.pl  nginx              webmin
[root@localhost tools]# ./awstats_configure.pl           //进行执行安装
…………省略
-----> Check for web server install

Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
> /etc/httpd/conf/httpd.conf                         //输入httpd配置文件路径
…………省略
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
> www.kgc.com                                        //输入域名    
…………省略                                              //其他全部是y 或者 回车
You can also read your statistics for 'www.kgc.com' with URL:
> http://localhost/awstats/awstats.pl?config=www.kgc.com    
//最后会生成一个访问地址,将localhost改为自己定义的域名即可

Press ENTER to finish...

#检查awstats模块是否自动写到apache主配置文件中并修改访问权限

[root@localhost tools]# vim /etc/httpd/conf/httpd.conf 
…………省略
<Directory "/usr/local/awstats/wwwroot">
    Options None
    AllowOverride None
#    Order Allow,deny                        //添加注释
#    Allow from all                         //添加注释
Require all granted                         //允许所有
</Directory>

#修改站点统计配置文件

[root@localhost tools]# cd /etc/awstats/           //切换至站点统计配置文件
[root@localhost awstats]# ls
awstats.www.kgc.com.conf
[root@localhost awstats]# vim awstats.www.kgc.com.conf 
LogFile="/var/log/httpd/access_log"       //修改访问日志文件位置
DirData="/var/lib/awstats"               //指定数据存储目录,awstats 默认不存在(需要创建)
[root@localhost awstats]# mkdir  /var/lib/awstats           //创建目录
[root@localhost awstats]# systemctl restart httpd           //重启服务

#这时可以使用客户机进行测试访问了

先改网络属性,dns指向服务端地址

在这里插入图片描述

这时可以访问统计页面,http://www.kgc.com/awstats/awstats.pl?config=www.kgc.com

但目前没有任何记录,需要去实时更新

在这里插入图片描述

#操作实时更新(now表示截至现在的更新)

[root@localhost awstats]# cd /usr/local/awstats/tools/           //切换至统计站点路径进行更新
[root@localhost tools]# ls
awstats_buildstaticpages.pl  awstats_exportlib.pl  dolibarr            httpd_conf          maillogconvert.pl  urlaliasbuilder.pl  xslt
awstats_configure.pl         awstats_updateall.pl  geoip_generator.pl  logresolvemerge.pl  nginx              webmin
[root@localhost tools]# ./awstats_updateall.pl now             //执行实时更新
Running '"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=www.kgc.com -configdir="/etc/awstats"' to update config www.kgc.com

#浏览网页后执行实时更新,再去验证是否有统计

在这里插入图片描述

#每次浏览后都需要执行更新才可以进行实时统计,这是不实际的,所以我们可以做一个优化,使用周期性计划任务,每隔两分钟执行一次实时更新

[root@localhost awstats]# crontab -e
*/2  *  *  *  * /usr/local/awstats/tools/awstats_updateall.pl now
[root@localhost awstats]# systemctl start crond         //开启计划性任务

#访问路径太长:http://www.kgc.com/awstats/awstats.pl?config=www.kgc.com ,可以对网页地址进行优化

[root@localhost awstats]# cd /var/www/html                //切换至网页站点,新建一个html文件
[root@localhost html]# vim aws.html
<html>
 <head>
   <meta http-equiv=refresh content="0;url=http://www.kgc.com/awstats/awstats.pl?config=www.kgc.com">
 </head>
 <body></body>
</html>

#配置完成后,我们就可以直接使用此地址直接进行访问了 http://www.kgc.com/aws.html

在这里插入图片描述

发布了72 篇原创文章 · 获赞 44 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/ML908/article/details/103562769