设为首页 收藏本站
查看: 3395|回复: 0

[经验分享] AWStats日志分析工具

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-10-8 09:27:32 | 显示全部楼层 |阅读模式
awstats官方网站:http://awstats.sourceforge.net/

perl官方网站:http://www.perl.com/


Awstats是一个非常简洁而且强大的统计工具。它可以统计您站点的如下信息:

一:访问量,访问次数,页面浏览量,点击数,数据流量等精确到每月、每日、每小时的数据
二:访问者国家、访问者IP、操作系统、浏览器等
三:Robots/Spiders的统计
四:纺客持续时间
五:对不同Files type 的统计信息
六:Pages-URL的统计
七:其它信息(搜索关键字等等)


===============================开始配置=======================================

(1)环境


1. 当前系统环境

[iyunv@web01 ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)
[iyunv@web01 ~]# hostname -I
10.0.0.8 172.16.1.8
[iyunv@web01 ~]# hostname
web01
[iyunv@web01 ~]# uname -r
2.6.32-573.el6.x86_64


2. 配置阿里云的base源和epel源(CentOS6)

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum repolist


Awstats基于Perl的WEB日志分析工具,网上关于它的介绍还是比较多的,因为是基于perl开发的,在管在windows还是linux下都需要先安装perl环境。所以,我们先安装perl。另外,还需要一个apache环境,

[iyunv@web01 ~]# rpm -qa perl
perl-5.10.1-141.el6.x86_64


需要提前安装apache服务

[iyunv@web01 ~]# yum -y install httpd
[iyunv@web01 ~]# rpm-qa httpd
httpd-2.2.15-54.el6.centos.x86_64


启动apache服务

[iyunv@web01 ~]# /etc/init.d/httpd start
ServerName                                                     [ OK  ]
[iyunv@web01 ~]# chkconfig httpd on
[iyunv@web01 ~]# chkconfig --list httpd
httpd          0:off   1:off   2:on   3:on    4:on    5:on   6:off


(2)配置


1. 创建相关目录

[iyunv@web01 ~]# mkdir /etc/awstats           #<== 用于存放站点日志分析的配置文件
[iyunv@web01 ~]# mkdir /var/lib/awstats       #<== 用于存放日志数据信息


2. 上传awstats-6.4.tgz 源码包文件

[iyunv@web01 ~]# cd /usr/local/src/
[iyunv@web01 src]# rz awstats-6.4.tgz
[iyunv@web01 src]# tar xf awstats-6.4.tgz
[iyunv@web01 src]# ls
awstats-6.4 awstats-6.4.tgz


3. 复制目录及目录内的所有项目到/usr/local/目录下(去掉版本号,方便使用)

[iyunv@web01 src]# cp -R ./awstats-6.4 /usr/local/awstats
[iyunv@web01 src]# ll -d /usr/local/awstats
drwx------ 5 root root 4096 Oct  4 00:50 /usr/local/awstats


4. 配置awstats

[iyunv@web01 local]# cd /usr/local/awstats/tools


Awstats的配置有自带的配置工具awstats_configure.pl ,首先用vim打开configure.pl文件,看看第一行有关perl运行环境的配置是否正确

[iyunv@web01 tools]# vim awstats_configure.pl
#!/usr/bin/perl


运行配置文件进行配置

[iyunv@web01 tools]# perl awstats_configure.pl
Config file path ('none' to skip web server setup):
> /etc/httpd/conf/httpd.conf                          #<== 填写配置文件的路径
Do you want me to build a new AWStatsconfig/profile
file (required if first install) [y/N] ? y
Your web site, virtual server or profile name:
> web                                                  #<==设置一个网站的域名或名称(自定义)
Directory path to store config file(s) (Enter fordefault):
>                                                      #<== 以下均可一路回车
You can then manually update your statistics for'web' with command:
> perl awstats.pl -update -config=web                  #<== 分析日志命令(直接回车)
You can also read your statistics for 'web' withURL:
> http://localhost/awstats/awstats.pl?config=web       #<== 回车


awstats_configure.pl工具会自动修改您的apache配置,在apache的配置文件httpd.conf文件中自动修改下面信息

[iyunv@web01 tools]# tail /etc/httpd/conf/httpd.conf
#
# This is to permit URL access to scripts/files inAWStats directory.
#
<Directory"/usr/local/awstats/wwwroot">
    OptionsNone
   AllowOverride None
    Orderallow,deny
    Allowfrom all
</Directory>


awstats_configure.pl还将根据安装过程中您的回答(要分析的网站名称)信息,自动产生/etc/awstats/awstats.web.conf文件(该文件主要功能就是指定要分析日志文件的路径)

[iyunv@web01 tools]# ll /etc/awstats/
total 60
-rw-r--r-- 1 root root 58330 Oct  4 01:01 awstats.web.conf


在awstast生成的配置文件中指定apache日志的路径

[iyunv@web01 ~]# cd /etc/awstats/
[iyunv@web01 awstats]# vim awstats.web.conf
LogFile="/var/log/httpd/access_log"               #<== 改为我们要分析的apache的日志文件路径


因为我们需要执行awstast中自带的perl脚本分析日志,所以要对脚本进行授权

[iyunv@web01 awstats]# cd/usr/local/awstats/wwwroot/cgi-bin
[iyunv@web01 cgi-bin]# chmod +x awstats.pl       #<== 加可执行权限
[iyunv@web01 cgi-bin]# ll awstats.pl
-rwxr-xr-x 1 root root 527395 Oct  4 00:50 awstats.pl


(3)测试


执行分析日志脚本并测试

[iyunv@web01 ~]# perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl-update -config=web
#-----------------出现以下结果表明成功-----------------------------
Update for config"/etc/awstats/awstats.web.conf"
With data in log file"/var/log/httpd/access_log"...
Phase 1 : First bypass old records, searching newrecord...
Searching new records from beginning of log file...
Jumped lines in file: 0
Parsed lines in file: 0
Found 0dropped records,
Found 0corrupted records,
Found 0 oldrecords,
Found 0 newqualified records.


现在将分析的日志结果放到站点目录下的一个文件,得以在web界面上查看日志分析的结果

cd /usr/local/awstats/wwwroot/cgi-bin/
perl awstats.pl -update -config=web -output-staticlinks >/var/www/html/awastats.html

# 提示:每次分析日志时都需要将其重定向到站点下的页面才能在web界面上查看
现在即可打开浏览器进行访问http://10.0.0.8/awastats.html
[iyunv@web01 ~]# chown -R apache.apache /var/www/html/   #<== 授权站点目录
wKiom1f2D52zbgw1AADpdqugRK4721.jpg

以下模拟客户访问网站进行测试
1. 创建测试文件

[iyunv@web01 ~]# cd /var/www/html/
[iyunv@web01 html]# echo 123 >test1.html
[iyunv@web01 html]# echo 123 >test2.html
[iyunv@web01 html]# echo 123 >test3.html


2. 使用ab命令模拟用户访问apache服务器

ab -c 1000 -n 1000 http://10.0.0.8/test1.html
ab -c 2000 -n 2000 http://10.0.0.8/test2.html
ab -c 3000 -n 3000 http://10.0.0.8/test3.html
ab -c 3000 -n 3000 http://10.0.0.8/wastats.html


3. 现在开始执行perl脚本分析apache访问日志(在命令行查看日志分析结果)

[iyunv@web01 cgi-bin]# perl awstats.pl -opdate-config=web
Update for config"/etc/awstats/awstats.web.conf"
With data in log file"/var/log/httpd/access_log"...
Phase 1 : First bypass old records, searching newrecord...
Searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history ondisk after 20000 hosts)...
Jumped lines in file: 0                       
Parsed lines in file: 9631                    
Found 84dropped records,
Found 0corrupted records,
Found 0 oldrecords,
Found 9547new qualified records.


4. 现在将分析日志的结果直接重定向到站点目录的文件下(通过web界面查看)

perl awstats.pl -update -config=web -output-staticlinks >/var/www/html/awastats.html


5. 现在打开浏览器访问http://10.0.0.8/awastats.html
wKioL1f2EByR0s_vAADSP_FE_P4204.jpg


被访问最多的URL页面:
wKiom1f2EHGz1pHaAABpDzRvGBE301.jpg

查看访问的主机:
wKioL1f2EG_AtC1QAAAvEXYBrK8808.jpg


错误页面显示:
wKiom1f2EG-jldT_AAAcYOZGFdk320.jpg

   .........
      ..........
         ..........
              此日志分析界面还有很多信息,就不一一列举啦!



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-282907-1-1.html 上篇帖子: awstats日志分析系统部署 下篇帖子: awstats的安装和配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表