goaccess基本概述
GoAccess - 可视化 Web 日志分析工具
GoAccess 是一款开源(MIT许可证)的且具有交互视图界面的实时 Web 日志分析工具,通过你的 Web 浏览器或者 *nix 系统下的终端程序即可访问
goaccess
- 日志分析工具
- matomo(piwiki)
- awstat
- goaccess
- elk
goaccess 主要功能
- 通用统计
- 独立访客
- 请求的文件
- 请求的静态文件
- 404或者文件未找到
- 操作系统
- 主机、DNS和ip地址
- 浏览器和搜索引擎
- HTTP响应代码
- 自定义显示
- 支持超大日志(分析速度很快)
goaccess官方网址
https://goaccess.cc/
①下载goaccess
②命令行源码编译安装
#1. 安装与搭建环境
[root@web01 ~]#wget http://tar.goaccess.io/goaccess-1.2.tar.gz
[root@web01 ~]# tar xf goaccess-1.2.tar.gz
[root@web01 ~]# cd goaccess-1.2/
[root@web01 ~]# ./configure --enable-utf8 --enable-geoip=legacy
configure: error:
*** Missing development files for the GeoIP library
[root@web01 ~]# yum install ncurses-devel -y #缺少的依赖包
[root@web01 ~]# yum install GeoIP GeoIP-devel -y #缺少的依赖包
[root@web01 ~]# ./configure --enable-utf8 --enable-geoip=legacy #
[root@web01 ~]# make
[root@web01 ~]# make install
#2. goaccess 初使用
goaccess
-f 指定日志文件
-p 指定配置文件(html页面显示使用)
[root@web01 ~]# goaccess -f /var/log/nginx/access.log
配置完成:
Your build configuration:
Prefix : /usr/local
Package : goaccess
Version : 1.2
Dynamic buffer : no
Geolocation : GeoIP Legacy
Storage method : In-memory Hash Database (Default)
TLS/SSL : no
Compiler flags : -pthread
Linker flags : -lnsl -lncursesw -lGeoIP -lpthread
Bugs : goaccess@prosoftcorp.com
- html 方式显示
- 选择日志格式
③配置
1.安装完成后,默认将配置文件goaccess.conf放置于/usr/local/etc路径,为了统一管理,使用mv /usr/local/etc/goaccess.conf /etc命令将其移动到/etc目录下
2.对文件文件做一些主要配置
[root@web01 ~]#which goaccess
/usr/local/bin/goaccess
[root@web01 /usr/local/etc]#vim goaccess.conf
log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"
date-format %d/%b/%Y
time-format %H:%M:%S
特殊格式说明符
格式 | 说明 |
---|---|
%h | 主机(客户端IP地址,IPv4或者IPv6) |
%^ | 忽略此字段 |
%r | $request |
%s | 服务器回传客户端的状态码 |
%b | %b 回传客户端的对象的大小 |
%R | HTTP 请求的 "Referer"值 |
%u | HTTP 请求的 "UserAgent"值 |
%H | 请求协议 |
-
详细帮助参考 man goaccess
-
官网
https://goaccess.cc/?mod=man
配置
# 1.测试是否能通过终端直接显示
[root@web01 ~]# goaccess -f /var/log/nginx/access.log -p /usr/local/etc/goaccess.conf
# 2.将分析结果保存为HTML
[root@web01 ~]# goaccess -f /var/log/nginx/access.log -o report.html
GoAccess - version 1.2 - May 13 2022 19:32:39
Config file: No config file used
Fatal error has occurred
Error occured at: src/parser.c - parse_log - 2705
No time format was found on your conf file.
# 对配置文件做一些主要配置:
[root@web01 /usr/local/etc]# cat goaccess.conf
log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"
date-format %d/%b/%Y
time-format %H:%M:%S
#创建目录
[root@web01 ~]# mkdir -p /code/log
#移动
[root@web01 ~]#mv report.html /code/log/
#将分析结果保存为HTML
[root@web01 ~]# goaccess -f /var/log/nginx/access.log -o /code/log/report.html
# 所执行的命令是否成功执行
# 测试
[root@web01 ~]# echo $?
0
#3.配置Nginx虚拟主机,将root指向/code/log
#这样就可以通过域名去访问HTML界面
[root@web01 ~]#vim /etc/nginx/conf.d/log.huhao.com.conf
server {
listen 80;
server_name log.huhao.com; #网站域名 也要做hosts解析
root /code/log;
}
# 检查Nginx配置语法
[root@web01 ~]# nginx -t
# 重载
[root@web01 ~]# systemctl reload nginx
# 将分析结果保存为HTML
[root@web01 ~]# goaccess -f /var/log/nginx/access.log -o /code/log/report.html
Daemonized GoAccess: 4785
[root@web01 ~]# echo $?
0
结果显示