Bernie Yu » awstats http://bernieyu.com 复刻生活 Tue, 17 May 2016 09:03:15 +0000 zh-CN hourly 1 https://wordpress.org/?v=4.2.38 awstats按天统计 http://bernieyu.com/2015/04/awstats-day-by-day/ http://bernieyu.com/2015/04/awstats-day-by-day/#comments Fri, 17 Apr 2015 05:49:03 +0000 http://bernieyu.com/?p=181   >>阅读全文<<]]> awstats默认是按月统计访问数据,想要查看每天的数据明细该怎么办呢?

其实awstats是支持生成每天的统计数据的,只要在更新时加上-databasebreak=day选项就可以。但这样的数据还不能在WEB页面查看,还需要对页面进行一下小改造。

首先需要下载下面的文件,解压到wwwroot/js下

awstats-day-by-day.zip

解压后文件如下:

-rw-r--r-- 1 www-data www-data 2832 May 21  2010 day-by-day-end.js
-rw-r--r-- 1 www-data www-data 4271 May 21  2010 day-by-day-head.js
-rw-r--r-- 1 www-data www-data  115 Jun  5  2013 readme.txt

更改权限

chown -R www-data:www-data /usr/local/awstats/wwwroot/js

修改awstats配置文件

vi /etc/awstats/awstats.www.conf

HTMLHeadSection="<script language=javascript src="/js/day-by-day-head.js"></script>"

HTMLEndSection="<script language=javascript src="/js/day-by-day-end.js"></script>"

更新数据

/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www -databasebreak=day

修改crontab

/etc/crontab

添加

10 0 * * * root /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www --databasebreak=day

 

访问 http://awstats.bernieyu.com/www 看效果吧~~

 

参考: http://blog.fity.cn/post/391/  。JS文件亦转自此贴。

]]>
http://bernieyu.com/2015/04/awstats-day-by-day/feed/ 0
nginx + awstats 7.3 + GeoIP + PHP-FPM 全记录 http://bernieyu.com/2015/04/nginx-awstats-7-3-geoip-php-fpm-install/ http://bernieyu.com/2015/04/nginx-awstats-7-3-geoip-php-fpm-install/#comments Thu, 16 Apr 2015 08:33:23 +0000 http://bernieyu.com/?p=179   >>阅读全文<<]]> nginx + awstats 7.3 + GeoIP + PHP-FPM 全记录

VPS上已经部署好了nginx+php-fpm,此次为添加awstats的过程全记录,以备后查。

  1. 下载awstats 7.3
    • wget http://prdownloads.sourceforge.net/awstats/awstats-7.3.zip
      
      unzip awstats-7.3.zip
      mv awstats-7.3 /usr/local/awstats
  2. 运行awstats配置向导,生成配置文件
    • cd /usr/local/awstats
      perl tools/awstats_configure.pl
    • 根据屏幕提示输入
    • #-----> 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    #不用apache,输入none
      
      #-----> 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        #创建新的配置文件
      
      #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  #配置文件名称
      
      #Default: /etc/awstats 
      #Directory path to store config file(s) (Enter for default): 
      >(enter) #保存在默认位置,直接回车
      
      
    • 再几次回车后,结束配置向导
  3. 下载GeoIP库
    • wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
      wget  http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
      wget http://geolite.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz
      
      gunzip GeoIP.dat.gz
      gunzip GeoLiteCity.dat.gz
      gunzip GeoIPASNum.dat.gz
      
      mv *.dat /usr/local/awstats/wwwroot/cgi-bin/
      chown -R www-data:www-data /usr/local/awstats/wwwroot/
  4. 下载并安装GeoIP API(C和Perl)
    • wget https://www.maxmind.com/download/geoip/api/c/GeoIP-1.4.8.tar.gz
      
      wget https://www.maxmind.com/download/geoip/api/perl/Geo-IP-1.40.tar.gz
      
      tar xf GeoIP-1.4.8.tar.gz
      cd GeoIP-1.4.8
      ./configure
      make && make install 
      
      #检查是否生成c库文件
      ls /usr/local/lib
      
      rm -rf GeoIP-1.4.8
      
      tar xf Geo-IP-1.40.tar.gz
      cd Geo-IP-1.40
      perl Makefile.PL LIBS='-L/usr/local/lib' 
      make && make install
      
  5. 建立awstats数据库文件夹,并调整权限
    • mkdir /usr/local/awstats/wwwroot/output
      chown -R www-data:www-data /usr/local/awstats/wwwroot
  6. 修改awstats配置文件
    • vi /etc/awstats/awstats.www.conf
      
      #日志文件位置
      #使用logresolvemerge.pl 可以解析多个日志文件,并且可以直接解析.gz这样已经压缩的日志
      LogFile="/usr/local/awstats/tools/logresolvemerge.pl /var/log/nginx/www.bernieyu.com.access.log* |"
      
      #站点域名
      SiteDomain="bernieyu.com"
      HostAliases="bernieyu.com www.bernieyu.com 127.0.0.1 localhost"
      
      #数据输出文件夹
      DirData="/usr/local/awstats/wwwroot/output"
      
      #解决搜索关键字乱码
      LoadPlugin="decodeutfkeys"  
      
      #IP解析插件
      LoadPlugin="geoip GEOIP_STANDARD /usr/local/awstats/wwwroot/cgi-bin/GeoIP.dat"
      LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /usr/local/awstats/wwwroot/cgi-bin/GeoLiteCity.dat"
      LoadPlugin="geoip_asn_maxmind GEOIP_STANDARD /usr/local/awstats/wwwroot/cgi-bin/GeoIPASNum.dat"
      
    • 注意:在网上搜到的文章,大部分都说GeoIPASNum.dat是机构数据,对应的插件是geoip_org_maxmind,这个是错误的,应该是geoip_asn_maxmind
      
      
  7. 生成数据,测试配置
    • chmod +x /usr/local/awstats/wwwroot/cgi-bin/awstats.pl 
      /usr/local/awstats/wwwroot/cgi-bin/awstats.pl  -config=www
  8. 生成密码文件
    • htpasswd -c /etc/awstats/awstats.pwd username
  9. 配置nginx,使其支持awstats
    • 在网上查到的文件大部分都说nginx对perl支持不好,因此需要生成静态文件,再由nginx访问。而事实上awstats本身已经提供了nginx的支持
    • 复制awstats提供的模板到对应位置
    • cp /usr/local/awstats/tools/nginx/awstats-fcgi.php /usr/local/awstats/wwwroot/cgi-bin/fcgi.php
      cp /usr/local/awstats/tools/nginx/awstats-nginx.php /etc/nginx/conf.d/awstats.conf
      ln -s /etc/nginx/conf.d/awstats.conf /etc/nginx/site-available/awstats.conf
    • 编辑awstats.conf
    • vi /etc/nginx/conf.d/awstats.conf
      
      server {
              #去掉127.0.0.1,否则只能本地访问
              listen 80;
              server_name awstats.bernieyu.com;
              access_log /var/log/nginx/awstats.bernieyu.com.access_log main;
              error_log /var/log/nginx/awstats.bernieyu.com.error_log info;
              root /usr/local/awstats/wwwroot;
              index index.html;
              access_log off;
      
              #访问限制,使用之前生成的密码文件
              # Restrict access
              auth_basic "Restricted";
              auth_basic_user_file /etc/awstats/awstats.pwd;
      
      
              # Static awstats files: HTML files stored in DOCUMENT_ROOT/awstats/
              location /awstats/classes/ {
                      alias /usr/local/awstats/wwwroot/classes/;
              }
      
              location /awstats/css/ {
                      alias /usr/local/awstats/wwwroot/css/;
              }
      
              location /awstats/icon/ {
                      alias /usr/local/awstats/wwwroot/icon/;
              }
      
              location /awstats/js/ {
                      alias /usr/local/awstats/wwwroot/js/;
              }
      
              #支持http://awstats.bernieyu.com/www的方式访问
              location ~ ^/([a-z0-9-_\.]+)$ {
                      return 301 $scheme://awstats.bernieyu.com/cgi-bin/awstats.pl?config=$1;
              }
      
              # Dynamic stats.
              location ~ ^/cgi-bin/(awredir|awstats)\.pl {
                      gzip off;
      
                      #指定到php-fpm的位置
                      fastcgi_pass unix:/var/run/php5-fpm.sock;
      
                      fastcgi_param SCRIPT_FILENAME /usr/local/awstats/wwwroot/cgi-bin/fcgi.php;
                      fastcgi_param X_SCRIPT_FILENAME /usr/local/awstats/wwwroot$fastcgi_script_name;
                      fastcgi_param X_SCRIPT_NAME $fastcgi_script_name;
                      include fastcgi_params;
              }
      }
      
  10. 编辑nginx的主配置文件,主要是日志格式,并将awstats.conf包含进去
    • vi /etc/nginx/nginx.conf
      
      http {
          ...
          log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
          include /etc/nginx/sites-available/*.conf;
      }
  11. 在crontab中添加更新的调度
    • vi /etc/crontab
      
      #根据自已经需要配置更新频率
      #every hour
      #0 * * * * root /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www
      
      #every day
      0 0 * * * root /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www
      
  12. 更新一下数据
    • /usr/local/awstats/tools/awstats_updateall.pl now
  13. 访问http://awstats.bernieyu.com/www看效果吧

 

]]>
http://bernieyu.com/2015/04/nginx-awstats-7-3-geoip-php-fpm-install/feed/ 0