nginx日志可视化分析GoAccess

作者: siediyer 分类: linux 发布时间: 2021-10-27 23:35

1、安装 GoAccess

yum install goaccess
wget https://tar.goaccess.io/goaccess-1.3.tar.gz
tar -xzf goaccess-1.3.tar.gz
cd goaccess-1.3
./configure --enable-utf8 --enable-geoip=legacy
make
make install

2、GeoIP错误

若出现 configure: error: *** Missing development files for the GeoIP library
则安装GeoIP

wget https://github.com/maxmind/geoip-api-c/releases/download/v1.6.12/GeoIP-1.6.12.tar.gz
tar -zxvf GeoIP-1.6.12.tar.gz
cd GeoIP-1.6.12
./configure 
make
make install

3、配置nginx

在 nginx.conf 文件中修改以下配置:

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';

在server中增加
location /report.html {
        alias /usr/local/nginx/html/go.html;
}

4、启动GoAccess

在 nginx 安装目录下,执行 goaccess 命令:

cd /usr/local/nginx
goaccess ./logs/access.log -o ./html/go.html --real-time-html --time-format='%H:%M:%S' --date-format='%d/%b/%Y' --log-format=COMBINED

需要中文界面,则执行

LANG="zh_CN.UTF-8" bash -c "goaccess ./logs/access.log -o ./html/go.html --real-time-html --time-format='%H:%M:%S' --date-format='%d/%b/%Y' --log-format=COMBINED"

 

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

Title - Artist
0:00