goaccess 解析nginx日志
概要: 在Debian11上使用goaccess轻量工具,解析nginx日志
创建时间: 2022.08.18 22:15:12
更新时间: 2023.07.28 23:18:33
安装依赖包
此步骤解决在编译goaccess时的依赖问题
Bash |
---|
| sudo apt update
sudo apt install libmaxminddb-dev geoip-bin libncursesw5-dev
|
编译安装goaccess
获取安装文件
Bash |
---|
| wget https://tar.goaccess.io/goaccess-1.6.2.tar.gz
tar -xzvf goaccess-1.6.2.tar.gz
|
本地编译安装
Bash |
---|
| cd goaccess-1.6.2/
./configure --enable-utf8 --enable-geoip=mmdb
make && make install
|
配置goaccess
直接编辑配置文件(先备份)
Bash |
---|
| cp /usr/local/etc/goaccess/goaccess.conf /usr/local/etc/goaccess/goaccess.conf-bak
vim /usr/local/etc/goaccess/goaccess.conf
|
下面为示例配置
Bash |
---|
| time-format %H:%M:%S
date-format %d/%b/%Y
log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"
config-dialog false
hl-header true
json-pretty-print false
no-color false
no-column-names false
no-csv-summary false
with-mouse false
# Parse Options
agent-list false
with-output-resolver false
http-method yes
http-protocol yes
no-query-string false
no-term-resolver false
444-as-404 false
4xx-to-unique-count false
all-static-files false
double-decode false
ignore-crawlers false
crawlers-only false
ignore-panel REFERRERS
ignore-panel KEYPHRASES
real-os true
static-file .css
static-file .js
static-file .jpg
static-file .png
static-file .gif
static-file .ico
static-file .jpeg
static-file .pdf
static-file .csv
static-file .mpeg
static-file .mpg
static-file .swf
static-file .woff
static-file .woff2
static-file .xls
static-file .xlsx
static-file .doc
static-file .docx
static-file .ppt
static-file .pptx
static-file .txt
static-file .zip
static-file .ogg
static-file .mp3
static-file .mp4
static-file .exe
static-file .iso
static-file .gz
static-file .rar
static-file .svg
static-file .bmp
static-file .tar
static-file .tgz
static-file .tiff
static-file .tif
static-file .ttf
static-file .flv
static-file .dmg
static-file .xz
static-file .zst
|
注意,对于 nginx.conf 的日志格式为
Bash |
---|
| log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
|
使用goaccess
输出日志分析结果到JSON文件
Bash |
---|
| goaccess ./test.log --ignore-crawlers --json-pretty-print --real-os --output="report_$(date +"%Y%m%d_%H%M%S").json"
|
参考