搭建AWStats日志分析系统
AWStats是一款功能强大且功能强大的免费工具,可以图形方式生成高级Web,流媒体,ftp或邮件服务器统计信息。此日志分析器用作CGI或命令行, 并在几个图形网页中显示您的日志包含的所有可能信息。
它使用部分信息文件来经常快速地处理大型日志文件。它可以分析来自所有主要服务器工具的日志文件,如Apache日志文件(NCSA组合/ XLF / ELF日志格式或通用/ CLF日志格式),WebStar,IIS(W3C日志格式)以及许多其他Web,代理,wap,流服务器,邮件服务器和一些ftp服务器。
实验步骤:
修改DNS主配置文件
[root@localhost ~]# yum -y install httpd bind
[root@localhost ~]# vim /etc/named.conf
[root@localhost ~]# vi /etc/named.rfc1912.zones
zone "test.com" IN {
type master;
file "test.com.zome";
allow-update { none; };
};
[root@localhost ~]# vim /etc/named.rfc1912.zones
zone "test.com" IN {
type master;
file "test.com.zome";
allow-update { none; };
[root@localhost ~]# cp -p named.localhost kgc.com.zone
[root@localhost ~]# vim kgc.com.zone
[root@localhost named]# vi test.com.zome ## 编辑配置文件
修改最后一行内容为:
www IN A 192.168.136.123
[root@localhost ~]# systemctl restart named
修改http服务主配置文件
[root@localhost named]# vim /etc/httpd/conf/httpd.conf ## 修改配置文件
Listen 192.168.50.136:80
#Listen 80
ServerName www.test.com:80
[root@localhost named]# vi /var/www/html/index.html ## 新建网页文件
<h1>This is ko03</h1>
安装AWStats
[root@localhost named]# cd /opt
[root@localhost opt]# tar zxvf awstats-7.6.tar.gz
[root@localhost opt]#mv awstats-7.6 /usr/local/awstats 安装并移动软件
[root@localhost opt]# cd /usr/local/awstats/tools/
[root@localhost tools]# ./awstats_updateall.pl now
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 输入http服务主配置文件路径
-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y
-----> 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 输入域名
修改http服务配置文件
[root@localhost tools]# vi /etc/httpd/conf/httpd.conf
<Directory "/usr/local/awstats/wwwroot">
Options None
AllowOverride None
# Order allow,deny 注释掉
# Allow from all 注释掉
Require all granted 所有人都可以访问
[root@localhost tools]# cd /etc/awstats/
[root@localhost awstats]# vim awstats.www.kgc.com.conf
LogFile="/var/log/httpd/access_log" 修改监控的 日志名称
找到220行,有如下内容,这是放日志的位置:
DirData="/var/lib/awstats"
发现没有在这个目录下创建一个目录
v[root@localhost lib]# mkdir awstats 创建一个目录
[root@localhost lib]# systemctl restart httpd.service
www.kgc.com/awstats/awstats.pl?config=www.kgc.com 访问网站
在客户机中打开浏览器,访问统计后台地址
进入awstats软件目录,执行脚本刷新访问数据
[root@localhost awstats]# cd /usr/local/awstats/tools/ **进入目录
[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
Create/Update database for config "/etc/awstats/awstats.www.kgc.com.conf" by AWStats version 7.6 (build 20161204)
From data in log file "/var/log/httpd/access_log"...
Phase 1 : First bypass old records, searching new record...
Direct access after last parsed record (after line 98)
Jumped lines in file: 98
Found 98 already parsed records.
Parsed lines in file: 0
Found 0 dropped records,
Found 0 comments,
Found 0 blank records,
Found 0 corrupted records,
Found 0 old records,
Found 0 new qualified records.
添加周期性计划任务
[root@localhost awstats]# crontab -e ## 编辑周期性计划任务
写入如下内容:
*/5 * * * * /usr/local/awstats/tools/awststs_updateall.pl now
[root@localhost tools]# systemctl start crond 开启服务
优化网页地址
[root@localhost httpd]# cd /var/www/html/
[root@localhost html]# vim logs.html
<html>
<head>
<meta http-equiv=refresh content="0;url=http://20.0.0.26/awstats/awstats.pl?config=www.test.com">
</head>
<body></body>
</html>