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

[经验分享] 使用awstats分析网站日志

[复制链接]
发表于 2019-1-30 07:45:04 | 显示全部楼层 |阅读模式
  运营需要网站的数据统计,本来想用JS的方式来统计所有请求的情况,但是由于时间紧迫,所以重新部署awstats这个工具!

AWStats是一个基于PerlWEB日志分析工具,主页:http://awstats.sourceforge.net
  Awstats 是一个免费非常简洁而且强大有个性的统计工具。它可以统计您站点的如下信息:
① 访问量,访问次数,页面浏览量,点击数,数据流量等
② 精确到每月、每日、每小时的数据
③ 访问者国家
④ 访问者 IP
⑤ Robots/Spiders 的统计
⑥ 纺客持续时间
⑦ 对不同 Files type 的统计信息
⑧ Pages-URL 的统计
⑨ 访客操作系统浏览器等信息
其它信息(搜索关键字等等)
  AWStats 是一个免费的强大而有个性的工具,带来先进的网络流量,FTP 或邮件服务器统计图。 本日志分析器作为 CGI  或从命令行在数个图形网页中显示你日志中包含的所有可能信息。  它利用一部分档案资料就能经常很快地处理大量日志档案,它能分析日志文件来自从各大服务器工具,如 Apache日志档案(NCSA  combined/XLF/ELF log format or common/CLF log format), WebStar,IIS  (W3C的日志格式)及许多其他网站,Proxy(代理服务器)、Wap、流量服务器、邮件服务器和一些 FTP 服务器。

AWStats的运行模式
  1、统计分析日志:将结果保存在一个txt文件中,最新版本支持xml数据格式。
  2、输出分析结果:利用cgi程序输出,或生成静态html文件进行浏览。

AWStats的安装与配置
  先创建如下两个目录:
  /etc/awstats -- 网站统计的配置文件存放位置
  /var/lib/awstats -- 网站统计的数据文件
  awstats默认的目录是/usr/local/,所以下载下来请保存至此。
  awstats采用perl来进行安装,所以服务器一定要有perl环境 yum install perl ;


  • cd /usr/local;
  • wget http://prdownloads.sourceforge.net/awstats/awstats-7.0.tar.gz
  • tar zxvf awstats-7.0.tar.gz;
  • mv awstats-7.0  awstats;
  • chown apache:apache awstats -R  #设置web服务能访问此目录
  • perl /usr/local/awstats/tools/awstats_configure.pl #执行awstats安装

  • 安装过程如下:
  • ----- AWStats awstats_configure 1.0 (build 1.9) (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
  • Warning: AWStats standard directory on Linux OS is '/usr/local/awstats'.
  • If you want to use standard directory, you should first move all content
  • of AWStats distribution from current directory:
  • /root
  • to standard directory:
  • /usr/local/awstats
  • And then, run configure.pl from this location.
  • Do you want to continue setup from this NON standard directory [yN] ?   
  • #这个选项告知你awstats默认应该安装在/usr/local/awstats下,问你是否采用默认的目录,默认即可

  • -----> 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):
  • >  
  • #这个选项是问你的apache默认配置文件在哪,awstats会在你的配置文件中增加相关配置选项。
  • 如果你用Nginx等其他web 跳过此选项,我的配置是: /etc/httpd/conf/httpd.conf

  • -----> Check and complete web server config file '/usr/local/apache2/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
    #AWStats推荐使用combined格式的日志,apache默认使用common格式.

  • 所以这个地方提示要不要修改apache的配置文件将日志格式改为combined,当然回答yes

  • -----> Check and complete web server config file '/etc/httpd/conf/httpd.conf'
  • 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 '' directive
    AWStats directives added to Apache config file.
  • #apache的配置文件里面增加了上述内容,里面是一些目录和别名的设置.这部分一般加到了文件的最后面.

  • -----> 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] ?  这个选项是询问是否要要生成独立的 conf 文件的名称,
  • 因为 conf 文件的名称都是 awstats.yourdomainname.conf 格式的,所以这里要求你输入你要监测的域名,
  • 其实这个域名只是与其他域名相区分的,并不一定非要真实的。

  • -----> 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):
    >  这个选项是问你独立的配置文件(见上一个问题)放在哪?默认在/etc/awstats/

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

  • -----> Create config file '/etc/awstats/awstats.www.sonkwo.com.conf'
    Config file /etc/awstats/awstats.www.sonkwo.com.conf created.
    -----> Restart Web server with '/sbin/service httpd restart'
    Stopping httpd:                                            [  OK  ]
    Starting httpd:                                            [  OK  ]
  • -----> Add update process inside a scheduler
    Sorry, configure.pl does not support automatic add to cron yet.
    You can do it manually by adding the following command to your cron:
    /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.sonkwo.com
    Or if you have several config files and prefer having only one command:
    /usr/local/awstats/tools/awstats_updateall.pl now
    Press ENTER to continue...
  • #上面是告知你你可以在crontab中单独增加/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.sonkwo.com来定期刷新域:
    www.sonkwo.com域的日志统计,也可以使用/usr/local/awstats/tools/awstats_updateall.pl now 来刷新
    所有域的(/etc/awstats下)的统计

    A SIMPLE config file has been created: /etc/awstats/awstats.www.sonkwo.com.conf
    You should have a look inside to check and change manually main parameters.
    You can then manually update your statistics for 'www.sonkwo.com' with command:
    > perl awstats.pl -update -config=www.sonkwo.com
    You can also read your statistics for 'www.sonkwo.com' with URL:
    > http://localhost/awstats/awstats.pl?config=www.sonkwo.com
    #配置文件创建完成,可以通过 perl awstats.pl -update -config=www.sonkwo.com来刷新你的日志统计
    访问方式 http://$awstats_ip/awstats/awstats.pl?config=www.sonkwo.com


AWStats配置文件


  • #vi /etc/awstas/awstats.yourdomain.conf
  • 更改:
  • LogFile (要分析的日志的绝对路径)
  • DirData  (指定AWSTATS生成数据的存放目录,可以任意指定,但注意目录
  •            目录要具有读写权限,可以设置为777或755)
  • DirCgi   (cgi的路径,是相对于网站根目录的绝对路径,Default: "/cgi-bin"  
  • DirIcons  (icon的路径,是相对于网站根目录的绝对路径:/icon)
  • SiteDomain (输入你的域名:yourdomain)
  • HostAliases (主机别名,如果还有其他的二级域名或三级域名,请在此添加。)
  • AllowToUpdateStatsFromBrowser (是否允许用户从浏览器中实时更新统计。0:不允许;1:允许)
  • Lang="cn" (设置网页显示语言为简体中文。)


问题解决


  • 问题1:Error: Failed to open '/root/wwwroot/cgi-bin/awstats.model.conf' for read.
  •   解决:进入awstats程序目录,本例为:/usr/local/awstats ,然后在运行
      perl /usr/local/awstats/tools/awstats_configure.pl
  • 问题2:Error: AWStats database directory defined in config file by 'DirData'
    parameter (/var/lib/awstats) does not exist or is not writable.
    Setup ('/etc/awstats/awstats.www.sonkwo.com.conf' file, web server or permissions) may be wrong.
    Check confi
    g file, permissions and AWStats documentation (in 'docs' directory).  解决:确保存在/var/lib/awstats目录,如果存在改变权限 chmod 777 /var/lib/awstats -R

  •   问题3:如何修改首页LOGO 和 链接地址
  •   解决:在 /etc/awstas/awstats.yourdomain.conf 中找到如下两个选项

  •   Logo="awstats_logo6.png"  #logo图片要放在awstats/wwwroot/icon/other/下
    LogoLink="http://www.sonkwo.com"

  •   问题4:如何修改统计页面的中文字体
  •   解决:要根据你在/etc/awstas/awstats.yourdomain.conf中设置的语言,如果你选择的是
      Lang="cn"  则修改/usr/local/awstats/wwwroot/cgi-bin/lang/awstats-cn.txt文件即可

  •   问题5:统计中,“用以搜索的关键字” “用以搜索的词语”字体乱码,如何解决?
  •   分析:因为现在的搜索引擎都是使用UTF8,而Awstats是使用decodeUTFkeys这个plugin来处理搜索引擎的UTF8关键字,
  •   默认是没有打开的,所以在显示上会出现乱码
  •   解决:启用 DecodeUTFKeys,在 /etc/awstas/awstats.yourdomain.conf 把 LoadPlugin="decodeutfkeys"
  •   的注释去掉,根据插件的描述(如下)还要安装Encode and URI::Escape 的perl模块,使用cpan安装
  •   cpan> install Encode ; cpan> install  URI::Escape
  •   # PLUGIN: DecodeUTFKeys
    # REQUIRED MODULES: Encode and URI::Escape
    # PARAMETERS: None
    # DESCRIPTION: Allow AWStats to show correctly (in language charset)
    # keywords/keyphrases strings even if they were UTF8 coded by the
    # referer search engine.
    #






运维网声明 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-669362-1-1.html 上篇帖子: awstats+jawstats自动分析日志2 下篇帖子: 为awstats日志查看添加密码验证
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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