五、awstats 安装与配置详解
1.环境准备
(1).安装yum源
[root@node6 src]# wget http://ftp.sjtu.edu.cn/Fedora/epel/6/i386/epel-release-6-8.noarch.rpm
[root@node6 src]# rpm -ivh epel-release-6-8.noarch.rpm
warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing... ########################################### [100%]
1:epel-release ########################################### [100%]
(2).安装cronolog日志切割工具
[root@node6 src]# wget http://cronolog.org/download/cronolog-1.6.2.tar.gz
[root@node6 src]# tar xf cronolog-1.6.2.tar.gz
[root@node6 src]# cd cronolog-1.6.2
[root@node6 cronolog-1.6.2]# ./configure
[root@node6 cronolog-1.6.2]# make && make install
[root@localhost ~]# which cronolog
/usr/local/sbin/cronolog
2.时间同步
[root@node6 src]# yum install -y ntp
[root@node6 src]# ntpdate 202.120.2.101
28 Dec 17:59:17 ntpdate[1413]: step time server 202.120.2.101 offset -25666.776448 sec
3.安装awstats
(1).yum直接安装
1 [root@node6 ~]# yum install -y awstats
(2).源码包安装
首先,我们要下载awstats软件包,并将其放在常规目录(/usr/local)下。
123456 [root@node6 src]# wget http://jaist.dl.sourceforge.net/project/awstats/AWStats/7.2/awstats-7.2.tar.gz
[root@node6 src]# tar xf awstats-7.2.tar.gz
[root@node6 src]# mv awstats-7.2 /usr/local/awstats
[root@node6 src]# cd /usr/local/awstats
[root@node6 awstats]# ls
docs README.TXT tools wwwroot
注,由于wget下载下来的包中权限是非root的,所以这里要修改权限,否则稍后*.pl将无法运行。
[root@node6 awstats]# chown -R root.root /usr/local/awstats
[root@node6 awstats]# ll
总用量 20
drwx------. 4 root root 4096 7月 10 04:01 docs
-rw-------. 1 root root 6790 7月 10 03:50 README.TXT
drwx------. 5 root root 4096 7月 10 04:01 tools
drwx------. 7 root root 4096 7月 10 04:01 wwwroot
[root@node6 awstats]# chmod +x /usr/local/awstats/tools/*.pl
[root@node6 awstats]# cd tools/
[root@node6 tools]# ls
awstats_buildstaticpages.pl awstats_exportlib.pl geoip_generator.pl logresolvemerge.pl nginx webmin
awstats_configure.pl awstats_updateall.pl httpd_conf maillogconvert.pl urlaliasbuilder.pl xslt
[root@node6 tools]# chmod +x /usr/local/awstats/wwwroot/cgi-bin/*.pl
[root@node6 tools]# cd ..
[root@node6 awstats]# cd wwwroot/cgi-bin/
[root@node6 cgi-bin]# ls
awdownloadcsv.pl awredir.pl awstats.model.conf awstats.pl lang lib plugins
(3).接下来,我们要执行/usr/local/awstats/tools下的awstats_configure.pl配置向导,用来生成awstats的配置文件,awstats配置文件的命名规则是awstats.website.conf。
[root@node6 ~]# cd /usr/local/awstats/tools/
[root@node6 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/apache2/conf/httpd.conf #这里让你输入apache配置文件的目录,我这里的apache是源码安装的,所以我的路径是/usr/local/apache2/conf/httpd.conf
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: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
> www.test.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):
> #这里要填写你配置文件存放路径,我们使用它默认的路径/etc/awstats,所以直接回车即可。
-----> Create config file '/etc/awstats/awstats.www.test.com.conf'
Config file /etc/awstats/awstats.www.test.com.conf 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.test.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.www.test.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.test.com' with command:
> perl awstats.pl -update -config=www.test.com
You can also build static report pages for 'www.test.com' with command:
> perl awstats.pl -output=pagetype -config=www.test.com
Press ENTER to finish... #提示配置文件创建完成和如何更新配置及建立静态报告页,这里我们回车即可结束这个配置向导。
(4).结束这个向导以后,我们对www.test.com站点的awstats配置文件已经配置好了。下面我们来查看并修改一下这个配置文件。
[root@node6 tools]# cd /etc/awstats/
[root@node6 awstats]# ls
awstats.www.test.com.conf
[root@node6 awstats]# vim awstats.www.test.com.conf #这个配置文件有很多配置,我们这里只讲解重点配置。
LogFile="/log/www/access_%YYYY-24%MM-24%DD-24.log" #日志文件存放路径,其中%YYYY-24%MM-24%DD是指年月日模式
DirData="/var/lib/awstats" #创建生成的数据路径
Lang="cn" #默认语言中文
SkipHosts="127.0.0.1 REGEX[^192\.168\.]" #本地及内部的访问不做分析统计
LevelForWormsDetection=2 #日志等级,不对警告日志进行统计
好了,到这里我们awstats配置文件就修改完成。
(5).下面我们来修改一下apache配置文件
[root@node6 www]# vim /usr/local/apache2/conf/httpd.conf
#CustomLog logs/access_log combined
CustomLog "|/usr/local/sbin/cronolog /log/www/access_%Y%m%d.log" combined
(6).新建apache日志目录
[root@node6 ~]# mkdir -pv /log/www/
mkdir: 已创建目录 "/log"
mkdir: 已创建目录 "/log/www/"
[root@node6 ~]# cd /log/www/
[root@node6 www]# chmod -R 755 /log/www/
[root@node6 www]# chown -R daemon /log/www/
(7).重新启动apache服务器
[root@node6 www]# /usr/local/apache2/bin/apachectl restart
(8).创建awstats的数据存放目录
[root@node6 www]# mkdir -pv /var/lib/awstats
[root@node6 www]# chmod 755 /var/lib/awstats
好了,到这里我们的awstats配置就全部完成了,下面我们来执行一下日志分析。
