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

[经验分享] AWstats 分析Nginx访问日志

[复制链接]

尚未签到

发表于 2018-11-10 07:04:59 | 显示全部楼层 |阅读模式
  软件下载地址:http://awstats.sourceforge.net/
  我下载的是稳定版本awstats-6.95.tar.gz
  先上传下载文件到服务器上我习惯放在/opt下面
  一、解压软件包:
  tar zxvf  awstats-6.95.tar.gz
  然后放到/usr/local/下面
  mv awstats-6.95 /usr/local/awstats
  二、接着执行 tools 目录中的 awstats_configure.pl 配置向导,创建一个新的统计
  [root@www tools]# perl awstats_configure.pl
  ----- AWStats awstats_configure 1.0 (build 1.8) (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>  - 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):
  >none     #因为是分析nginx日志
  Your web server config file(s) could not be found.
  You will need to setup your web server manually to declare AWStats
  script as a CGI, if you want to build reports dynamically.
  See AWStats setup documentation (file docs/index.html)
  -----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'
  File awstats.model.conf updated.
  -----> 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  # 没有发现web 配置文件创建一个 选择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.test.com  #你网站访问的网址
  -----> 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.test.com.conf'
  Config file /etc/awstats/awstats.www.test.com.conf created.
  -----> 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.test.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...
  A SIMPLE config file has been created: /etc/awstats/awstats.www.test.com.conf
  You should have a look inside to check and change manually main parameters.
  You can then manually update your statistics for 'www.test.com' with command:
  > perl awstats.pl -update -config=www.test.com
  You can also build static report pages for 'www.test.com' with command:
  > perl awstats.pl -output=pagetype -config=www.test.com
  Press ENTER to finish...
  安装配置完成
  三、编辑配置文件/etc/awstats/awstats.www.test.com.conf
  找到LogFile="/var/log/httpd/mylog.log"
  修改成nginx日志文件的正确位置
  LogFile="/var/log/nginx/test.com.acc.log"
  保存,退出。
  四、修改Nginx 日志文件生成格式一适应awstats的需要
  标红部分 注意:格式一定要注意,不能多一个空格,或少一个空格,否则在后面更新的时候会报告日志格式错误(这个问题浪费了我一天的时间)
  http {
  client_header_buffer_size 16k;
  large_client_header_buffers 4 64k;
  include       mime.types;
  default_type  application/octet-stream;
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  '$status $body_bytes_sent "$http_referer" '
  '"$http_user_agent" $http_x_forwarded_for';
  server {
  listen       80;
  server_name  www.test.com;
  access_log  /var/log/nginx/test.com.acc.log main;
  保存后重启Nginx
  由于在配置日志分析之前网站已经运行了一段时间,所以我得把线有的日志给清除掉,因为格式不匹配
  Cat /dev/null  > /var/log/nginx/test.com.acc.log
  现在多刷几次网站有了日志记录就行了
  五、现在手动运行统计脚本:(添加到cron 任务中)
  [root@www cgi-bin]#perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl  -update -config=www.test.com
  Create/Update database for config "/etc/awstats/awstats.www.test.com.conf" by AWStats version 6.95 (build 1.943)
  From data in log file "/var/log/nginx/test.com.acc.log "...
  Phase 1 : First bypass old records, searching new record...
  Direct access after last parsed record (after line 1348)
  Jumped lines in file: 1348
  Found 1348 already parsed records.
  Parsed lines in file: 798
  Found 0 dropped records,
  Found 9 corrupted records,
  Found 0 old records,
  Found 789 new qualified records.
  出现上面的输出,表示完全没问题可以继续。
  如果Nginx日志格式不对就会报错:如下:
  This means each line in your web server log file need to have "combined log format" like this:
  111.22.33.44 - - [10/Jan/2001:02:14:14 +0200] "GET / HTTP/1.1" 200 1234 "http://www.fromserver.com/from.htm" "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
  And this is an example of records AWStats found in your log file (the record number 50 in your log):
  220.181.27.12 - - [08/Jul/2010:04:06:32 +0800] HEAD /yiyou/27/pages/2930.swf HTTP/1.0 "200" 0 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" "-"
  Setup ('/etc/awstats/awstats.www.test.com.conf' file, web server or permissions) may be wrong.
  Check config file, permissions and AWStats documentation (in 'docs' directory).
  六、都说nginx对cgi支持不是很好,我在此也就不写关于cgi的配置了
  Awstats可以输出静态html格式的文件,而且静态页面还是很低碳的啊,哈哈! (添加到计划任务中)
  [root@wwwcgi-bin]#perl/usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.test.com  -lang=cn -dir=/var/www/html -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
  #这个脚本命令就是输出静态格式的html 页面 -lang=cn语言,当然是中文了,-dir=/var/www/html 输出文件的路径。
  Launch update process : "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -update -configdir=
  Build main page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output
  Build alldomains page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=alldomains
  Build allhosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=allhosts
  ………忽略后面输出
  这时候可以配置Nginx访问那些静态页面了
  http://www.test.com/awstats.www.test.com.html
  访问认证的配置网上也有很多,在这里就免去了http://blog.51cto.com/attachment/201007/172617331.jpg
  到这里也就差不多完事了!
  七、在网上看到了一篇关于显示IP地址地区的配置,在这次我也添加进去了,还不错! :)
  (感谢那些为互联网做出贡献的人!感谢这位作者!)
  具体方法:
  1. 首先下载插件(qqhostinfo.pm)。把它放在、/usr/local/awstats/wwwroot/cgi-bin/plugins中。
  2. 下载分析QQWry.dat的perl脚本(qqwry.pl)。放在同一目录。
  3. 修改,qqwry.pl中:
  ./QQWry.Dat 修改为 ${DIR}/plugins/QQWry.Dat
  4. 去网上下载QQWry.Dat放在同一目录中 下载(http://www.cz88.net/fox/),注意文件名一定要是QQWry.Dat
  5. 编辑你得awstats配置文件,大概在LoadPlugin="hostinfo"的后面增加一行
  LoadPlugin="qqhostinfo"
  重新运行上面第五、六步。

  常见错误解决:
  一、AWStats搜索关键词中文出现乱码解决办法
  1. 修改站点配置文件awstats.www.test.com.conf
  把LoadPlugin=”decodeutfkeys”前边的#去掉
  2. 安装Perl模块
  二、[root@www nginx]#cpan
  cpan> install Encode
  cpan> install URI::Escape
  重新运行上面第五、六步。
  本文完!


运维网声明 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.iyunv.com/thread-632997-1-1.html 上篇帖子: Nginx重启时丢失nginx.pid文件 下篇帖子: 统计nginx访问量
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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