Loading... <div class="tip inlineBlock success"> 官方在线演示 https://rt.goaccess.io/?20170729002319 </div> 使用 GoAccess 的 --real-time-html 参数生成实时html后,用浏览器打开网页显示一片空白,状态一直在加载中。查看html源码发信息网页正常生成,网页也可离线打开,初步判断是与服务器建立socket连接异常,查看浏览器控制台发现提示: > SecurityError The operation is insecure. 查阅资料后发现可能是以下问题导致的。 - 没有开启7890端口 - https启动时没有指定 --ssl-cert,--ssl-key - https协议下只能使用wss连接,不能使用ws连接 但是如果 GoAccess 是通过 yum 安装的,默认是没有编译 openssl 模块的,指定 --ssl-cert 参数会提示: > unrecognized option '--ssl-cert' 所以我们只能通过编译安装,和想象中的一样,编译安装并不顺利。下面以Centos7为例介绍安装过程。 ## 安装依赖 这里只考虑编译openssl需要的依赖,其他的依赖问题可通过yum解决。 ### OpenSSL ```bash yum install openssl ``` ### GeoIP > 地理位置支持。依赖 MaxMind GeoIP 模块。 legacy 将使用原始 GeoIP 数据库。 mmdb 将使用增强版 GeoIP2 数据库。 这里我们使用 mmdb,查看最新版本https://github.com/maxmind/libmaxminddb/releases/ ```bash wget https://github.com/maxmind/libmaxminddb/releases/download/1.4.2/libmaxminddb-1.4.2.tar.gz tar zxvf libmaxminddb-1.4.2.tar.gz cd libmaxminddb-1.4.2 ./configure make make check make install ldconfig ``` ## 安装 GoAccess <div class="tip inlineBlock success"> GoAccess1.3 已经支持简体中文。 </div> ```bash wget http://tar.goaccess.io/goaccess-1.3.tar.gz tar -xzvf goaccess-1.3.tar.gz cd goaccess-1.3/ ./configure --enable-utf8 --enable-geoip=mmdb --with-openssl make make install ``` >GoAccess 拥有多个配置选项。获取完整的最新配置选项列表,请运行:./configure --help > >- `--enable-debug` > > 使用调试标志编译且关闭编译器优化。 > >- `--enable-utf8` > > 宽字符支持。依赖 Ncursesw 模块。 > >- `--enable-geoip=` > > 地理位置支持。依赖 MaxMind GeoIP 模块。`legacy` 将使用原始 GeoIP 数据库。`mmdb` 将使用增强版 GeoIP2 数据库。 > >- `--enable-tcb=` > > Tokyo Cabinet 存储支持。 `memhash` 将使用 Tokyo Cabinet 的内存哈希数据库。 `btree` 将使用 Tokyo Cabinet 的磁盘 B+Tree 数据库。 > >- `--disable-zlib` > > 禁止在 B+Tree 数据库上使用 zlib 压缩。 > >- `--disable-bzip` > > 禁止在 B+Tree 数据库上使用 bzip2 压缩。 > >- `--with-getline` > > 使用动态扩展行缓冲区用来解析完整的行请求,否则将使用固定大小(4096)的缓冲区。 > >- `--with-openssl` > > 使 GoAccess 与其 WebSocket 服务器之间的通信能够支持 OpenSSL。 ## 配置 GoAccess ```bash find / -name "goaccess.conf" vim /usr/local/etc/goaccess/goaccess.conf ``` 需要配置的地方有 > Time Format Options (required) > > Date Format Options (required) > > Log Format Options (required) > > Path to TLS/SSL certificate > > TLS/SSL private key > > WebSocket URI scheme 任何使用配置文件配置的地方都可以用启动参数代替,这里提供一个适用于nginx日志的启动参数 ```bash goaccess /logsaccess_nginx.log -o /report.html \ --real-time-html \ --time-format='%H:%M:%S' \ --date-format='%d/%b/%y' \ --log-format=COMBINED \ --ssl-cert='/ssl.cer' \ --ssl-key='/ssl.key' \ --ws-url=wss://host:7890 \ --port=7890 ``` 将以下内容替换成自己的 | 项目 | 含义 | | --------------------- | ----------------------------- | | /ssl.cer | ssl 公钥 | | /ssl.key | ssl 私钥 | | 7890 | GoAccess 监听的端口 | | wss://host:7890 | socket 协议 + hostname + 端口 | | /logsaccess_nginx.log | nginx 日志路径 | | /report.html | 生成的报告路径,下面会用到 | 如果不需要使用https查看报告,则不需要配置ssl-cert,ssl-key和ws-url ## 配置网络访问 ### Firewall 确保防火墙开启了 7890 端口 ### nginx 修改 server {} ```nginx server { ... location /report.html { alias /report.html; } ... } ``` 这样就可以通过 https://hostname/report.html 查看日志分析 ## 参考资料 https://github.com/allinurl/goaccess/issues/683 https://github.com/allinurl/goaccess/issues/1568 https://github.com/maxmind/libmaxminddb https://goaccess.io/man#examples https://www.goaccess.cc/?mod=download https://www.goaccess.cc/?mod=man 最后修改:2020 年 04 月 08 日 05 : 26 PM © 允许规范转载