cd /usr/local/
sudo wget
sudo tar xzf awstats-6.95.tar.gz
sudo mv awstats-6.95 awstats
cd /usr/local/awstats/tools/
sudo perl awstats_configure.pl
根据提示完成配置后生成/etc/awstats/awstats.bb.ssss.com.cn.conf
文件,修改awstats配置文件LogFile的格式如下:
LogFile="/var/log/nginx/yqbb_access.log%YYYY-0%MM-0%DD-0"
sudo mkdir /var/lib/awstats
chown -R www-data:www-data /var/lib/awstats
#安装awstatsGeoip库:
cd /opt/src
sudo wget
sudo wget
cd /opt/build
sudo tar zxf ../src/GeoIP-1.4.6.tar.gz
cd GeoIP-1.4.6/
sudo ./configure
sudo make
sudo make check
sudo make install
cd /opt/build/
sudo tar xzf ../src/Geo-IP-1.38.tar.gz
cd Geo-IP-1.38/
sudo perl Makefile.PL LIBS='-L/usr/local/lib'
sudo make
sudo make test
sudo make install
#每隔2周更新一次ip库:
cd /opt/src
sudo wget
sudo wget wget
sudo wget wget
sudo gunzip /opt/src/GeoIP.dat.gz
sudo gunzip /opt/src/GeoIPASNum.dat.gz
sudo gunzip GeoLiteCity.dat.gz
sudo mv GeoIPASNum.dat GeoIP.dat GeoLiteCity.dat /usr/local/share/GeoIP/
添加到配置文件:/etc/awstats/awstats.bb.ssss.com.cn.conf
LoadPlugin="geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat"
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /usr/local/share/GeoIP/GeoLiteCity.dat"
LoadPlugin="geoip_org_maxmind GEOIP_STANDARD /usr/local/share/GeoIP/GeoIPASNum.dat"
手动执行更新:
sudo /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=bb.ssss.com.cn
每天切割日志并产生静态文件脚本:
cat /opt/sh/nginx_log_cron.sh
#!/bin/bash
if
cd /var/log/nginx;then
for file in `ls *.log`
do
sudo mv ${file} ${file}`date +%Y%m%d`
done
fi
sudo kill -USR1 `sudo cat /var/run/nginx.pid`
find /var/log/nginx/ -type f -mtime +30 | sudo xargs rm -f
sleep 5
sudo /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=bb.ssss.com.cn -lang=cn -dir=/home/web/awstats/yqbb -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
脚本在每天的23:59分执行:
59 23 * * * /opt/sh/nginx_log_cron.sh > /dev/null 2&>1
在nginx配置文件server中添加访问awstats的配置项:
location /awstats {
alias /home/web/awstats/yqbb;
index index.html index.htm;
access_log off;
error_log off;
charset gb2312;
}
location /icon {
alias /usr/local/awstats/wwwroot/icon;
index index.html;
error_log off;
access_log off;
charset gb2312;
}
阅读(372) | 评论(0) | 转发(0) |