记录在 Centos7 中安装 GoAccess 的过程。
安装依赖
安装 libmaxminddb,避免出现 ** Missing development files for libmaxminddb library. **
wget https://github.com/maxmind/libmaxminddb/releases/download/1.8.0/libmaxminddb-1.8.0.tar.gz
tar -xzvf libmaxminddb-1.8.0.tar.gz
cd libmaxminddb-1.8.0
$ ./configure
$ make
$ make check
$ sudo make install
$ sudo sh -c "echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf"
$ ldconfig
安装 ncurses-devel,避免出现:**configure: error: *** Missing development libraries for ncursesw**
yum install ncurses-devel
官方安装
wget https://tar.goaccess.io/goaccess-1.8.1.tar.gz
$ tar -xzvf goaccess-1.8.1.tar.gz
$ cd goaccess-1.8.1/
$ ./configure --enable-utf8 --enable-geoip=mmdb
$ make
# make install
输入 ** goaccess -V ** 验证,提示如下,表明安装成功。
GoAccess - 1.8.1.
For more details visit: https://goaccess.io/
Copyright (C) 2009-2023 by Gerardo Orellana
Build configure arguments:
--enable-utf8
--enable-geoip=mmdb
开机启动
可以实时输出 Dashborad。
首先新建启动脚本,因为在服务中,获取不到当前时间,因此把启动脚本单独放到一个 shell 中。
#!/bin/bash
# vim /etc/goaccess/daemonize.sh
/usr/local/bin/goaccess "/var/log/nginx/access-$(date -I).log" -o /opt/site/js-garden/access-log/real-time.html --log-format=COMBINED --real-time-html
其次在 /etc/systemd/system/ 中创建 goaccess.service 后台服务。
记得设置 nginx accesslog 访问权限。
[Unit]
Description=GoAccess Service
After=network.target nss-lookup.target
[Service]
NoNewPrivileges=true
ExecStart=/usr/bin/sh /etc/goaccess/daemonize.sh
Restart=on-failure
RestartSec=10s
LimitNOFILE=infinity
[Install]
WantedBy=multi-user.target
开机启动
systemctl daemon-reload
systemctl enable goaccess
systemctl restart goaccess
# 查看启动状态
systemctl status goaccess
定时归档
Nginx 按天纬度保存 accesslog ,为了追溯或排查问题,还需要根据以前的日志,定时归档。
我是每天 23点55分,对当天 accesslog 进行归档。
58 23 * * * /usr/local/bin/goaccess "/var/log/nginx/access-$(date -I).log" -o "/opt/site/js-garden/access-log/$(date -I).html" --log-format=COMBINED