分享

如何在 Linux 环境下部署 AWStats 分析系统来监控 Web 站点?

 西北望msm66g9f 2019-07-30


 CSDN海量资源免费下载!

前言

在上一篇文章《详解 Linux 环境下部署 HTTPD 服务》中我们介绍了 Linux 环境下部署 httpd 服务的基本搭建、相关配置以及相关说明描述,那么搭起来这个 httpd 服务肯定是需要为我们提供服务的。同时,在 httpd 服务器的访问日志文件中,也记录了大量的客户端的访问信息。通过这些信息可以了解到 Web 站点的访问情况等等;

那么,在这篇文章中我们将给大家介绍一款功能强大的免费工具 AWStats,可以将图形的方式来进行展示统计信息,以完成自动化的日志分析及统计工作。

1.AWStats 简介

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

AWStats 软件包下载地址

https:///projects/awstats/files/AWStats/

http://www./

2.安装 AWStats 软件包

将下载好的 AWStats 软件包解压到 httpd 服务器中的 /usr/local/ 目录下。

# tar zxf awstats-7.3.tar.gz
# mv awstats-7.3 /usr/local/awstats

为需统计的站点建立配置文件,AWStats 系统支持统计多个网站的日志文件,以网站名称来区分不同的站点。执行日志文件分析前,需为每个 web 站点建立站点统计配置文件,这时需在 awstats/tools 目录下执行 AWStats 系统提供的 awstats_configure.pl 脚本创建过程。

执行后,将会进入交互式的配置终端,需用户根据提示来进行手动输入指定 httpd 主配置文件的路径。

# cd /usr/local/awstats/tools/
# chmod +x awstats_configure.pl
# ./awstats_configure.pl

----- AWStats awstats_configure 1.0 (build 20140126) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).

-----> Running OS detected: Linux, BSD or Unix

-----> 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):
> /usr/local/httpd/conf/httpd.conf                 # 输入 httpd.conf 配置文件的路径

执行完上一步的操作后,接下来需设置日志类型,当提示是否修改日志类型时,输入 'y' 字母后配置脚本将自动修改 httpd.conf 配置文件,来进行添加访问 AWStats 分析系统的相关配置内容。

-----> Check and complete web server config file '/usr/local/httpd/conf/httpd.conf'
Warning: You Apache config file contains directives to write 'common' log files
This means that some features can't work (os, browsers and keywords detection).
Do you want me to setup Apache to write 'combined' log files [y/N] ? y
Add 'Alias /awstatsclasses '/usr/local/awstats/wwwroot/classes/''
Add 'Alias /awstatscss '/usr/local/awstats/wwwroot/css/''
Add 'Alias /awstatsicons '/usr/local/awstats/wwwroot/icon/''
Add 'ScriptAlias /awstats/ '/usr/local/awstats/wwwroot/cgi-bin/''
Add '<Directory>' directive
AWStats directives added to Apache config file.

-----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'
File awstats.model.conf updated.

为指定 web 站点创建配置文件,根据提示输入 'y' 来创建站点配置文件,并指定要统计的目标网站名称(www.)站点配置文件的存放路径(/etc/awstats)等;后续直接按 回车键 直到退出配置工具即可。

-----> 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.                   # 指定要统计的目标网站名称

-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
>                              # 直接按 Enter 键接受默认设置

-----> Create config file '/etc/awstats/awstats.www..conf'
Config file /etc/awstats/awstats.www..conf created.

按照上述目标网站名称 www. 建立的站点统计配置文件将存放在 /etc/awstats 目录下,文件名为:awstats.www.jacktiangjwan.con.conf 然后需修改站点统计配置文件中的指定分析的 web 日志文件和指定用来存放统计数据的目录,所修改的配置如下;

  • LogFile:指定日志路径,设置 web 日志文件的位置;

  • SiteDomain:为指定的网站名称;

  • DirData:指定数据目录,但需要创建指定的目录;

# vi /etc/awstats/awstats.www..conf # 修改配置文件,将以下原有的三行配置进行替换成如下即可;
LogFile='/usr/local/httpd/logs/access_log'
SiteDomain='www.'
DirData='/var/lib/awstats'
# mkdir /var/lib/awstats

使用 awstats 提供的 awstats_updateall.pl 脚本,可更新所有站点的日志统计数据。执行该脚本时,系统将会自动分析新增的日志内容,并将分析结果更新到统计数据库中。

# chmod +x awstats_updateall.pl
# ./awstats_updateall.pl now
Running ''/usr/local/awstats/wwwroot/cgi-bin/awstats.pl' -update -config=www. -configdir='/etc/awstats'' to update config www.
Create/Update database for config '/etc/awstats/awstats.www..conf' by AWStats version 7.3 (build 20140126)
From data in log file '/usr/local/httpd/logs/access_log'...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Jumped lines in file: 0
Parsed lines in file: 4
Found 0 dropped records,
Found 0 comments,
Found 0 blank records,
Found 4 corrupted records,
Found 0 old records,
Found 0 new qualified records.

因为 web 日志文件的内容将不断更新,我们可以设置成定时任务来定期并自动的执行该任务来完成日志分析工作。

# crontab -e
*/5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now
# /etc/init.d/crond start
# chkconfig --level 35 crond on

以上步骤做完后,这时需要来验证是否做得成功,需把客户端的 IP 地址及指定网站名称添加在 /etc/hosts 文件中,并进行重启 httpd 服务及 crond 定时任务;

# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.3.123 www.
# service httpd restart
# service crond restart
停止 crond:[确定]
正在启动 crond:[确定]
3.访问 AWStats 分析系统

在客户端打开浏览器地址栏中访问站点 :http://www./awstats/awstats.pl?config=www. 后即可看到 AWStats 日志分析系统的页面(如下图所示)该页面分别按访问时间、用户来源、所用浏览器等多种类别分别列出了详细的网站访问情况;还可以通过左侧栏中可以查看每个小时、天、周、月的网站访问次数、网页数、文件数等信息;除此之外,还有很多其他的功能,在这里就不一一演示了,感兴趣的朋友可以搭建一下该环境研究一下。

在访问 AWStats 分析系统时,需指定 awstats 目录、脚本位置、统计目标等相关信息,这样看来,不方便大家的记忆,输入比较麻烦,因此我们可以在 web 根目录下建立一个自动跳转的 html 网页文件。在 /usr/local/httpd/htdocs/ 目录下建立 abc.html 的文件,将上述访问的 url 写在该文件中。用户只需要访问 http://www./abc.html ,即可自动跳转到 www. 站点的 AWStats 日系分析系统页面中。

# vi /usr/local/httpd/htdocs/abc.html
<html>
<head>
<meta http-equiv=refresh content='0;
url=http://www./awstats/awstats.pl?config=www.'
>

</head>
<body></body>
</html>

演示效果图

END

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多