一:nginx-module-vts介绍
由于所有业务只有一个公网IP入口,无法统计到每个业务的流量带宽,好在nginx上通过域名进行业务区分,可以借助nginx-module-vts模块来实现需求,相比较使用http_stub_status_module模块监控信息更加全面,并且可以提供json、html、prometheus格式的数据产出
使用该模块需要进行编译安装,并且同样适用于OpenResty
二:版本信息及下载链接
操作系统:CentOS 7.9
Nginx版本:1.20.2
Nginx下载链接:http://nginx.org/download/nginx-1.20.2.tar.gz
nginx-module-vts下载链接:GitHub - vozlt/nginx-module-vts: Nginx virtual host traffic status module
三:解压源码安装包
# 解压Nginx源码包至/root目录
[root@test ~]# ls /root
nginx-1.20.2.tar.gz
[root@test ~]# tar -zxvf nginx-1.20.2.tar.gz
# 解压nginx-module-vts模块至/root目录
[root@test ~]# ls /root/
nginx-module-vts-master.zip
[root@test ~]# unzip nginx-module-vts-master.zip
四:安装依赖环境
[root@test ~]# yum install -y \
pcre \
pcre-devel \
openssl-devel \
gcc \
gcc-c++ \
curl \
zlib \
zlib-devel \
openssl \
openssl-devel
五:编译安装
[root@test ~]# cd /root/nginx-1.20.2
[root@test nginx-1.20.2]# ./configure --add-module=/root/nginx-module-vts-master/
[root@test nginx-1.20.2]# make && make install
六:验证安装
[root@test ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.20.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
configure arguments: --add-module=/root/nginx-module-vts-master/
# 成功编辑安装后,执行nginx -V将显示安装附带的模块信息
七:编辑Nginx配置文件
[root@test ~]# vi /usr/local/nginx/conf/nginx.conf
# 在对应模块下添加以下内容
. . . . . .
http {
. . . . . .
vhost_traffic_status_zone;
. . . . . .
server {
. . . . . .
location /vts_status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
. . . . . .
}
. . . . . .
八:访问并测试
1.启动Nginx
[root@test ~]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
2.访问http://IP:80/vts_status
成功将显示各个虚机主机(站点)的详细监控数据
并且可以通过访问 http://IP:80/vts_status/format/json 获取监控数据