goaccess日志分析工具

参考文档

  https://github.com/allinurl/goaccess

  https://blog.csdn.net/ytulnj/article/details/85125760?utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control

  https://www.jianshu.com/p/b134995ae16c?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

 

安装

#为方便最终日志统计时显示IP地理位置,需要安装依赖项GeoIP-devel:
yum install GeoIP-devel.x86_64
#安装ncurses-devel开发库:
yum install ncurses-devel
#安装tokyocabinet-devel开发库:
yum install tokyocabinet-devel
#安装openssl-devel开发库:
yum install openssl-devel

官网下载最新安装包

  https://github.com/allinurl/goaccess

  解压

  

./configure --enable-utf8 --enable-geoip=legacy

configure: error: 
*** Missing development files for the GeoIP library
或者是这个错误
Missing development files for libmaxminddb 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

./configure

make && make install 


make && make install

 

goaccess -V  #查看是否安装成功

whereis GeoIP #搜索位置
#为nginx添加模块http_geoip_module
#找到nginx的源码
echo '/usr/local/lib' > /etc/ld.so.conf.d/geoip.conf
 ./configure --prefix=/usr/local/nginx --with-http_geoip_module && make && make install #重新编译并安装新模块
nginx -V #查看是否安装成功显示新模块
nginx -s reload

 

nginx.conf日志配置修改
http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
}

goaccess.conf修改
whereis goaccess
vi xxx/goaccess.conf
添加:
date-format %d/%b/%Y
time-format %H:%M:%S
log-format %h %^[%d:%t %^] "%r" %s %b

 



 

goaccess -f /home/logs/xxx.access.log -o /usr/local/nginx/html/report.html -p /usr/local/etc/goaccess/goaccess.conf  --real-time-html --daemon
--daemonize参数是为了后台执行,执行这个的前提是有--real-time-html    
这个参数。
--real-time-html    实时更新
如果我们是https的还需要添加--ssl-cert=crt文件目录 --ssl-key=key文件目录这两个参数才可以实现wss

-f <input-file> : 需要解析的日志文件
-a --agent-list : 在host模块是不是能点击IP出现这个IP的user-agentlist,就是出现如图的功能

-o --output-format=csv|json 输出为csv或者json形式

-p --conf-file=<filename>
指定配置文件,如果你有配置文件,配置文件中又恰巧设置了log-format和date,那么你就不会被强制进入到format对话框了。如果你没有设置的话,默认使用~/.goacessrc。

--real-os
展示真实的操作系统。在Operation System模块中,是否展示更详细的操作系统信息。

 

 

让页面变成中文

vi /etc/locale.conf
LANG="zh_CN.UTF-8" #让页面变成中文
source /etc/locale.conf  #立即生效

 

 

注意:在使用--real-time-html可能不能实时刷新,是因为没有开端口号,可能是防火墙,默认socket连接使用7890端口,所以要保证端口号与外网畅通

 

posted @ 2021-05-25 23:41  RainBol  阅读(333)  评论(0编辑  收藏  举报
Live2D