用awstats分析apache日志

1.安装Apache(略)

2.安装cronolog(日志截取工具)
tar zxf cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure
make
make install

3.配置apache
在<VirtualHost *:80>  </VirtualHost>中加入类似:
    CustomLog "|/usr/local/sbin/cronolog /usr/local/apache2/logs/%Y/%m/%d/bbs.testtimes.net-access_log" combined
    ErrorLog "|/usr/local/sbin/cronolog /usr/local/apache2/logs/%Y/%m/%d/bbs.testtimes.net-error_log"
的日志分年月日截取的设置。

4.安装awstats(http://awstats.sourceforge.net/#DOWNLOAD,最新稳定版6.9)
tar jxf awstats-6.9.tar.bz2
mv awstats-6.9 /usr/local/awstats
chown -R root:root awstats
chmod -R 755 awstats
cd /usr/local/awstats/tools
perl awstats_configure.pl

随后跟随设置向导:
Do you want me to setup Apache to write 'combined' log files [y/N] ?y

Do you want me to build a new AWStats config/profile file (required if first install) [y/N] ?y

Your web site, virtual server or profile name:
>www.testtimes.net

Directory path to store config file(s) (Enter for default): //直接回车,默认路径/etc/awstats

配置结束后,向导程序自动在apache配置文件httpd.conf中加入awstats的对应段落。如:
#
# Directives to allow use of AWStats as a CGI
#
Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"

#
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory "/usr/local/awstats/wwwroot">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

5.创建文件夹
mkdir -p /var/lib/awstats

6.给awstats访问设置密码
/usr/local/apache2/bin/htpasswd -cb /etc/awstats/htpasswd admin 123456
在apache配置文件httpd.conf最后添加一段:
<Files "awstats.pl">
    AuthType Basic
    AuthName "awstat access"
    AuthUserFile "/etc/awstats/htpasswd"
    Require valid-user
</Files>

7.重启Apache
/usr/local/apache2/bin/apachectl restart

8.安装国家和城市插件
http://search.cpan.org/CPAN/authors/id/B/BO/BORISZ/Geo-IP-PurePerl-1.23.tar.gz
http://www.maxmind.com/download/geoip/api/c/GeoIP-1.4.6.tar.gz
http://www.maxmind.com/download/geoip/api/perl/Geo-IP-1.38.tar.gz

tar zxf Geo-IP-PurePerl-1.23.tar.gz
cd Geo-IP-PurePerl-1.23
perl Makefile.PL
make
make install

tar zxf GeoIP-1.4.6.tar.gz
cd GeoIP-1.4.6
./configure
make
make install

tar zxf Geo-IP-1.38.tar.gz
cd Geo-IP-1.38
perl Makefile.PL
make
make install

http://www.maxmind.com/download/geoip/database/
http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/
gzip -d GeoLiteCity.dat.gz
cp GeoLiteCity.dat /usr/local/share/GeoIP/
gzip -d GeoIP.dat.gz
cp GeoIP.dat /usr/local/share/GeoIP/

9.安装QQ纯真IP库解析插件
http://www.ieasy.org/download/qqhostinfo.pm
http://www.ieasy.org/download/qqwry.pl

cp qqhostinfo.pm /usr/local/awstats/wwwroot/cgi-bin/plugins
cp qqwry.pl /usr/local/awstats/wwwroot/cgi-bin/plugins

编辑qqwry.pl,把./QQWry.Dat 改为 ${DIR}/plugins/QQWry.Dat
上传QQWry.Dat到/usr/local/awstats/wwwroot/cgi-bin/plugins目录下

10.安装Net-XWhois

tar zxf Net-XWhois-0.90.tar.gz
cd Net-XWhois-0.90
perl Makefile.PL
make
make install

11.编辑awstats配置文件
配置文件位于/etc/awstats目录下,修改如下:
LogFile="/usr/local/apache2/logs/%YYYY/%MM/%DD/www.testtimes.net-access_log"
SiteDomain="www.testtimes.net"

注:对于多域名的日志分析,每个域名对应一个日志文件,可以复制后修改其中的LogFile、SiteDomain这两项即可。

打开如下的LoadPlugin:
LoadPlugin="tooltips"
LoadPlugin="decodeutfkeys"
LoadPlugin="geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat"
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /usr/local/share/GeoIP/GeoLiteCity.dat"
LoadPlugin="hostinfo"
LoadPlugin="qqhostinfo"(该项不存在,手动添加的)

12.分析过去的日志
可以下载并运行附件中的shell脚本程序,传递域名参数,即可开始分析了。

13.添加crontab
crontab -e
* */3 * * * /usr/local/awstats/tools/awstats_updateall.pl now  (每3小时运行一次)

注:以上是多域名的情况,最简单就是那样了,对于单域名也可以写成/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.testtimes.net

 

http://seawavecau.iteye.com/blog/579337

猜你喜欢

转载自qianxunniao.iteye.com/blog/1536190