美文网首页
awstats基本配置以及IP地区的显示

awstats基本配置以及IP地区的显示

作者: Zhaifg | 来源:发表于2015-04-29 14:13 被阅读779次

    前提

    1. 首先安装了httpd,并且httpd的日志格式为combined
    2. 做日志切割时,

    yum方式与源码方式

    1, yum 安装与配置

    1. 安装
    添加epel源
    yum install awstats
    
    1. 修改httpd配置,确保mod_cgi以被加载.
      vim /etc/httpd/conf.d/awstats.conf
    Alias /awstats/icon/ /var/www/awstats/icon/
    ScriptAlias /awstats/ /var/www/awstats/
    <Directory "/var/www/awstats/">
        DirectoryIndex awstats.pl
        Options ExecCGI
        order deny,allow
        deny from all
        allow from 127.0.0.1
        allow from 192.168.1.0/24
    </Directory>
    
    
    1. 创建要统计的网站的配置文件,以主域名方式命令
    # cp /etc/awstats/awstats.localhost.localdomain.conf /etc/awstats/awstats.tecadmin.net.conf
    # vim /etc/awstats/awstats.tecadmin.net.conf
    
    1. 修改相应的配置文件里的相应配置.
    # httpd access log的位置,及文件名
    LogFile="/var/log/httpd/tecadmin.net-access_log"
    # 设置要统计的网站的域名
    SiteDomain="tecadmin.net"
    # 这个网站的其他域名
    HostAliases="tecadmin.net www.tecadmin.net"
    

    还有一些其他的配置比如跳过统计某些IP地址.

    1. 生成数据,

    /usr/bin/perl /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=tecadmin.net -update
    添加crontab定时生成数据.

     0 2 * * * /usr/bin/perl /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=tecadmin.net -update
    
    1. 访问方式

    http://svr1.tecadmin.net/awstats/awstats.pl?config=tecadmin.net

    源码安装

    (1) 下载

    [root@node6 src]# wget http://jaist.dl.sourceforge.net/project/awstats/AWStats/7.2/awstats-7.2.tar.gz
    [root@node6 src]# tar xf awstats-7.2.tar.gz
    [root@node6 src]# mv awstats-7.2 /usr/local/awstats 
    [root@node6 src]# cd /usr/local/awstats  
    [root@node6 awstats]# ls  
    docs  README.TXT  tools  wwwroot
    

    注,由于wget下载下来的包中权限是非root的,所以这里要修改权限,否则稍后*.pl将无法运行。

    (2) 授权

    [root@node6 awstats]# chown -R root.root /usr/local/awstats 
    [root@node6 awstats]# ll  
    总用量 20  
    drwx------. 4 root root 4096 7月  10 04:01 docs  
    -rw-------. 1 root root 6790 7月  10 03:50 README.TXT  
    drwx------. 5 root root 4096 7月  10 04:01 tools  
    drwx------. 7 root root 4096 7月  10 04:01 wwwroot  
    [root@node6 awstats]# chmod +x /usr/local/awstats/tools/*.pl  
    [root@node6 awstats]# cd tools/  
    [root@node6 tools]# ls  
    awstats_buildstaticpages.pl  awstats_exportlib.pl  geoip_generator.pl  logresolvemerge.pl  nginx               webmin  
    awstats_configure.pl         awstats_updateall.pl  httpd_conf          maillogconvert.pl   urlaliasbuilder.pl  xslt  
    [root@node6 tools]# chmod +x /usr/local/awstats/wwwroot/cgi-bin/*.pl  
    [root@node6 tools]# cd ..  
    [root@node6 awstats]# cd wwwroot/cgi-bin/  
    [root@node6 cgi-bin]# ls  
    awdownloadcsv.pl  awredir.pl  awstats.model.conf  awstats.pl  lang  lib  plugins
    

    (3) 配置要统计网站
    我们要执行/usr/local/awstats/tools下的awstats_configure.pl配置向导,用来生成awstats的配置文件,awstats配置文件的命名规则是awstats.website.conf。

    [root@node6 ~]# cd /usr/local/awstats/tools/ 
    [root@node6 tools]# ./awstats_configure.pl
    此时会出现如下提示,
    ----- 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
    -----> 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):
    > /usr/local/apache2/conf/httpd.conf #这里让你输入apache配置文件的目录,我这里的apache是源码安装的,所以我的路径是/usr/local/apache2/conf/httpd.conf 
    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.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... #提示不能自动加入crontab定时任务,需要稍后自己添加,我们按回车继续即可。
    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... #提示配置文件创建完成和如何更新配置及建立静态报告页,这里我们回车即可结束这个配置向导。
    

    (4).查看并修改一下这个配置文件

    [root@node6 tools]# cd /etc/awstats/ 
    [root@node6 awstats]# ls  
    awstats.www.test.com.conf
    [root@node6 awstats]# vim awstats.www.test.com.conf #这个配置文件有很多配置,我们这里只讲解重点配置。
    LogFile="/log/www/access_%YYYY-24%MM-24%DD-24.log"  #日志文件存放路径,其中%YYYY-24%MM-24%DD是指年月日模式
    DirData="/var/lib/awstats"  #创建生成的数据路径
    Lang="cn"  #默认语言中文
    SkipHosts="127.0.0.1 REGEX[^192\.168\.]" #本地及内部的访问不做分析统计
    LevelForWormsDetection=2  #日志等级,不对警告日志进行统计
    

    (5).下面我们来修改一下apache配置文件

    root@node6 www]# vim /usr/local/apache2/conf/httpd.conf
    #CustomLog logs/access_log combined 
    CustomLog "|/usr/local/sbin/cronolog /log/www/access_%Y%m%d.log" combined
    

    (6).新建apache日志目录

    [root@node6 ~]# mkdir -pv /log/www/ 
    mkdir: 已创建目录 "/log"  
    mkdir: 已创建目录 "/log/www/"  
    [root@node6 ~]# cd /log/www/  
    [root@node6 www]# chmod -R 755 /log/www/  
    [root@node6 www]# chown -R daemon /log/www/
    

    (7).重新启动apache服务器

    [root@node6 www]# /usr/local/apache2/bin/apachectl restart
    (8).创建awstats的数据存放目录`

    [root@node6 www]# mkdir -pv /var/lib/awstats 
    [root@node6 www]# chmod 755 /var/lib/awstats
    

    (9) 加入定时任务.

    [root@node6 ~]# /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 7.2 (build 1.992) 
    From data in log file "/log/www/access_20131228.log"...  
    Phase 1 : First bypass old records, searching new record...  
    Direct access to last remembered record has fallen on another record.  
    So searching new records from beginning of log file...  
    Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...  
    Jumped lines in file: 0  
    Parsed lines in file: 155446  
    Found 8 dropped records,  
    Found 0 comments,  
    Found 0 blank records,  
    Found 1 corrupted records,  
    Found 0 old records,  
    Found 155437 new qualified records.
    
    crontab -e
     /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.test.com
    

    问题总结

    1) 建立多个日志统计的方式:可以多次运行`./awstats_configure.pl`,也可以复制配置文件进行修改.

    2) 修复中文乱码问题
      确保URI::Escape已安装

    perl -MCPAN -e 'install URI::Escape'
    # 源码安装
    [root@node6 src]# wget http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/URI-1.60.tar.gz
    [root@node6 src]# tar xf URI-1.60.tar.gz
    [root@node6 src]# cd URI-1.60
    [root@node6 src]# perl Makefile.PL
    [root@node6 src]# make && make install
    

    打开解码,解码UTF8

    [root@node6 ~]# vim /etc/awstats/awstats.www.test.com.conf
    #LoadPlugin="decodeutfkeys" #1300 行
    LoadPlugin="decodeutfkeys"
    

    IP显示地区

    1. 使用GeoIP的方式
    (1).MaxMind目前免费提供了GeoIP和GeoIPCityLite数据包:可以定期每个月从以下地址下载

    [root@node6 src]# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
    [root@node6 src]# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
    [root@node6 src]# ls
    GeoIP.dat.gz GeoLiteCity.dat.gz
    

    注,下载下来用gunzip解压即可。

    [root@node6 src]# gunzip GeoIP.dat.gz
    [root@node6 src]# gunzip GeoLiteCity.dat.gz
    [root@node6 src]# ls
    GeoIP.dat GeoLiteCity.dat
    

    (2).新建的目录,把两个文件移入新建的目录

    [root@node6 src]# mkdir /var/geoip
    [root@node6 src]# mv GeoIP.dat GeoLiteCity.dat /var/geoip
    

    (3).安装GeoIP与GeoIP perl库

    [root@node6 src]# yum install –y GeoIP perl-Geo-IP
    perl -MCPAN -e "install Geo::IP::PurePerl"
    
    

    (4).修改awstats配置文件

    [root@node6 ~]# vim /etc/awstats/awstats.www.test.com.conf
    #LoadPlugin="geoip GEOIP_STANDARD /pathto/GeoIP.dat" #1429行
    #LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /pathto/GeoIPCity.dat" #1438行
    修改为:
    LoadPlugin="geoip GEOIP_STANDARD /var/geoip/GeoIP.dat"
    LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /var/geoip/GeoLiteCity.dat"
    

    2. 使用QQ纯真版IP
    (1) 在awstats的wwwroot下的plugin目录里下载

    cd /usr/local/awstats/wwwroot/cgi-bin/plugins
    # yum安装时目录为:/usr/share/awstats/wwwroot/cgi-bin/plugins ,没有则建立
    wget http://www.haiyun.me/download/qqwry.pl
    wget http://www.haiyun.me/download/qqhostinfo.pm
    
    

    获取最新的IP信息的方式为:到update.cz88.net中下在windows安装版,之后在安装目录里有qqwry.dat,既是最新的数据。

    (2)上传qqwry到awstats的wwwroot下的plugin目录里.

    (3) 修改插件配置

    #修改qqwry.pl内IP数据目录:
    my $ipfile="${DIR}/plugins/qqwry.dat"; 
    

    (4) 添加插件到awstats

    #修改awstats配置加载扩展:
    LoadPlugin="qqhostinfo"
    

    3.删除旧的统计数据库

    [root@node6 ~]# rm -rf /var/lib/awstats/*
    

    4.重新生成一下数据库

    [root@node6 ~]# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.test.com
    

    参考

    http://freeloda.blog.51cto.com/2033581/1346412
    http://tecadmin.net/steps-to-configure-awstats-on-centos-and-rhel-system/
    http://www.haiyun.me

    相关文章

      网友评论

          本文标题:awstats基本配置以及IP地区的显示

          本文链接:https://www.haomeiwen.com/subject/wxvvfttx.html