本文共 3349 字,大约阅读时间需要 11 分钟。
AWStats是使用Perl语言开发的一款开源日志分析系统。它不仅可以用来分析Apache网站服务器的访问日志,也可以用来分析Samba、Vsftpd、IIS等服务的日志文件。结合crond等计划任务服务,可以对不断增长的日志内容定期进行分析。
AWStats提供一系列的perl脚本实现:服务配置,日志读取,报表生成等功能。而功能实现的过程是:CenTos7中软件的安装多使用yum安装,在没有本地yum源的情况下,我们就需要连接到现网,获取在线更新源。但是在实验中我们只需要在本地虚拟机中操作,访问Web网页查看日志分析情况。所以可以先联网安装好实验所需的软件包,然后再将网卡模式更改为仅主机模式,设定静态IP地址,方便实验。
应为awstats是基于perl语言开发的,所以我们首先需要准备perl环境,再centos7系统中会有安装,如果没有,只需要使用yum安装即可,一般即使已经安装了,但会有更新。perl -version //检查perl版本号yum -y install perl* //yum安装即可
httpd的安装也是使用yum安装,当然也是可以选择编译安装。
yum -y install httpd
yum -y install bind
AWStats软件包安装非常简单,只需将软件包解压到httpd服务器的/usr/local/下即可。软件包可使用挂载windows共享文件夹的方式。
tar zxf awstats-7.6.tar.gzmv awstats-7.6/ /usr/local/awstats
systemctl start httpd.service //启动服务systemctl status httpd.service //查看服务状态
cd /var/www/html/echo "HTTPD TEST" > index.html
systemctl disable firewalld.servicesystemctl stop firewalld.servicesetenforce 0
关于如何搭建DNS服务器,我在之前的文章中有过详细介绍,那篇文中的系统版本是Redhat 6.5,更换了系统,但是搭建方式却没有改变,可以参考,链接奉上
cd /usr/local/awstats/tools/perl awstats_configure.pl //执行脚本创建配置文件
Options NoneAllowOverride NoneOrder allow,denyAllow from allRequire all granted //添加该句
systemctl restart httpd.service
cd /etc/awstatsvim awstats.www.benet.com.confLogFile="/etc/httpd/logs/access_log" //50行DirData="/var/lib/awstats" //220行,该目录实际上没有,需要手动创建mkdir /var/lib/awstats
perl /usr/local/awstats/tools/awstats_updateall.pl nowRunning '"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=www.benet.com -configdir="/etc/awstats"' to update config www.benet.comCreate/Update database for config "/etc/awstats/awstats.www.benet.com.conf" by AWStats version 7.6 (build 20161204)From data in log file "/etc/httpd/logs/access_log"...Phase 1 : First bypass old records, searching new record...Searching new records from beginning of log file...Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...Jumped lines in file: 0Parsed lines in file: 63Found 0 dropped records,Found 0 comments,Found 0 blank records,Found 0 corrupted records,Found 0 old records,Found 63 new qualified records.
crontab -e*/5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now //表示每隔五分钟更新systemctl start crond //启动服务systemctl enable crond //将服务加入系统启动项/var/spool/mail/root //执行计划任务会在该目录下有新邮件提醒
访问站点” “即可看到AWStats日志分析系统的统计页面
不做更改的网页地址过长,不方便记忆,为了简化操作,我们可以在web站点的站点目录下建立一个自动调转的HTML网页。当访问http://www.benet.com/aws.html 即可自动跳转到日志分析系统页面。
vim /var/www/html/aws.html //头部标签中添加网页
转载于:https://blog.51cto.com/13643643/2132082