• GoAccess日志分析工具


    简介

    官网:https://goaccess.io/download#installation

    GoAccess是一个非常良心的开源软件,它的良心之处体现在如下方面:
    1)安装简单;
    2)操作容易;
    3)界面酷炫;

    安装

    系统环境:sentos7

    selinux设置:

    查看:# sestatus

      SELinux status: disabled

    安装过程:

    方案一:yum安装

    #yum install glib2 glib2-devel GeoIP-devel  ncurses-devel zlib zlib-develyum install gcc -y
    #yum -y install GeoIP-update
    #yum install goaccess

    方案二:源码安装

    # 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

    配置完成:

    Your build configuration:
    
      Prefix         : /usr/local
      Package        : goaccess
      Version        : 1.3
      Compiler flags :  -pthread
      Linker flags   : -lnsl -lncursesw -lGeoIP -lpthread
      Dynamic buffer : no
      Geolocation    : GeoIP Legacy
      Storage method : In-memory Hash Database (Default)
      TLS/SSL        : no
      Bugs           : goaccess@prosoftcorp.com

    编译出错解决:

    1、

    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
    # cd GeoIP-1.6.11/
    # ./configure && make && make install

    2、

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

    解决:

    # yum install ncurses-devel
    # yum install ncurses-libs

    使用GoAccess分析日志

    这次分析日志为nginx标准输出

    ①goaccess命令使用: 

    # goaccess -f access.log

    ②出现goaccess界面:按“空格”选择格式为    NCSA Combined Log Format   

     

     ③再回车即可看到分析结果

    生成HTML页面

    修改配置,先查看当前配置:

    ]# egrep -v '^#|^$' goaccess.conf
    config-dialog false
    hl-header true
    json-pretty-print false
    no-color false
    no-column-names false
    no-csv-summary false
    no-progress false
    no-tab-scroll false
    with-mouse false
    agent-list false
    with-output-resolver false
    http-method yes
    http-protocol yes
    no-query-string false
    no-term-resolver false
    444-as-404 false
    4xx-to-unique-count false
    all-static-files false
    double-decode false
    ignore-crawlers false
    crawlers-only false
    ignore-panel REFERRERS
    ignore-panel KEYPHRASES
    real-os true
    static-file .css
    static-file .js
    static-file .jpg
    static-file .png
    static-file .gif
    static-file .ico
    static-file .jpeg
    static-file .pdf
    static-file .csv
    static-file .mpeg
    static-file .mpg
    static-file .swf
    static-file .woff
    static-file .woff2
    static-file .xls
    static-file .xlsx
    static-file .doc
    static-file .docx
    static-file .ppt
    static-file .pptx
    static-file .txt
    static-file .zip
    static-file .ogg
    static-file .mp3
    static-file .mp4
    static-file .exe
    static-file .iso
    static-file .gz
    static-file .rar
    static-file .svg
    static-file .bmp
    static-file .tar
    static-file .tgz
    static-file .tiff
    static-file .tif
    static-file .ttf
    static-file .flv

    由上可见默认配置中并无时间参数,需要在配置中添加时间参数。

    # cat  >>goaccess.conf<<EOF
    > time-format %H:%M:%S
    > date-format %d/%b/%Y
    > #NCSA Combined Log Format
    > log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"
    > EOF

    生成命令h5的日志页面

    # goaccess  /usr/local/nginx/logs/access.log -o /usr/local/nginx/logs/report.html -p /etc/goaccess.conf
    -p 指定配置文件
    -o 指定生成文件的位置

    添加到定时任务

    30 * * * * /usr/bin/goaccess  /usr/local/nginx/logs/access.log -o /usr/local/nginx/logs/report.html -p /etc/goaccess.conf

    访问:http://loghost/report.html

     

    调整

    1、中文展示

    如果你的系统默认设置时英文显示,想要以中文显示日志报表,就需要进行字符设置

    查看系统语言:
    # cat /etc/sysconfig/i18n
    LANG="en_US.UTF-8"
    SYSFONT="latarcyrheb-sun16"
    
    临时设置为中文的命令:
    # LANG="zh_CN.UTF-8"

    如果不设置系统默认语言,还有其他办法调整goaccess为中文吗?当然可以

    #LANG="zh_CN.UTF-8" bash -c "goaccess -p /etc/goaccess.conf /usr/local/nginx/logs/access.log -o /usr/local/nginx/logs/report.html --log-format=COMBINED"

    2、html可视化文件的实时更新方法:

    #nohup goaccess -f access.log -p goaccess.conf -o report.html --real-time-html --ws-url=report.xxx.com &
     
    
      选项解释
    
      -f 指定nginx日志文件
      -p 指定日志格式文件
      -o 输出到指定html文件
      --real-time-html 实时刷新
      --ws-url 绑定一个域名

    3、配置nginx中日志log_format中的日志格式

    改完记得reload配置

    3.1 获取nginx.conf中log_format配置

    3.2 获取nginx2goaccess脚本,可以将日志格式转换为goaccess能识别的日志格式,脚本地址:https://www.cnblogs.com/erbiao/p/9221543.html

    # sh nginx2goaccess.sh '$remote_addr $http_x_forwarded_for [$time_local] $host "$request_uri" $status "$http_referer" "$http_user_agent"'
    
    - Generated goaccess config:
    time-format %T
    date-format %d/%b/%Y
    log_format %h %^ [%d:%t %^] %v "%U" %s "%R" "%u"

    3.3 将转换后的内容加入到配置/etc/goaccess.conf 

  • 相关阅读:
    AOP 相关包
    Dubbo学习(一) Dubbo原理浅析
    maven 三个仓库表
    关于servlet中doGet和doPost乱码再一次理解
    关于对String中intern方法的理解
    模拟文件上传(五):为文件添加描述信息
    模拟文件上传(四):对于前面三版中一些出错细节进行处理
    对于模拟文件上传(三)中,批量上传,传空值抛异常前台约束实现
    模拟文件上传(三):使用apache fileupload组件进行文件批量上传
    模拟文件上传(二):使用apache fileupload组件进行文件上传
  • 原文地址:https://www.cnblogs.com/-abm/p/10846617.html
Copyright © 2020-2023  润新知