- #解压awstats软件包至/usr/local/
tar zxvf awstats-7.6.tar.gz -C /usr/local/
#重命名awstats
mv /usr/local/awstats-7.6 /usr/local/awstats
#修改awstats属主属组
chown root.root -R /usr/local/awstats
#进入tools目录
cd /usr/local/awstats/tools/
- #新建站点统计配置文件
./awstats_configure.pl
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 #输入y,创建一个新的统计配置
-----> 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):
#直接 “回车键”
- 修改www.test.com统计配置文件
vim /etc/awstats/awstats.www.test.com.conf
…
LogFile="/usr/local/nginx/logs/access.log" #50行,修改nginx日志文件位置
DirData="/var/lib/awstats" #220行,数据目录,awstats目录默认不存在(需要创建)
创建/var/lib/awstats目录
mkdir -p /var/lib/awstats
-
更新分析日志文件
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.test.com -
生成静态分析日志网页数据
/usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.test.com -lang=cn -dir=/usr/local/awstats/wwwroot -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
上述命令解释如下:
/usr/local/awstats/tools/awstats_buildstaticpages.pl :awstats静态页面生成工具
-update -config=www.test.com :更新配置域名
-lang=cn :语言为中文
dir=/usr/local/awstats/wwwroot :统计结果输出的目录
awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl :日志更新程序的路径 -
建立定时任务让Awstats自动更新数据(每小时59更新)
vim /etc/crontab
59 * * * * root /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.test.com -lang=cn -dir=/usr/local/awstats/wwwroot -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
启动crond服务
systemctl start crond.service
- 在nginx中建立awstats虚拟目录
vim /usr/local/nginx/conf/nginx.conf
#http{}标签内增添一个server{}
server {
listen 80;
server_name 192.168.100.7;
location / {
root /usr/local/awstats/wwwroot;
index index.html awstats.www.test.com.html;
}
}