Tengine:7.使用GoAccess分析日志

2019-08-13  本文已影响0人  小六的昵称已被使用

环境

简介

第一步:安装

1.安装依赖

yum install -y ncurses-devel openssl-devel tokyocabinet-devel libmaxminddb-devel GeoIP-devel.x86_64

2.下载IP地址库

https://dev.maxmind.com/geoip/geoip2/geolite2/

3.下载并编译安装

./configure --prefix=/usr/local/goaccess \
--enable-utf8 \
--enable-geoip=mmdb \
--enable-tcb \
--with-openssl

make && make install && echo $?

4.启动

LANG="zh_CN.UTF-8" bash -c "/usr/local/goaccess/bin/goaccess \
        /home/Nginx_Log/nginx-01_access.log \
        /home/Nginx_Log/nginx-02_access.log \
        /home/Nginx_Log/nginx-03_access.log \
        -o /var/www/html/nginx.html \
        --geoip-database=/home/GeoLite2-City.mmdb \
        --time-format='%H:%M:%S' \
        --date-format='%d/%b/%Y' \
        --log-format=COMBINED \
        --date-spec=hr \
        --real-time-html"

第一步:安装

1.安装依赖

yum install -y GeoIP-devel.x86_64 ncurses-devel

2.下载并安装

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 && echo $?
make && echo $?
make install && echo $?

3.使用

goaccess -f /opt/nginx/logs/access.log -p /opt/goaccess/goaccess_log_conf_nginx.conf -o /opt/www/day-report.html

nohup goaccess -f /opt/tengine/logs/access.log -p -o /home/report.html --real-time-html --ws-url=report.xxx.com &

goaccess -f /var/log/nginx/access.log \
        -o /usr/share/nginx/html/report.html \
        --time-format='%H:%M:%S' \
        --date-format='%d/%b/%Y' \
        --log-format=COMBINED \
        --date-spec=hr \
        --real-time-html \
        --daemonize
    
        /opt/tengine/logs/access.log-20190405   日志路径
        /home/report.html                       报告路径
        --real-time-html                        实时html
        --daemonize                             使 GoAccess 作为守护程序运行(仅在 --real-time-html 开启下有效)。
        --log-format                            按小时分析
        -o --output=<json|csv>
            将给定文件重定向到标准输出,通过后缀名决定输出格式: 
            /path/file.csv - Comma-separated values (CSV)
            /path/file.json - JSON (JavaScript Object Notation)
            /path/file.html - HTML
        -a --agent-list                         开启 UserAgent 列表。开启后会降低解析速度。
        -e --exclude-ip <IP|IP-range>           排除一个 IPv4 或者 IPv6 地址。 使用连接符表示 IP 段(开始-结束)。
            exclude-ip 127.0.0.1
            exclude-ip 192.168.0.1-192.168.0.100
            exclude-ip ::1
            exclude-ip 0:0:0:0:0:ffff:808:804-0:0:0:0:0:ffff:808:808
        --444-as-404                            将非标准状态 444 作为 404 处理。
        --4xx-to-unique-count                   将 4xx 客户端错误数加到独立访客数中。
        --date-spec=<date|hr>                   设置日期的显示格式,一种是标准日期格式(默认),一种是日期后附加小时的格式。 
                                                仅在访客面板有效。对于在小时级别分析访客数据很有帮助。显示格式示例:18/Dec/2010:1
        --hour-spec=<hour|min>                  设定时间的显示格式,一种是标准时间格式(默认),一种是时间后附加分钟数(每十分钟)的格式。 
                                                用于时间分布面板。对于在特定时间段分析流量峰值很有用处。
        --ignore-crawlers                       忽略爬虫

        ## 地理位置选项
        -g --std-geoip                          标准 GeoIP 数据库,低内存占用。
        --geoip-database <geocityfile>          设定 GeoIP 数据库路径。例如:GeoLiteCity.dat。需要从 maxmind.com 上下载到本地。
                                                IPv4 和 IPv6 均可用支持。注意:--geoip-city-data 是    --geoip-database 的别名。 
                                                注意: 如果使用 GeoIP2,您需要从 MaxMind 下载 城市/国家 数据库,并通过 --geoip-database 设定。

LANG="zh_CN.UTF-8" bash -c \
    "goaccess -f /var/log/nginx/access.log \
            -o /usr/share/nginx/html/report.html \
            --time-format='%H:%M:%S' \
            --date-format='%d/%b/%Y' \
            --log-format=COMBINED \
            --date-spec=hr \
            --real-time-html \
            --daemonize"

LANG="zh_CN.UTF-8" bash -c "/usr/local/goaccess/bin/goaccess /home/Nginx_Log/*.log \
-o /var/www/html/nginx.html \
--geoip-database=/home/GeoLite2-City.mmdb \
--time-format='%H:%M:%S' \
--date-format='%d/%b/%Y' \
--log-format=COMBINED \
--date-spec=hr \
--real-time-html \
--daemonize"

4.在Nginx中添加访问链接

在Nginx中对应server内加入如下配置:

location /report.html {
    alias /opt/nginx/goaccess/report.html;
    access_log off;
}

重启Nginx,访问localhost:8080/report.html可以看到报告结果。

附录:

https://goaccess.io/download

https://www.goaccess.cc/?mod=man

http://www.qingpingshan.com/m/view.php?aid=401406

上一篇下一篇

猜你喜欢

热点阅读