2017年4月19日 星期三

GoAccess 分析 Apache、Nginx Log,監控 Server 狀態


系統平台: CentOS 7

所需的 compile 套件(環境差異有所不同):
# yum install -y gcc GeoIP-devel php-pear php-pecl-geoip ncurses-devel

下載 GoAccess 套件:
# wget http://tar.goaccess.io/goaccess-1.2.tar.gz
# tar -xzvf goaccess-1.2.tar.gz
# cd goaccess-1.2/

編譯安裝:
# ./configure --enable-utf8 --enable-geoip=legacy
# make
# make install

修改 goaccess.conf 設定檔:
vi /usr/local/etc/goaccess.conf

調整時間格式:
# The following time format works with any of the
# Apache/NGINX's log formats below.
#
time-format %H:%M:%S

調整日期格式:
# The following date format works with any of the
# Apache/NGINX's log formats below.
#
date-format %d/%b/%Y

Log 檔內容格式:
# NCSA Combined Log Format
log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"

更改 UI 配色(SSH 連線 Console UI):
# Choose among color schemes
# 1 : Monochrome
# 2 : Green
# 3 : Monokai (if 256-colors supported)
#
color-scheme 2

排除 IP 位址:
# Exclude an IPv4 or IPv6 from being counted.
# Ranges can be included as well using a dash in between
# the IPs (start-end).
#
#exclude-ip 127.0.0.1
#exclude-ip 192.168.0.1-192.168.0.100
#exclude-ip ::1
#exclude-ip 0:0:0:0:0:ffff:808:804-0:0:0:0:0:ffff:808:808

調整 靜態檔案(static-file) 類型:
.................................等等


即時查看(沒有特別修改 Apache、Nginx 的 Log 格式沒有修改過 goaccess.conf 設定檔):
# /usr/local/bin/goaccess -f /var/log/nginx/access.log --log-format=COMBINED

沒修改 goaccess.conf、沒加 --log-format=COMBINED 啟動即時查看時,會先彈出要選擇 "Log Format Configuration"

Dashboard 欄位說明:
1.Unique visitors per day – Including spiders(分析每天多少不同的IP造訪)
2.Requested files (Pages-URL)(瀏覽的動態網頁)
3.Requested static files – (Static content: png,js,etc)(瀏覽的靜態檔案)
4.HTTP 404 Not Found response code (HTTP 404 錯誤的頁面)
5.Hosts (拜訪最多次數的IP,DDos常常看這裡)
6.Operating Systems (分析來客的系統,但這個參數可以偽裝)
7.Browsers (分析來客的瀏覽器,同樣可以偽裝)
8.Referrers URLs (最多請求的 URL)
9.Referring Sites (從哪裡URL來源鏈結過來的)
10.Top Keyphrases used on Google’s search engine (分析Google熱門關鍵字,似乎沒有辦法分析)
11.Geo Location (來源的地區)
12.HTTP Status Codes (HTTP狀態,可以拿來看網站的穩定度)
(Dashboard 欄位說明來源: Mr. 沙先生 https://shazi.info/)


動態更新 goaccess report.html 網頁(Console 下執行,執行後顯示持續執行中狀態):
# goaccess /var/log/nginx/access.log -o /var/www/html/report.html --real-time-html

WEB UI 重新整理(F5) 資訊即時更新。

crontab 排程產生網頁(每五分鐘更新一次):
*/5 * * * * /usr/local/bin/goaccess -f /var/log/nginx/access.log -a -o /var/www/html/web-report.html

瀏覽器連線:
http://host/web-report.html


其他用法:
goaccess 也附加了 GeoIP,用來分析 IP 的位置 :
# geoiplookup www.hinet.net

GeoIP Country Edition: TW, Taiwan


備註,以下設定都可在 goaccess.conf 裡設定:
排除 IP:
# /usr/local/bin/goaccess -f /var/log/nginx/access.log -e 192.168.1.1
# /usr/local/bin/goaccess -f /var/log/nginx/access.log -e 192.168.1.1-192.168.1.20

-e 的參數可以排除指定的 IP,也可以用範圍,但不支援 netmask

更改配色(SSH 連線 Console UI):
# /usr/local/bin/goaccess -f /var/log/nginx/access.log --color-scheme=(預設 1 灰色, 2 綠色)




沒有留言:

張貼留言

ManageEngine EventLog Analyzer版本更新步驟

更新檔下載位址: Upgrade to Latest Version of EventLog Analyzer Build (manageengine.com) 先將下載的更新檔上傳到主機裡,再進行下列動作。 切換到 ManageEngine EventLog Analyzer ...