用awstats分析apache日志

声明:zhouxuan@testtimes.net原创

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

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值