安装GoAccess

  • 下载goaccess源码包
wget https://tar.goaccess.io/goaccess-1.4.tar.gz
  • 编译安装

解压安装包

tar xf goaccess-1.4.tar.gz

安装依赖

yum -y install GeoIP-devel ncurses-devel    

编译goaccess

cd goaccess-1.4
./configure --enable-utf8 --enable-geoip=legacy
make && make install

GoAccess应用

  • 指定日志文件
goaccess -f /var/log/nginx/access.log
  • 修改配置文件
[root@web03 ~]# vim /usr/local/etc/goaccess/goaccess.conf
time-format %H:%M:%S
date-format %d/%b/%Y
log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"
  • 将分析的日志保存为html,在浏览器分析显示
goaccess -f /var/log/nginx/access.log -p /usr/local/etc/goaccess/goaccess.conf
  • 添加nginx配置文件
[root@web03 ~]# cat /etc/nginx/conf.d/goaccess.conf 
server{
    listen 80;
    server_name goaccess.test.com;
    root /code/log;
    index index.html;
}

创建站点目录

mkdir -p /code/log

重启服务

systemctl restart nginx
  • 将日志文件生成html文件
goaccess -f /root/access.log -o /code/log/index.html -p /usr/local/etc/goaccess/goaccess.conf 

文档更新时间: 2020-12-28 19:03   作者:Wan Hebin