Nginx系列4:用GoAccess實現可視化並實時監控access日志


1.ubuntu16.04安裝GoAccess

GoAccess下載地址:https://goaccess.io/download

安裝步驟:

$ 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

Q1:在執行第四步./configure時,遇到問題:

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
$ tar -xzvf GeoIP-1.6.11.tar.gz $ cd GeoIP-1.6.11 $ ./configure $ make # make install

 Q2:在執行第四步./configure時,遇到問題:

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

解決方法:

要使用--enable-utf8,你需要安裝ncursesw,下面是安裝命令:

sudo apt-get install libncursesw5-dev

安裝完成截圖:

 

2.修改nginx服務器的配置文件nginx.conf

location /report.html { alias /home/zopen/nginx/html/report.html;    #指定個人配置的目錄 }

如下圖所示:

重新加載配置文件:

../sbin/nginx -s reload

 

 

3.執行goaccess命令,在nginx/logs目錄下,執行:

goaccess access.log -o ../html/report.html --real-time-html --time-format='%H:%M:%S'  --date-format='%d/%b/%Y' --log-format=COMBINED

打開網站,成功運行!

 

4.后台運行GoAccess

打開 Tmux 並啟動 GoAccess

$ tmux $ goaccess access.log -o ../html/report.html --real-time-html --time-format='%H:%M:%S'  --date-format='%d/%b/%Y' --log-format=COMBINED

 一切正常的話 GoAccess 應該開始分析日志文件了,然后顯示 "WebSocket server ready to accept new client connections"。
現在按下你 Tmux 的 PREFIX 鍵(默認是 Ctrl+B),再按 d 從 Tmux 中脫離出來,這樣即使 ssh 斷開連接了也能保持后台運行,想查錯也可以用

$ tmux attach

連接剛才那個會話。
現在用瀏覽器打開 http://114.116.120.230:8080/report.html 應該就可以看見分析結果了,每秒鍾刷新一次數據。


免責聲明!

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



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