nginx日志分析--可视化
2021/5/2 7:25:38
本文主要是介绍nginx日志分析--可视化,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1. 安装依赖
yum install glib2 glib2-devel GeoIP-devel ncurses-devel zlib zlib-devel -y
wget https://github.com/maxmind/geoip-api-c/releases/download/v1.6.11/GeoIP-1.6.11.tar.gz
tar -zvxf GeoIP-1.6.11.tar.gz
cd GeoIP-1.6.11
./configure
make && make install
2. 安装goaccess
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 make && make install
3. 校对nginx和goaccess日志格式
查看你的nginx日志格式
cat /usr/local/nginx/conf/nginx.conf
'$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer"
''"$http_user_agent" "$http_x_forwarded_for"'
'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
4. 让你安装的goaccess插件了解你的nginx日志格式
使用如下方式获取日志格式:
sh nginx2goaccess.sh '日志格式'
sh nginx2goaccess.sh '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'
得到日志格式
得到的结果,在goaccess-1.3/config下面创建一个nginxlog.conf:
- Generated goaccess config:
time-format %T date-format %d/%b/%Y log_format %h - %^ [%d:%t %^] "%r"
5. 输出结果
./goaccess -f /usr/local/nginx/logs/access.log -p config/nginxlog.conf -o /usr/local/soft/report.html (报告内容阔以生成中文) LANG="zh_CN.UTF-8" bash -c "./goaccess -f /usr/local/nginx/logs/access.log -p config/nginxlog.conf -o /usr/local/soft/report.html"(<====输出路径可自行定义)
效果图如下:
/usr/local/nginx/log/access.log -p config/nginxlog.conf
这篇关于nginx日志分析--可视化的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-29fail2ban nginx
- 2024-03-18install nginx proxy manager
- 2024-01-2444从零开始用Rust编写nginx,命令行参数的设计与解析及说明
- 2024-01-22比Nginx更好用的Gateway!
- 2024-01-17nginx daemon off
- 2023-12-30Nginx Vhost Traffic Status 是什么意思-icode9专业技术文章分享
- 2023-12-26使用nginx搭建creates.io镜像(稀疏索引)
- 2023-11-18centos7编译安装Nginx教程。
- 2023-11-02nginx启动命令和停止命令
- 2023-10-25Centos7系统Nginx负载均衡如何安装和配置?