原文鏈接:https://blog.csdn.net/yown/article/details/56027112
需求:及時得到線上用戶訪問日志分析統計結果,以便給開發、測試、運維、運營人員提供決策!
找了各種工具,最終還是覺得goaccess不僅圖文並茂,而且速度快,每秒8W 的日志記錄解析速度,websocket10秒刷新統計數據,站在巨人肩膀上你也會看得更遠…先上圖:
具體安裝步驟如下:
一、linux上安裝goaccess
a.先安裝依賴包
yum install ncurses-devel wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz tar -zxvf GeoIP.tar.gz cd GeoIP-1.4.8/ ./configure make && make install
b.安裝goaccess
wget http://tar.goaccess.io/goaccess-1.1.1.tar.gz tar -xzvf goaccess-1.1.1.tar.gz cd goaccess-1.1.1/ ./configure –enable-geoip –enable-utf8 make make install
二、校對nginx和goaccess日志格式
a、配置nginx.conf中log_format中的日志格式(改完記得重啟nginx服務),如:
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" ' '$connection $upstream_addr ' '$upstream_response_time $request_time';
b、使用nginx2goaccess.sh腳本將nginx日志格式格式化為goaccess能識別的日志格式,nginx2goaccess.sh腳本內容在https://www.cnblogs.com/erbiao/p/9221543.html
1、保存下來
2、使用如下方式獲取日志格式:
sh nginx2goaccess.sh '<log_format>' #log_format為你nginx.conf中配置的日志格式
如:
sh nginx2goaccess.sh '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for" $connection $upstream_addr $upstream_response_time $request_time'
3、會得到三個格式:
time-format %T date-format %d/%b/%Y log_format %h - %^ [%d:%t %^] "%r" %s %b "%R" "%u" "%^" %^ %^ %^ %T
三、生成統計頁面。上面三行分別是時間、日期、日志格式,將三行輸出保存到任意文件,然后就可以開始生成html可視化文件
./goaccess -f nginx_access.log -p /opt/goaccess/nginxlog.conf -o day-report.html
html可視化文件的實時更新方法
nohup ./goaccess -f access.log -p /opt/goaccess/nginxlog.conf -o day-report.html --real-time-html --ws-url=report.xxx.com &
選項解釋
-f 指定nginx日志文件 -p 指定日志格式文件 -o 輸出到指定html文件 --real-time-html 實時刷新 --ws-url 綁定一個域名
四、將生成的文件用web服務器展示在瀏覽器上
略。
-----------------------------------
相關鏈接
goaccess官網:https://goaccess.io