awstats部署

1.下载awstats并解压
wget http://prdownloads.sourceforge.net/awstats/awstats-6.95.tar.gz
tar -C /usr/local/awstats zxvf awstats-6.95.tar.gz
mkdir -m 755 /usr/local/awstats/data/

2.初始化配置awstats
perl /usr/local/awstats/tools/awstats_configure.pl
输入需分析的域名即可

3.修改配置文件,使用日志自动合并分析
vi /etc/awstats/awstats.www.test.com.conf
LogFile="/usr/local/awstats/tools/logresolvemerge.pl /data/*_access_log_%YYYY-24%MM-24%DD-24|"

4.修改apache配置文件
每天自动切割日志文件
vi httpd.conf
CustomLog "|/usr/sbin/rotatelogs /var/log/httpd/53_access_log_%Y%m%d 86400 480" combined
service httpd restart

5.添加IP及地区的分析插件
cpan install Geo::IP
wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz
tar zxvf GeoIP.tar.gz
cd GeoIP-1.4.6/
./configure && make && make install
wget http://geolite.maxmind.com/download/geoip/api/perl/Geo-IP-1.38.tar.gz
tar zxvf Geo-IP-1.38.tar.gz
cd Geo-IP-1.38
perl Makefile.PL && make && make install
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoLiteCity.dat.gz
cp GeoLiteCity.dat /usr/local/share/GeoIP/
vi /etc/awstats/awstats.www.test.com.conf
修改以下参数
LoadPlugin="tooltips"
LoadPlugin="decodeutfkeys"
LoadPlugin="geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat"
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /usr/local/share/GeoIP/GeoLiteCity.dat"

6.设置awstats服务器与apache主机互信
ssh-keygen -t rsa
chmod 700 ~/.ssh
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
rcp ~/.ssh/authorized_keys ip地址:~/.ssh/authorized_keys

7.添加自动分析脚本
01 03 * * * /sbin/awstats.sh > /var/log/awstat.log
脚本内容
POSTFIX=`date -dyesterday '+%Y%m%d'`
scp ip地址:/var/log/httpd/53_access_log_$POSTFIX /data/
scp ip地址:/var/log/httpd/54_access_log_$POSTFIX /data/
sleep 10
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.test.com
sleep 10
rm -f /data/53_access_log_$POSTFIX /data/54_access_log_$POSTFIX

大功告成
http://ip地址/awstats/awstats.pl?config=www.test.com

你可能感兴趣的:(网站运维)