当前位置: 首页 > ds >正文

nginx-增加VTS模块

ngixn-增加VTS模块

  • 一、VTS模块的核心功能
  • 二、增加VTS模块


一、VTS模块的核心功能

Nginx Virtual Host Traffic Status Module 实时监控 Nginx 虚拟主机(或服务器块)的流量状态、请求指标、响应性能等数据,并提供可视化页面和 API 接口,方便运维人员排查问题、分析流量趋势

VTS 模块能监控的指标覆盖 “请求 - 流量 - 响应” 全链路,且支持按虚拟主机、服务、位置(Location)粒度拆分

功能分类核心监控指标
请求指标总请求数、成功请求数、各 HTTP 状态码(2xx/3xx/4xx/5xx)请求数、每秒请求数(RPS)
流量指标入站流量(接收字节数)、出站流量(发送字节数)、每秒流量(BPS)
响应性能指标平均响应时间、响应时间分布(如 100ms 内、500ms 内的请求占比)
连接指标当前活跃连接数、空闲连接数、已关闭连接数
过滤与排序支持按 “请求数、流量、响应时间” 等维度排序,也可过滤特定虚拟主机或状态码
数据输出方式1. 内置 HTML 可视化页面(直观查看)
2. JSON/CSV/Prometheus 格式 API(集成监控系统)

二、增加VTS模块

首先需要上传vts模块包nginx-module-vts-master.zip到/root家目录

下载与当前 Nginx 版本一致的源码和 VTS 模块源码
执行./configure时,在复制的原有参数后追加--add-module=path/nginx-module-vts

[root@web-2 ~]# vim install_nginx.sh
#!/bin/bash
set -e#下载nginx
mkdir  -p   /nginx9
cd  /nginx9
curl  -O  https://nginx.org/download/nginx-1.28.0.tar.gz
echo   "下载nginx成功"#解压nginx源码包
tar  xf  nginx-1.28.0.tar.gz
cd  nginx-1.28.0#解决nginx依赖的软件 
yum  install gcc pcre-devel  openssl-devel zlib-devel  vim  net-tools unzip -y#解压vts模块包 nginx-module-vts-master.zip
cp /root/nginx-module-vts-master.zip .
unzip nginx-module-vts-master.zip#编译前的配置工作
./configure  --prefix=/usr/local/nginx9 --with-http_ssl_module  
--with-http_v2_module --with-http_v3_module --with-http_stub_status_module 
--with-stream --with-stream_ssl_module --with-threads  
--add-module=/nginx9/nginx-1.28.0/nginx-module-vts-master#编译
make  -j  2
#编译安装
make  install#修改PATH环境变量
echo 'PATH=/usr/local/nginx9/sbin:$PATH' >> /etc/bashrc
echo "安装nginx成功,请使用nginx"#考虑nginx开机自启
echo  '/usr/local/nginx9/sbin/nginx' >>/etc/rc.local
chmod +x /etc/rc.d/rc.localsu

执行脚本

[root@web2 ~]# bash install_nginx.sh

如需给原来的nginx增加则需替换二进制文件,且参数要–prefix要一致,用objs/nginx替换sbin/nginx

目前有多个版本的nginx了,如何启动指定版本的nginx?
-> 使用绝对路径去启动nginx

/usr/local/nginx1/sbin/nginx
/usr/local/nginx1/sbin/nginx -s stop
/usr/local/nginx1/sbin/nginx -s reload

直接输入nginx会启动最新版本的nginx,因为PATH变量里的最左边的路径是最新的nginx的安装路径

[root@web2 sbin]# /usr/local/nginx1/sbin/nginx -s stop
[root@web2 sbin]# which nginx
/usr/local/nginx9/sbin/nginx

启动新的nginx

[root@web2 sbin]# nginx
[root@web2 sbin]# ps aux|grep nginx
root        5435  0.0  0.0  12220  2464 ?        Ss   16:35   0:00 nginx: master process nginx
sc          5436  0.0  0.1  16632  5536 ?        S    16:35   0:00 nginx: worker process
root        5438  0.0  0.0   6636  2176 pts/0    S+   16:35   0:00 grep --color=auto nginx
[root@web2 sbin]# nginx -V
nginx version: nginx/1.28.0
built by gcc 11.5.0 20240719 (Red Hat 11.5.0-5) (GCC) 
built with OpenSSL 3.2.2 4 Jun 2024
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx9 --user=sc --group=sc --with-http_ssl_module --with-http_v2_module --with-http_v3_module --with-http_stub_status_module --with-stream --with-stream_ssl_module --with-threads --add-module=/nginx9/nginx-1.28.0/nginx-module-vts-master

修改nginx.conf主配置文件,添加支持vts的功能

[root@web2 sbin]# cd /usr/local/nginx9/conf/
[root@web2 conf]# vim  nginx.conf
http {include       mime.types;default_type  application/octet-stream;log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';#添加vts功能的配置vhost_traffic_status_zone;vhost_traffic_status_filter_by_host on;access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;server {listen       80;server_name  www.feng.com;#charset koi8-r;access_log  logs/feng.com.access.log  main;location / {root   html;index  index.html index.htm;}#添加vts功能的配置location /status {vhost_traffic_status_display;vhost_traffic_status_display_format html;	}}..... 省略部分配置

刷新配置

[root@web2 conf]# nginx -t
nginx: the configuration file /usr/local/nginx9/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx9/conf/nginx.conf test is successful
[root@web2 conf]# nginx -s reload

最后去访问web服务器

访问效果

在这里插入图片描述

http://www.xdnf.cn/news/19550.html

相关文章:

  • 数据结构八股
  • 数据结构(C语言篇):(八)栈
  • vscode+EIDE+Clangd环境导入keil C51以及MDK工程
  • shell脚本第六阶段---三剑客之sed
  • C++日志系统:高效异步日志实现解析
  • LeetCode 36. 有效的数独 - 解题思路与实现详解
  • ans.1中的对象标识符OBJECT_IDENTIFIER----OID
  • 【机器学习基础】决策树算法原理及其在无人驾驶技术中的应用
  • Matplotlib:让数据在Python中跳舞的魔法画笔![特殊字符]
  • 基于FPGA的正弦波和及滤波(已通过仿真和上板)
  • 如何确定虚拟机的IP
  • DVWA靶场通关笔记-SQL Injection (Impossible级别)
  • [ Android Audio 篇 ] 高通平台 Android AudioRecord 多通道录音
  • LangChain中Prompt处理机制的技术架构与核心思想分析
  • STL库——stack/queue(类函数学习)
  • 切片语法[::-1]及其可用的类型
  • 基于STM32设计的智能家居控制系统(华为云IOT)_275
  • 2023年IEEE IOTJ SCI1区TOP,动态环境下无人机目标覆盖任务路径规划,深度解析+性能实测
  • KingbaseES JDBC 驱动详解:连接、配置与最佳实践
  • 介绍Ansible和实施Ansible PlayBook
  • pinia状态管理工具
  • Redis核心原理与Java应用实践
  • 洞悉边界:软件测试中边界值分析的艺术与科学
  • OpenJDK 17 解释器分发表与安全点表机制解析
  • 零基础入门AutoSar中的ARXML文件
  • 【Flask】测试平台开发,产品管理功能UI重构-第九篇
  • Kubernetes 服务发现与健康检查详解
  • 搭建卷积神经网络
  • 软考 系统架构设计师系列知识点之杂项集萃(139)
  • C++11语言(三)