1、安装依赖
dnf install libmaxminddb libmaxminddb-devel -y
2、编译安装
wget https://tar.goaccess.io/goaccess-1.7.2.tar.gz tar xf goaccess-1.7.2.tar.gz cd goaccess-1.7.2 ./configure --prefix=/usr/local/goaccess --enable-utf8 --enable-geoip=mmdb make && make install
3、修改配置
# vim /usr/local/goaccess/etc/goaccess/goaccess.conf ... time-format %H:%M:%S #13行 date-format %d/%b/%Y #36行 log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u" #80行 log-format COMBINED #124行 addr 0.0.0.0 #287行 daemonize true #291行 port 7890 #302行 pid-file /var/run/goaccess.pid #306行 real-time-html true #310行 geoip-database /usr/local/goaccess/geoip/GeoLite2-City.mmdb #741行 ...
4、城市IP地址配置
# 下载城市地址数据库 https://www.maxmind.com/en/home # 解压并拷贝最新的国家地址数据库 tar xf GeoLite2-City_20230411.tar.gz \cp -f GeoLite2-City_20230411/GeoLite2-City.mmdb /usr/local/goaccess/geoip/
5、启动脚本
# vim /data/scripts/goaccess.sh #!/bin/bash # author devops # time 2019/10/31 LANG="zh_CN.UTF-8" bash -c "goaccess -a -d -f /data/wwwlogs/access_nginx.log -p /usr/local/goaccess/etc/goaccess/goaccess.conf -o /data/wwwroot/goaccess/go.html"
6、Nginx访问配置
# vim /etc/nginx/conf.d/goaccess.conf server { listen 8181; server_name _; #access_log /data/wwwlogs/access_nginx.log combined; #root /data/wwwroot/dist; #index index.html index.htm index.php; #error_page 404 /404.html; #error_page 502 /502.html; error_page 405 =200 $request_uri; charset utf-8; location / { root /data/wwwroot/goaccess; index index.html index.htm; allow 10.10.0.0/24; deny all; } }
参考:https://github.com/allinurl/goaccess