GoAccess日志分析工具


簡介

官網:https://goaccess.io/download#installation

GoAccess是一個非常良心的開源軟件,它的良心之處體現在如下方面:
1)安裝簡單;
2)操作容易;
3)界面酷炫;

安裝

系統環境:sentos7

selinux設置:

查看:# sestatus

  SELinux status: disabled

安裝過程:

方案一:yum安裝

#yum install glib2 glib2-devel GeoIP-devel  ncurses-devel zlib zlib-develyum install gcc -y
#yum -y install GeoIP-update
#yum install goaccess

 

方案二:源碼安裝

# wget https://tar.goaccess.io/goaccess-1.3.tar.gz
# tar -xzvf goaccess-1.3.tar.gz
# cd goaccess-1.3/
#./configure --enable-utf8 --enable-geoip=legacy
#make
#make install

配置完成:

Your build configuration:

  Prefix         : /usr/local
  Package        : goaccess
  Version        : 1.3
  Compiler flags :  -pthread
  Linker flags   : -lnsl -lncursesw -lGeoIP -lpthread
  Dynamic buffer : no
  Geolocation    : GeoIP Legacy
  Storage method : In-memory Hash Database (Default)
  TLS/SSL        : no
  Bugs           : goaccess@prosoftcorp.com

 

編譯出錯解決:

1、

configure: error:
*** Missing development files for the GeoIP library

解決:

# wget https://github.com/maxmind/geoip-api-c/releases/download/v1.6.11/GeoIP-1.6.11.tar.gz
# cd GeoIP-1.6.11/
# ./configure && make && make install

2、

configure: error: *** Missing development libraries for ncursesw

解決:

# yum install ncurses-devel
# yum install ncurses-libs

 

使用GoAccess分析日志

這次分析日志為nginx標准輸出

①goaccess命令使用: 

# goaccess -f access.log

②出現goaccess界面:按“空格”選擇格式為    NCSA Combined Log Format   

 

 ③再回車即可看到分析結果

 

生成HTML頁面

修改配置,先查看當前配置:

]# egrep -v '^#|^$' goaccess.conf
config-dialog false
hl-header true
json-pretty-print false
no-color false
no-column-names false
no-csv-summary false
no-progress false
no-tab-scroll false
with-mouse false
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

由上可見默認配置中並無時間參數,需要在配置中添加時間參數。

# cat  >>goaccess.conf<<EOF
> time-format %H:%M:%S
> date-format %d/%b/%Y
> #NCSA Combined Log Format
> log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"
> EOF

生成命令h5的日志頁面

# goaccess  /usr/local/nginx/logs/access.log -o /usr/local/nginx/logs/report.html -p /etc/goaccess.conf
-p 指定配置文件
-o 指定生成文件的位置

添加到定時任務

30 * * * * /usr/bin/goaccess  /usr/local/nginx/logs/access.log -o /usr/local/nginx/logs/report.html -p /etc/goaccess.conf

訪問:http://loghost/report.html

 

 

調整

1、中文展示

如果你的系統默認設置時英文顯示,想要以中文顯示日志報表,就需要進行字符設置

查看系統語言:
# cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"

臨時設置為中文的命令:
# LANG="zh_CN.UTF-8"

如果不設置系統默認語言,還有其他辦法調整goaccess為中文嗎?當然可以

#LANG="zh_CN.UTF-8" bash -c "goaccess -p /etc/goaccess.conf /usr/local/nginx/logs/access.log -o /usr/local/nginx/logs/report.html --log-format=COMBINED"

2、html可視化文件的實時更新方法:

#nohup goaccess -f access.log -p goaccess.conf -o report.html --real-time-html --ws-url=report.xxx.com &
 

  選項解釋

  -f 指定nginx日志文件
  -p 指定日志格式文件
  -o 輸出到指定html文件
  --real-time-html 實時刷新
  --ws-url 綁定一個域名

3、配置nginx中日志log_format中的日志格式

改完記得reload配置

3.1 獲取nginx.conf中log_format配置

3.2 獲取nginx2goaccess腳本,可以將日志格式轉換為goaccess能識別的日志格式,腳本地址:https://www.cnblogs.com/erbiao/p/9221543.html

# sh nginx2goaccess.sh '$remote_addr $http_x_forwarded_for [$time_local] $host "$request_uri" $status "$http_referer" "$http_user_agent"'

- Generated goaccess config:
time-format %T
date-format %d/%b/%Y
log_format %h %^ [%d:%t %^] %v "%U" %s "%R" "%u"

3.3 將轉換后的內容加入到配置/etc/goaccess.conf 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM