为Apache安装日志分析工具Awstats
February 27th, 2009 Posted in Linux, 乱七八糟由于apache日志太过于庞大,光借助中国站长网的免费统计工具来分析还是远远不够,所以想在本地安装一个Awstats来进行分析。
我们的安装环境是CentOS52:
Awstats下载地址:http://prdownloads.sourceforge.net/awstats/awstats-6.9.tar.gz。
如果是其他系统,请到这里下载:http://awstats.sourceforge.net/#DOWNLOAD
安装Awstats
下载并解压:
1 2 3 |
# wget http://prdownloads.sourceforge.net/awstats/awstats-6.9.tar.gz # tar -xvf awstats-6.9.tar.gz # mv awstats-6.9 /usr/local/awstats |
之后,我们要进行到awstats目录里面对其进行配置。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# cd /usr/local/awstats/tools # perl awstats_configure.pl ----- AWStats awstats_configure 1.0 (build 1.8) (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): > |
这里,我们需要填写自己的apache的配置文件的路径,CentOS默认是/etc/httpd/conf/httpd.conf
awstats在自动为其添加一系列的配置之后,就会停在这个地方,我们输入”y”,选择建立一个新的配置文件
1 2 3 |
-----> 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] ? |
这时,awstats会询问我们网站的名称,我这里填写blog.myhnet.cn
1 2 3 4 5 6 |
-----> 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: > |
之后的东西,如果没什么特殊要求,一直回车就是了
编辑配置文件
Awstats会在/etc/awstats目录下生成一个名称为awstats.yourname.conf的文件。比如我得到的文件就是awstats.blog.myhnet.cn.conf。
接下来,我们要修改这个文件当中的一些参数:
找到:
1 |
LogFile="/var/log/httpd/mylog.log" |
将其中的/var/log/httpd/mylog.log修改成为你网站的日志文件位置。
如果你想通过在网页上点击update来更新信息的话,除了保证apache用户有读取网站日志文件的权限之后,还要做以下的操作:
找到
1 |
EnableLockForUpdate=0 |
改为
1 2 |
AllowToUpdateStatsFromBrowser=1 EnableLockForUpdate=1 |
找到
1 |
SaveDatabaseFilesWithPermissionsForEveryone=0 |
改为
1 |
SaveDatabaseFilesWithPermissionsForEveryone=1 |
相关配置修改
接下来,我们还要修改apache的配置文件,把网站的日志格式改为combined,然后重启apache,我们就在浏览器中输入下面的地址可以查看网站的统计信息了(把yoursite换成你开始配置的域名)
http://localhost/awstats/awstats.pl?config=yoursite
最后,创建awstats的数据目录:
1 2 |
# mkdir -p /var/lib/awstats # chmod a+rwx /var/lib/awstats |
如果没有信息的话,点击网页最上面的“update now”,然后等待他自动刷新,应该就可以看到更新的信息了
这种方法有一个不好就是统计信息不会自动更新,我们也可以利用crontab每十分钟自动更新一次(把yoursite换成你开始配置的域名):
1 |
*/10 * * * * (perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=yoursite) &> /dev/null |
安装GeoIP
GeoIP需要依次安装下面GeoIP C API与GeoIP Perl API(网方网站:http://www.maxmind.com/app/perl?rId=awstats)
安装GeoIP C API
1 2 3 4 5 6 7 |
# wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.6.tar.gz # tar -xf GeoIP-1.4.6.tar.gz # cd GeoIP-1.4.6 # ./configure # make # make check # make install |
安装GeoIP Perl API
1 2 3 4 5 6 7 |
# wget http://geolite.maxmind.com/download/geoip/api/perl/Geo-IP-1.36.tar.gz # tar -xf Geo-IP-1.36.tar.gz # cd Geo-IP-1.36 # perl Makefile.PL LIBS='-L/usr/local/lib' INC='-I/usr/local/include' # make # make test # make install |
下载IP数据库文件并解压:
1 2 |
# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz # gunzip GeoIP.dat.gz |
修改前面生成的awstats.yoursite.conf,找到下面这行
1 |
#LoadPlugin="geoip GEOIP_STANDARD /pathto/GeoIP.dat" |
去掉前面的#号,把后面的/pathto/GeoIP.dat改为前面解压后的GeoIP.dat的路径,当然,你要保证apache可以读取这个文件
更新后,点击左边的countries,如果看到有许多小国旗就说明安装成功了。