本站采用的阿里云服务器,阿里云分数据盘和系统盘,数据盘的数据不会丢失,因此需要将awstats的相关数据全部保存到数据盘中,因此就不能采用默认位置安装和配置awstats了。

下面,本文将一步步指导你安装和配置awstats,系统为Centos 5.4,web服务器为nginx

第1步:检测是否安装了perl

# perl -version

This is perl, v5.8.8 built for i386-linux-thread-multi

Copyright 1987-2006, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

awstats需要perl的支持,如果没有安装perl的话,那么赶快去安装一个吧,具体安装步骤请自行搜索。

第2步:下载并安装awstats

awstats的官网地址为:http://awstats.sourceforge.net/

截止2013-11-13,awstats最新的版本为: http://prdownloads.sourceforge.net/awstats/awstats-7.2.tar.gz

cd /alidata/server
wget http://prdownloads.sourceforge.net/awstats/awstats-7.2.tar.gz
tar zxvf awstats-7.2.tar.gz
chown -R root:root awstats-7.2

mkdir -p /alidata/etc/awstats

我这里将awstats安装到阿里云服务器的数据盘下面了,你也可以安装到其他指定位置(所谓的安装,其实解压后直接就能用的,找一个路径放下就好)。

上面最好一条指令,是创建一个保存awstats配置文件的路径,在下面的配置中我们需要用到,因为我们这里不是采用的默认位置嘛,这个路径自己也可以自由指定。

第3步:创建awstats配置文件

awstats提供了脚本,可以辅助我们创建配置文件,那我们就用用吧

cd awstats-7.2/tools
perl awstats_configure.pl

或者直接
perl /alidata/server/awstats-7.2/tools/awstats_configure.pl

这里要保证路径正确就好了,下面会有一系列的提示,按照提示填写就可以了,列举如下:

Warning: AWStats standard directory on Linux OS is '/usr/local/awstats'.
If you want to use standard directory, you should first move all content
of AWStats distribution from current directory:
/alidata/server/awstats-7.2
to standard directory:
/usr/local/awstats
And then, run configure.pl from this location.
Do you want to continue setup from this NON standard directory [yN] ? y

会有个警告,因为我们没有把awstats放到默认位置嘛,别管,这里选y

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

因为我们是nginx,所以填 none

-----> 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

问是不是要创建一个新的配置文件,废话,不创建要你干嘛

-----> 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:
> yourdomain.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):
> /alidata/etc/awstats

配置文件保存路径,这里我们任然不使用默认位置(还记得我第2步中让你创建的目录没,就是那个路径,不创建的话,很可惜的告诉你,你得重新来过了~

-----> Create config file '/alidata/etc/awstats/awstats.yourdomain.com.conf'
 Config file /alidata/etc/awstats/awstats.yourdomain.com.conf created.

OK,配置文件创建完成!配置文件的保存位置也给出了!

-----> 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:
/alidata/server/awstats-7.2/wwwroot/cgi-bin/awstats.pl -update -config=yourdomain.com
Or if you have several config files and prefer having only one command:
/alidata/server/awstats-7.2/tools/awstats_updateall.pl now

这里告诉你,配置脚本没有办法配置定时任务,需要你自己来做!不过,幸好各位遇到我了,我会在下面告诉各位怎么做的,别着急哈~

第4步:修改配置文件

默认创建的配置文件虽然已经有很多东西了,但是任然需要修改几个地方,主要是你日志文件的路径以及awstats的输出数据输出到哪里。我这里将awstats的输出数据保存到配置文件一块了,这个自己自由发挥吧,就是那个DirData了。

LogFile="/alidata/log/nginx/access/%YYYY-1/%MM-1/letu_%YYYY-1%MM-1%DD-24.log"
DirData="/alidata/etc/awstats"

至于LogFile为什么这样设置,那么你可能得看下我之前的一篇文章《nginx日志定时切割脚本(支持多个域名的日志文件)》了。

第5步:配置定时任务

激动了没,配置脚本玩不成的或,我这里马上就要告诉你怎么做了。

#!/bin/bash

/alidata/server/awstats-7.2/wwwroot/cgi-bin/awstats.pl -update -config=yourdomain.com -configdir=/alidata/etc/awstats
/alidata/server/awstats-7.2/tools/awstats_buildstaticpages.pl -update -config=yourdomain.com -configdir=/alidata/etc/awstats -lang=cn -dir=/alidata/www/yourdomain.com/awstats -awstatsprog=/alidata/server/awstats-7.2/wwwroot/cgi-bin/awstats.pl

创建一个shell文件,写入上面内容,注意将yourdomain换成你自己的域名。

上面脚本的作用是分析log数据,并生成漂亮的网页格式,网页的保存位置为

/alidata/www/yourdomain.com/awstats

这样你通过浏览器访问 http://yourdomain.com/awstats/awstats.yourdomain.com.html 就可以看到统计结果了

执行crontab -e添加定时任务,

2 0 * * * /alidata/etc/awstats/awstats.sh

这样在每天的00:02分,系统就会自动执行awstats统计功能了,你只需要关注生成的网页报告即可!

至此,awstats的安装和配置大功告成!(此处应有掌声~)

转载请注明:知识蚂蚁 » 阿里云服务器nginx+awstats安装与配置详解

我来说说

(便于我们更好的交流)

有不明白的地方欢迎留言哦~
取消