GoAccess 分析nginx 日誌

2021-07-24 08:11:16 字數 4203 閱讀 4294

1、安裝goaccess需要一些系統支援庫

# yum -y install glib2 glib2-devel geoip-devel  ncurses-devel zlib zlib-devel
由於geo-ip庫沒有得到軟體作者的更新,分析的ip地理位置不準確,所以需要安裝外接ip庫分析ip的城市位置

# cd /usr/local

# tar zxvf nali-0.2.tar.gz

# cd nali-0.2

# ./configure

# make && make install

# nali-update
編譯安裝goaccess:

# cd /usr/local

# wget

# tar -xzvf goaccess-0.8.1.tar.gz

# cd goaccess-0.8.1/

# ./configure --enable-geoip --enable-utf8

# make && make install

centos伺服器可以雲安裝:yum install goaccess

然後就可以開始使用goaccess了。

首先,進入nginx的日誌目錄,如/var/log/nginx,輸入如下命令讓goaccess開啟指定檔案:

1 goaccess -f access.log

開啟之後會跳出選擇日誌檔案型別的介面:

nginx日誌是屬於combined log format (xlf/elf)型別的,所以我們選擇第三個。用上下游標移動,空格選中,回車確定。

進入了主介面:

鍵盤操作:

f1或h:幫助

f5 :重新整理主介面

q:退出程式/當前視窗/摺疊當前模組

o或enter:展開選中的模組或視窗

0-9以及shift + 0:將選中的模組或視窗啟用

k和j:模組內部移動

c:修改配色

^f和^b:模組中上下滾屏

tab shift+tab:前後切換模組

s:模組內部排序選擇

/:在所有模組中搜尋(支援正則)

n:找到下個匹配

g和g:跳到第一項/

如果報錯,則是nginx日誌格式和goaccess配置檔案不同,修改配置檔案

#vim /etc/goaccess.conf
#time-format

%ftime-format

%t#date-format

%d/%b/%y

log-format

%h%^[%d:%^] "%r"

%s%b

"%r"

"%u"

%^# squid native log

format

##time-format

%s

更改為如上所示即可

使用goaccess生成html報告

進入日誌目錄:

# cd /var/log/nginx/
如果日誌未壓縮:

#goaccess

-f access.

log.20161103

-a> index.html

如果日誌壓縮:

# zcat access.log.20161103.gz | goaccess -a >index.html
此時,就可以搭建php環境,將生成的html在網頁上呈現:

centos 7防火牆firewalld開放80埠:

#

firewall

-cmd--

zone=public--

add-

port=80/tcp--

permanent

平滑重啟:

# firewall-cmd --reload
安裝apache

# yum -y install httpd
開啟apache服務

# systemctl start httpd.service
設定apache服務開機啟動

# systemctl enable httpd.service
驗證apache服務是否安裝成功

在瀏覽器輸入:

安裝php

# yum -y install php
重啟apache服務

# systemctl restart httpd
或者

# systemctl restart httpd.service
在apache2預設目錄 /var/www/html

寫個php檔案

# vim /var/www/html/info.php
<?php phpinfo(); ?>

退出儲存

再在瀏覽器中輸入:

mysql安裝詳見另篇部落格

將php和mysql關聯起來

# yum -y install php-mysql
安裝常用的php模組

# yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
重啟apache服務

# systemctl restart httpd.service
【 lamp一鍵安裝:

不想折騰的,可以一鍵安裝lamp環境,詳見另篇部落格:centos7安裝zabbix監控

】最後,可將goaccess轉化log日誌生成的html檔案放在目錄/var/www/html中通過瀏覽器訪問

博主做了日誌模板:

登入頁

nginx日誌

ip城市分析

apache2日誌

監控apache2日誌:

則需要更改格式為 下面所示:

# vim /etc/goaccess.conf
# google cloud storage or

# the time in microseconds since the unix epoch.

##time-format %f

time-format

%tdate-format

%d/%b/%y

log-format

%v:%p

%h%^[%d:%^] "%r"

%s%b

"%r"

"%u"

%^# squid native log format

##time-format %s

GoAccess分析Nginx日誌

goaccess是乙個基於終端的快速日誌分析器。其核心思想是實時快速分析和檢視web伺服器統計資訊。1.安裝簡單 2.操作容易 3.介面酷炫 安裝分為yum安裝與原始碼安裝,大家可以自行選擇,我這裡選擇使用原始碼的方式安裝 1.安裝goaccess root bgx wget root bgx ta...

goaccess分析nginx日誌

最近想用goaccess來分析下nginx日誌,但是苦於nginx日誌配置格式不是按照正常格式來的,完全是我們按照自己的需求來寫的,所以導致goaccess分析不了,需要自己重新定義下格式 但是網上雖然介紹goaccess的很多,但是大多都是就重避輕,將格式的自定義忽略掉,因此我就來把自定義這塊說下...

使用GoAccess分析Nginx日誌

wget tar xzvf goaccess 0.9.6.tar.gz cd goaccess 0.9.6 configure prefix usr local goaccess enable geoip enable utf8 make make install 安裝缺失的庫 yum instal...