1.首先安装awstats
cd /data0/software
wget http://sourceforge.net/projects/awstats/files/AWStats/6.9/awstats-6.9.tar.gz/download
tar zxvf awstats-6.9.tar.gz
#mv /data0/software/awstats-6.9/* /usr/local/awstats
#cd /usr/local/awstats/tools
#./awstats_configure.pl
安装过程中会让你回答下列等问题
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):
> /opt/apache/conf/httpd.conf
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:
> redis.spy.com
Directory path to store config file(s) (Enter for default):
>
安装过程会自动在httpd.conf文件中添加下面的配置信息
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/"
<Directory "/usr/local/awstats/wwwroot">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
修改主机配置文件/etc/awstats/awstats.redis.spy.com.conf,重点检查LogFile、LogType、LogFormat、 SiteDomainin、HostAlias,把LogFile重新定义所要统计的日志文件的路径
/usr/local/apache/logs/redis_access_log
创建/var/lib/awstats创建数据库存放目录,并更新数据库:
# mkdir -p /var/lib/awstats
perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update-config=redis.spy.com
修改/usr/local/apache/conf/httpd.conf配置文件
CustomLog
/usr/local/apache/logs/redis_access_log combined
2.日志统计
统计主机日志
# cd /usr/local/awstats/wwwroot/cgi-bin/
# perl awstats.pl -config=redis.spy.com -update -lang=cn
定时统计主机日志
#update awstats
5 * * * * root perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update-config=redis.spy.com
重启apache服务测试
如果未对awstats设置访问控制时,访问awstats页面并不需要提供帐号和密码,只要知道对应的网址就可查看web日志的内容,这给服务器的安全带来了隐患,因此需要对其行进访问控制。接下来就对awstats页面进行基于用户的访问控制:
创建密码文件,cd /usr/local/awstats
touch .htpasswd
编辑httpd.conf配置文件,在awstats的目录区域设置,添加认证授权设置:
<Directory "/usr/local/awstats/wwwroot">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "AWSTATS"
AuthType Basic
AuthUserFile /usr/local/awstats/.htpasswd
require valid-user
</Directory>
创建存储认证用户账号及口令的文件
./htpasswd -c /usr/local/awstats/.htpasswd shipeiyu
按要求输入密码
重启apache服务
/usr/local/apache/bin/httpd -k restart
登录,弹出帐号密码框,成功。