使用goaccess分析nginx日志

GoAccess安装部署:

方案一:Yum安装部署
yum install glib2 glib2-devel GeoIP-devel ncurses-devel zlib zlib-develyum install gcc -y
yum -y install GeoIP-update
yum install goaccess

#修改/etc/nginx/nginx.conf文件的日志存储格式
log_format main '$remote_addr - $remote_user [$time_local] requesthost:"$http_host"; "$request" requesttime:"$request_time"; '
'$status $body_bytes_sent "$http_referer" - $request_body'
'"$http_user_agent" "$http_x_forwarded_for"';

#修改文件/etc/goaccess.conf改成goaccess格式标准对应为
time-format %T
date-format %d/%b/%Y
log-format %h - %^ [%d:%t %^] requesthost:"%v"; "%r" requesttime:"%T"; %s %b "%R" - %^"%u"

#测试生成页面
goaccess -f /var/log/nginx/access.log -c -a>/usr/share/nginx/html/go.html
方案二:源码安装部署

#yum安装依赖包
yum install glib2 glib2-devel GeoIP-devel ncurses-devel zlib zlib-devel
yum install gcc -y
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
yum -y install GeoIP-update

#下载goaccess源码包,并解压编译安装
wget https://tar.goaccess.io/goaccess-1.2.tar.gz
tar xzvf goaccess-1.2.tar.gz
cd goaccess-1.2/./configure --enable-geoip --enable-utf8make && make install

#修改/etc/nginx/nginx.conf文件的日志存储格式
log_format main '$remote_addr - $remote_user [$time_local] requesthost:"$http_host"; "$request" requesttime:"$request_time"; '
'$status $body_bytes_sent "$http_referer" - $request_body'
'"$http_user_agent" "$http_x_forwarded_for"';

#修改文件/usr/local/etc/goaccess.conf改成goaccess格式标准对应为
time-format %T
date-format %d/%b/%Y
log-format %h - %^ [%d:%t %^] requesthost:"%v"; "%r" requesttime:"%T"; %s %b "%R" - %^"%u"

#测试生成页面
goaccess -f /var/log/nginx/access.log -c -a>/usr/share/nginx/html/go.html

#后台实时生成数据到goaccess页面
/usr/local/bin/goaccess /var/log/nginx/access.log -o /usr/share/nginx/html/go.html --real-time-html &

 

点赞