1. 简介
GoAccess 是一款开源(MIT许可证)的且具有交互视图界面的实时 Web 日志分析工具,通过你的 Web 浏览器或者 *nix 系统下的终端程序即可访问。能为系统管理员提供快速且有价值的 HTTP 统计,并以在线可视化服务器的方式呈现。
2. 安装
1)二进制
方案一:
不同的操作系统,选不同的安装软件安装goaccess,例如:
yum install goaccess
apt install goaccess
方案二:
$ git clone https://github.com/allinurl/goaccess.git
$ cd goaccess
$ autoreconf -fi
$ ./configure --enable-geoip --enable-utf8
$ make
# make install
2)docker镜像
docker pull allinurl/goaccess
docker run --restart=always -d -p 7890:7890 \
-v "/srv/goaccess/data:/srv/data" \
-v "/srv/goaccess/html:/srv/report" \
-v "/var/log/apache2:/srv/logs" \
--name=goaccess allinurl/goaccess
3. 使用
官网是个好东西,更多使用问题,请查阅goaccess中文官网
如果是二进制安装,使用命令行解析日志的话
步骤1:访问github,获取nginx日志格式配置转化脚本https://github.com/stockrt/nginx2goaccess
示例:
#从nginx.conf文件中查出nginx日志,再执行脚本转化为time,date,log配置
root@loalhost:~# ./nginx2goaccess.sh '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"'
- Generated goaccess config:
time-format %T
date-format %d/%b/%Y
log_format %h - %^ [%d:%t %^] "%r" %s %b "%R" "%u"
步骤2:使用配置解析nginx日志
# 一般用html和csv格式足够了,其他格式请查官网
goaccess /var/log/nginx/access.log -c --time-format='%T' --date-format='%d/%b/%Y' --log-format='%h - %^ [%d:%t %^] "%r" %s %b "%R" "%u"' -a -o report.html
goaccess /var/log/nginx/access.log -c --time-format='%T' --date-format='%d/%b/%Y' --log-format='%h - %^ [%d:%t %^] "%r" %s %b "%R" "%u"' --no-csv-summary -o report.csv
步骤3:固化配置(可选)
在goaccess.conf配置文件中,固化time,date,log配置,简化goaccess命令
网友评论