Chinaunix首页 | 论坛 | 博客
  • 博客访问: 446477
  • 博文数量: 481
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 1040
  • 用 户 组: 普通用户
  • 注册时间: 2013-01-06 14:09
文章分类

全部博文(481)

文章存档

2013年(483)

我的朋友

分类: LINUX

2013-02-28 12:44:54

原文地址:awstats nginx neoip安装配置 作者:jack_sir

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;
        }
阅读(361) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~