很是小又精悍的 Nginx 日志分析工具 Goaccess,处理速度很是快,我用 XShell 查看,还能够生成 html 报告,先看图 php
GoAccess 在 CentOS 上的安装方法:
1. 须要安装 GeoIP, ncurses, glib2, 一句搞定
yum -y install glib2 glib2-devel ncurses ncurses-devel geoIP geoIP-devel html
2. 下载 GoAccess 解压编译安装 linux
3. GoAccess 使用方法
进入 Nginx 日志所在目录 nginx
命令行直接查看 apache
也能够生成 HTML 报告 ssh
或者干脆分析目前下全部日志 工具
zcat access.log* | goaccess 动画
若是须要分析某天的日志,例如10月5号那天的日志,咱们让linux管道命令来大显身手^_^。 网站
sed -n ‘/05\/Dec\/2010/,$ p’ access.log | goaccess -s –b
分析从11月5号到12月5号一个月内的日志
sed -n ‘/5\/Nov\/2010/,/5\/Dec\/2010/ p’ access.log | goaccess -s –b
当你不但愿在服务器上安装goaccess程序,能够经过调用本地的goaccess程序来分析服务器上的日志(很神奇吧^_^):
ssh user@server ‘cat /var/log/apache2/access.log’ | goaccess -s -a
附下个人NGINX日志格式:
log_format main ’$remote_addr – $remote_user [$time_local] “$request” ‘
color_scheme 0
date_format %d/%b/%Y
log_format %h %^[%d:%^] “%r” %s %b “%R” “%u” %T
for Apache HTTP Server 预设设定:
CustomLog logs/access_log common可选Common Log Format (CLF)
CustomLog logs/access_log combined可选NCSA Combined Log Formatfor Lighttpd mod_accesslog预设格式 : (需于GoAccess设定画面手动编辑Log Format)
Log Format: %h %^ %^ [%d:%^] “%r” %s %b “%R” “%u”
Date Format: %d/%b/%Y完成设定后产生~/.goaccessrc,往后执行goaccess -f /var/log/httpd/access_log不会再跳出这个设定画面;若要修改设定,可加上-c参数,例如: goaccess -c -f / var/log/httpd/access_log或直接编辑设定档案vi ~/.goaccessrc
基本操做
# goaccess -f /var/log/httpd/access_log
t:回到顶端
b:卷到最末
q:关闭视窗或离开程式
上下方向键:卷动画面
数字键0 ~ 9,接着按英文字母o或右方向键:查看某项目的细节(*注)*注: 0 表示第十项; Shift + 1 表示第十一项
排除统计某来源IP
# goaccess -e 123.123.123.123 -f /var/log/httpd/access_log检视Host详细资料的时候显示来自该Host的User-Agents资讯
# goaccess -a -f /var/log/httpd/access_log产生HTML报表(静态报表)
# goaccess -a -f /var/log/httpd/access_log > result.html只统计来自某IP的记录
# grep ^123.123.123.123 /var/log/httpd/access_log | goaccess注:目前GoAccess没法即时统计pipe进来的资料,往后改版或许会补强这部份(Ref: man goaccess )
Trouble Shooting
没法使用F1 检视help 讯息的替代方案
Ctrl + h
没法使用F10 完成设定画面的替代方案
# vi ~/.goaccessrc
color_scheme 1 date_format %d/%b/%Y log_format %h %^ %^ [%d:%^] "%r" %s %b "%R" "%u"其余log_format 参考:
Common Log Format (CLF): %h %^[%d:%^] "%r" %s %b Common Log Format (CLF) with Virtual Host: %^:%^ %h %^[%d:%^] "%r" %s %b NCSA Combined Log Format: %h %^[%d:%^] "%r" %s %b "%R" "%u" NCSA Combined Log Format with Virtual Host: %^:%^ %h %^[%d:%^] "%r" %s %b "%R" "%u" W3C: %d %^ %h %^ %^ %^ %^ %r %^ %s %b %^ %^ %u %R变动热键
# cd /path/to/goaccess-0.5
# vi goaccess.c
#将F1热键改成F2
找到[F1]Help [O]pen detail view
改成[ F2 ]Help [O]pen detail view找到Case 265:
改成Case 266 :# vi commons.c
#将Help讯息的F1改成F2
找到” ^F1^ or ^CTRL^ + ^h^ [main help]“,
改成” ^ F2 ^ or ^CTRL^ + ^h^ [main help]“,# vi goaccess.1
#将manpage的F1字眼改成F2
找到.IP “F1″
改成.IP “ F2 ”# vi settings.c
#将F10热键改成F9
找到mvwprintw (win, 2, 2, “[SPACE] to toggle – [F10] to proceed”);
改成mvwprintw (win, 2, 2, “[SPACE] to toggle – [ F9 ] to proceed”);找到Case 274:
改成Case 273 :