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

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.dtcms.com/a/360258.html

相关文章:

  • [光学原理与应用-357]:ZEMAX - 分析 - 光线迹点
  • Ubuntu 中复制粘贴快捷键
  • 中国 AI 应用出海研究:出海逻辑和注意事项
  • Dreamore AI-解读并描绘你的梦境
  • USBX移植(X是eXtended的意思)
  • 基于i.MX6ULL的RAM Disk驱动开发
  • Linux目录和命令介绍
  • 如何建立奢侈品牌的数字资产安全管控体系?
  • leetcode 371 两个整数之和
  • 智能数据建设与治理 Dataphin-数仓分层
  • 基于AI的大模型在S2B2C商城小程序中的应用与定价策略自我评估
  • “机器人管家“离我们还有多远?
  • 7.3 el-menu
  • 【C2000】C2000的硬件设计指导与几点意见
  • 官方 API 与网络爬虫的技术特性对比及选型分析
  • shell编程基础入门-2
  • Overleaf中文显示
  • 把 `QVector<QPointF>` 写入文件:三种风格、三段独立可编译的完整代码
  • APB协议​​ 构建一个完整的 ​​UVM验证VIP Agent介绍类的要素
  • 《隐性质量:决定软件生命周期的看不见的竞争力》
  • 【Linux】创建线程
  • flutter工程
  • 包的相对导入
  • Android开发简介
  • Redis常见数据类型及应用场景
  • Pytest 插件介绍和开发
  • 极客时间AI 全栈开发实战营毕业总结(2025年8月31日)
  • NCCL-TEST ib集群测试UCX代替方案
  • mit6.031软件构造 笔记 Testing
  • ROI、 binning、下采样功能区别