首先是安装goaccess
# yum -y install glib2 glib2-devel ncurses ncurses-devel GeoIP GeoIP-devel
# wget http://tar.goaccess.io/goaccess-1.2.tar.gz
# tar -xzvf goaccess-1.2.tar.gz
# cd goaccess-1.2/
# ./configure --prefix=/usr/local/goaccess --enable-utf8 --enable-geoip` 或者 `./configure --enable-utf8 --enable-geoip=legacy
# make && make install
然后是脚本
#!/bin/bash
export LANG="en_US.UTF-8"
yesterday=`date -d '-1 day' +%d/%b/%Y`
cat /data/3.x/logs/006-nginx/access.log |grep $yesterday > /home/wwwlog/awstats/access.log
cat /home/wwwlog/awstats/access.log |grep $yesterday |grep 'HTTP/1.1" 404' > /home/wwwlog/awstats/nginx-error$(date -d '-1 day' +%y-%m-%d).html
/usr/local/goaccess/bin/goaccess -f /home/wwwlog/awstats/access.log --log-format=COMBINED -a > /home/wwwlog/awstats/nginx$(date -d '-1 day' +%y-%m-%d).html
find /home/wwwlog/awstats/ -mtime +30 -name "*.html" -exec rm -rf {} \;
echo $yesterday
将此脚本加入任务计划,每天都要执行.
使用
goaccess -f access.log –log-format=COMBINED -a > test.html 生成html文件
goaccess -f access.log –log-format=COMBINED -a > test.html
查看分析结果:goaccess -f access.log