zoukankan      html  css  js  c++  java
  • 使用awstats统计分析tengine日志访问量及各种http网站数据

    下载awstats最新安装包并解压

    cd /usr/local/src
    wget http://www.awstats.org/files/awstats-7.3.tar.gz
    
    tar -zxvf awstats-7.3.tar.gz

    把awstats解压目录更名及把需要用到的pl文件提高到可执行权限、创建需要用到的文件夹:

    mv awstats-7.3 awstats
    
    mv awstats /usr/local/
    
    chmod +x /usr/local/awstats/tools/awstats_configure.pl
    
    chmod +x /usr/local/awstats/wwwroot/cgi-bin/awstats.pl
    
    chmod +x /usr/local/awstats/tools/awstats_buildstaticpages.pl
    
    # 这里是用来存放 AWStats 的数据库文件的
    mkdir /var/lib/awstats

    新建 awstats 配置文件(运行前查看perl版本是否安装)

    perl /usr/local/awstats/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 filesapache groupapacheconfhttpd.conf
    Config file path ('none' to skip web server setup):
    #> none  #因为我们这里用的是 Nginx,所以写 none,跳过。

    回车

    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	#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.moabc.net		#统计网站的域名

    回车

    -----> 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):
    #>

    使用默认直接回车,接下来便会出现以下的提示

    ----> 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.moabc.net  
                   #回头把该命令填入crontab 按指定时间执行
    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.moabc.net.conf  
                #新配置文件所在的路径
    You should have a look inside to check and change manually main parameters.
    You can then manually update your statistics for 'www.moabc.net' with command:
    > perl awstats.pl -update -config=www.moabc.net
    You can also build static report pages for 'www.moabc.net' with command:
    > perl awstats.pl -output=pagetype -config=www.moabc.net
    
    Press ENTER to finish...

    回车完成向导,接下来修改 www.moabc.net 的统计配置

    vi /etc/awstats/awstats.www.moabc.net.conf

    找到统计的日志文件的路径

    LogFile="/var/log/httpd/mylog.log"

    改为

    LogFile="/usr/local/tengine/logs/access_%YYYY-0%MM-0%DD-0.log

    对应上边 Nginx 日志切割程序的所生成的目录存放结构,要注意 Awstats 的年月日格式的跟 Nginx 的写法有所不同。我们现在执行统计的顺序是:

    Nginx 产生日志 –> 日志切割 –> Nginx 继续产生日志 –> 另存切割日志 –> 交由Awstats统计 –> 生成结果

    在本文中 Awstats 所统计的日志,是已切下来的那部分。也能调转顺序,先统计完了再切。不过这比较容易造成统计的遗漏。配置修改完成后,保存退出。然后我们可以开始试一下手动执行。

    创建切割日志脚本:

    vi /usr/local/tengine/sbin/log_cut.sh
    
    #!/bin/bash
    # 这里根据你自己的文件名来写
    
    mv /usr/local/tengine/logs/access.log /usr/local/tengine/logs/access_$(date -d "today" +"%Y%m%d").log
    
    #这里时tengine的pid存放目录
    kill -USR1 `cat /usr/local/tengine/logs/nginx.pid`

    保存

    设置可执行权限:

    chmod +x /usr/local/tengine/sbin/log_cut.sh

    可以试一下运行:

    /usr/local/tengine/sbin/log_cut.sh

    新建要生成 HTML 报告的目录,把图片和CSS复制进去

    mkdir -p /usr/local/tengine/html/awstats/
    
    cp -R /usr/local/awstats/wwwroot/css /usr/local/tengine/html/awstats/
    
    cp -R /usr/local/awstats/wwwroot/icon /usr/local/tengine/html/awstats/

    生成 awstats 数据库:

    /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.moabc.net #这里 -config=www.moabc.net 意思是说使用 /etc/awstats/awstats.www.moabc.net.conf 这个文件

    生成 AWStats 日志分析报告

    /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.moabc.net -lang=cn -dir=/usr/local/tengine/html/awstats/ awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl

    配置tengine页面访问认证

    通过使用apache的创建认证文件工具创建

    htpasswd -c /usr/local/tengine/sbin/pd mike

    如果没用可以用网上的认证工具生成验证账户和密码(如:http://www.4webhelp.net/us/password.php)

    vi /usr/local/tengine/sbin/pd
    
    mike:79y.NuPCo1CqU

    保存

    再tengine配置文件server主机中添加http访问增加一下代码:

    location /awstats {
               charset gbk;
               access_log off;
               root /usr/local/tengine/html; 
           index index.html index.htm;
          
    auth_basic "awstats login";
           auth_basic_user_file /usr/local/tengine/sbin/pd;
     
    }

     location /icon {
            charset gbk;
            access_log off;
            root /usr/local/tengine/html/awstats;
            index index.html index.htm;
    }

     

    至此浏览器打开可以看到分析结果页面了

    接下来配置分析日志定时任务

    crontab -e
    
    00 23 * * 0-6 /bin/bash /usr/local/tengine/sbin/log_cut.sh
    30 23 * * 0-6 /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.moabc.net -lang=cn -dir=/usr/local/tengine/html/awstats/ awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl

    设置成了每天晚上11点执行切割tengine日志,每天网上11点30分执行更新awstats分析日志生成静态分析日志结果html文档到目录。

    awstats中文关键字乱码

    修改awstats的配置文件 

    在使用centos/redhat系统的rpm包安装的awstats的配置路径为/etc/awstats下。打开所要统计网站的配置文件awstats.xxxxx.conf,将下面一行的#去掉:

    LoadPlugin="decodeutfkeys"

    不过打开这个plugin 需要perl模块儿Encode和URI::Escape的支持,一般情况下perl是默认支持的。

    如果打开AWStats会显示:

    Error: Plugin load for plugin 'decodeutfkeys' failed with return code: Error: Can't locate URI/Escape.pm in @INC (@INC contains: /usr/lib/perl5/5.8.7/i686-linux /usr/lib/perl5/5.8.7 /usr/lib/perl5/site_perl/5.8.7/i686-linux  /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl . ./lib ./plugins) at (eval 4) line 1.

    這是因為缺少 Perl 的 URI:Escape模块

    下载安装URI:Escape模块:

    cd /usr/local/src
    
    wget http://www.cpan.org/authors/id/G/GA/GAAS/URI-1.60.tar.gz
    
    tar -zxvf URI-1.60.tar.gz
    
    cd URI-1.60
    
    perl Makefile.PL
    
    make
    
    make install

    然后再更新下awstats重新更新tengine日志

    /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.moabc.net -lang=cn -dir=/usr/local/tengine/html/awstats/ awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl

    刷新下页面关键字乱码就正常了。

    完毕。 

  • 相关阅读:
    Java初试
    could not insert new action connection could not find any information for the class named
    GIT 从入门到放弃大整理
    'XCTest/XCTest.h' file not found
    The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.
    后台数据为空因此程序闪退
    UISearchController Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior
    AFNetworking request failed unacceptable content type text/html
    Xcode找不到模拟器
    如何查看设备的 UDID
  • 原文地址:https://www.cnblogs.com/havenshen/p/3512230.html
Copyright © 2011-2022 走看看