linux安装goAccess日志分析工具

安装goAccess日志分析工具

1
2
3
4
5
6
$ 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
  • 如果出现错误configure: error: *** Missing development files for the GeoIP library
  • 解决办法
    1
    2
    3
    yum install GeoIP-devel
    yum install php-pear
    yum install php-pecl-geoip
  • 再重新配置 -> 编译 ->安装
  • 测试日志分析
    1
    goaccess -f time_access.log -a > report.html
  • 错误提示
    1
    2
    3
    Fatal error has occurred
    Error occured at: src/parser.c - verify_formats - 1691
    No time format was found on your conf file.
  • 添加配置文件
    1
    2
    3
    4
    vi ~/.goaccessrc
    time-format %T
    date-format %d/%b/%Y
    log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"
  • 添加参数-p制定时间格式化配置文件
    1
    goaccess -f time_access.log -p ~/.goaccessrc -a > report.html
  • 配置nginx文件自动分割脚本
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    #!/bin/bash
    # Program:
    # Auto cut nginx log script.
    # 2017/6/30 Alex

    # nginx日志路径 /data/log/nginx/log
    LOGS_PATH=/data/log/nginx
    TODAY=$(date -d 'today' +%Y-%m-%d)
    #echo $TODAY

    # 移动日志并改名
    mv ${LOGS_PATH}/edu_online.com.access.log ${LOGS_PATH}/log/access_edu_online_${TODAY}.log
    mv ${LOGS_PATH}/edu_online.com.error.log ${LOGS_PATH}/log/error_edu_online_${TODAY}.log

    # 向nginx主进程发送重新打开日志文件的信号
    #kill -USR1 $(cat /var/run/nginx.pid)
    nginx -s reload

nginx日志格式设置

1
2
3
4
5
6
7
8
9
log_format main '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for" '

'$connection $upstream_addr '

'$upstream_response_time $request_time';
  • 对应时间格式设置
    1
    2
    3
    4
    5
    time-format %T

    date-format %d/%b/%Y

    log_format %h - %^ [%d:%t %^] "%r" %s %b "%R" "%u" "%^" %^ %^ %^ %T