前面两篇都在讲述如何去部署nginx下的awstats日志分析工具
日志分析工具Awstats实战之Nginx篇:分析结果静态化
日志分析工具Awstats实战之Nginx篇:分析结果动态化
现在终于轮到apache。作为老牌的网页服务器,awstats对apache的支持非常完美,所以整个配置过程也是十分简单。因此,在这里我就拓展了一下部署,实现了对多站点的日志分析功能。
注意:自本篇博文发表之日,apache-2.4.x还是无法支持部署awstats日志分析结果访问动态化,不过可以用前篇日志分析工具Awstats实战之Nginx篇-分析结果静态化中讲到的方法来实施部署awstats。因此,本篇博文将用apache2.2.25版本来为大家讲解如何部署awstats日志分析结果动态化及多站点。
环境:
CentOS 6.4 x86_64
ip:192.168.1.113
站点1:域名(server和client都通过hosts文件解析)
站点2:域名(server和client都通过hosts文件解析)
apache-2.2.25 编译安装,路径/usr/local/apache,服务开启状态
日志记录格式为apache默认的combined格式,切勿更改,否则会造成awstats无法分析日志。
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
apr-1.4.8 apr-util-1.5.2
awstats-7.2.tar.gz
一、日志自动切割
由于apache自带的日志轮询工具rotatelogs,据专家说在进行日志切割时容易丢日志,所以这里我们就用cronolog来做日志切割。
1、下载并安装cronolog
123456 cd /server/tools/
wget
tar zxf cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure
make&&make install
2、配置apache使用cronolog
由于实验用的apache开启了虚拟主机功能,所以以下配置都在虚拟主机中进行,这样也是为了方便对多站点的分析操作。
vim /usr/local/apache/httpd/extra/httpd-vhosts.conf
将配置文件中的CustomLog和ErrorLog替换为下面的(由于我们要对多站点,所以这里要替换两个虚拟主机的,并且将日志存放名字做有效的区分才好)
123456
CustomLog "|/usr/local/sbin/cronolog /app/logs/linuxidc_access_%Y%m%d.log" combined
ErrorLog "|/usr/local/sbin/cronolog /app/logs/linuxidc_error_%Y%m%d.log"
CustomLog "|/usr/local/sbin/cronolog /app/logs/88181_access_%Y%m%d.log" combined
ErrorLog "|/usr/local/sbin/cronolog /app/logs/88181_error_%Y%m%d.log"
注意:这里一定要注意对两个网站的日志名称配置。
二、Awstats的安装与配置
1、部署awstats
首先我们要下载awstats软件包,并将其放在常规目录(/usr/local)下
wget
tar zxf awstats-7.2.tar.gz
mv awstats-7.2 /usr/local/awstats
由于wget下载下来的包中权限是非root的,所以这里要修改权限,否则稍后*.pl将无法运行
chown -R root.root /usr/local/awstats
chmod +x /usr/local/awstats/tools/*.pl
chmod +x /usr/local/awstats/wwwroot/cgi-bin/*.pl
接下来我们要执行awstats/tools下的awstats_configure.pl配置向导,用来生成awstats的配置文件,awstats配置文件的命名规则是awstats.website.conf
cd /usr/local/awstats/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/apache/conf/httpd.conf #有可能是新版本的原因,这里会自动找到apache的配置文件,无需我们再自己填了,不过会问你一次,你回答y即可
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:
Example: demo
Your web site, virtual server or profile name:
> #这里让填写你的网站域名,虚拟主机名或者随便一个配置名
-----> 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.'
Config file /etc/awstats/awstats. 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.linuxidc.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.
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.linuxidc.com' with command:
> perl awstats.pl -update -config=www.linuxidc.com
You can also build static report pages for 'www.linuxidc.com' with command:
> perl awstats.pl -output=pagetype -config=www.linuxidc.com
Press ENTER to finish... #提示配置文件创建完成和如何更新配置及建立静态报告页,这里我们回车即可结束这个配置向导