Xinu

GoAccess工具安装及使用
GoAccess工具安装及使用非常好用的服务器访问日志分析工具,支持客户端及web,支持主流服务器日志格式下载及安...
扫描右侧二维码阅读全文
09
2020/01

GoAccess工具安装及使用

GoAccess工具安装及使用

非常好用的服务器访问日志分析工具,支持客户端及web,支持主流服务器日志格式

UTOOLS1578558618924.png

下载及安装

环境依赖

yum install -y ncurses-devel openssl-devel libmaxminddb-devel 

下载、安装

wget https://tar.goaccess.io/goaccess-1.3.tar.gz
tar -zxvf goaccess-1.3.tar.gz
cd goaccess-1.3
./configure --prefix=/www/server/goaccess --enable-utf8 --enable-geoip=mmdb --with-openssl
# --enable-utf8 宽字符支持 主要是对中文的支持
# --enable-geoip 启用根据ip显示地理位置 需要下载ip 数据
make && make install
# 增加软链接
ln -s /www/server/goaccess/bin/goaccess /usr/local/bin/goaccess

启动

终端启动

# 使用 LANG='zh_CN.UTF_8' 可以生成中文的终端,如果系统默认语言是中文,可以省略
LANG='zh_CN.UTF_8' && goaccess access.log && LANG='en_US.UTF_8'

web端

GoAccess能够生成一个静态的html页面,在html页面中通过WebSocket与服务端建立连接,服务端监测到日志信息变化时会实时向打开的html发送WebSocket数据。

web界面查看实时日志分析,首先我们要在启动时加上--real-time-html参数和-o /path/to/report.html指明生成的html位置。地理位置需要去 https://dev.maxmind.com/geoip/geoip2/geolite2/ 下载数据包

LANG='zh_CN.UTF_8' && goaccess /www/wwwlogs/access.log -o /www/wwwroot/goaccess/report.html --geoip-database=/www/server/goaccess/ipdata/GeoLite2-City.mmdb --real-time-html --log-format=COMBINED --daemon && LANG='en_US.UTF_8'

启动成功以后,直接将report.html静态文件放在nginx下访问即可,服务器需要开放7890端口,用于websocket通信,如果无法开启可通过修改nginx配置文件及report.html文件支持80端口。

# nginx 配置
# 定义上游服务器
upstream goaccess_server {
    server 127.0.0.1:7890;  
}
# 设置反向代理 升级http协议为websocket
server {
    # ...
     location /goaccess {
        proxy_pass http://goaccess_svr;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
    # ...
}

修改report.html文件 搜索 【"port"】关键字 ,定义url与port

var connection = {"url": "www.sample.com/goaccess","port": 80}

重启 nginx 即可正常通过80端口进行websocket通信

Last modification:January 9th, 2020 at 08:22 pm

Leave a Comment