Ngnix VTS模块添加和测试

目录

VTS模块介绍

 上传软件包xftp/lrzsz

 执行脚本

 添加vts的配置

测试

测试:nginx.conf配置文件是否有语法错误

 测试:windows机器上访问效果


VTS模块介绍

Nginx VTS模块(nginx Virtual Host Traffic Status Module)是一个第三方模块(需要自行下载),可以用于监控Nginx服务器的性能指标和流量统计。它提供了一组HTTP接口,通过这些接口可以获取关于Nginx服务器的详细信息,例如连接数、请求处理速度、状态码统计等等。这些信息对于监控和调优Nginx服务器非常有用。

示例图

 上传软件包xftp/lrzsz

此处用xftp上传,用脚本编译安装,软件包由上篇博客官网可下载

 [root@web2 ~]# pwd
/root
[root@web2 ~]# ls
anaconda-ks.cfg  nginx-module-vts-master.zip  onekey_install_yingboshuyuan_nginx_vts.sh

 脚本如下,这个脚本有很多linux的命令,非常有学习价值

[root@web2 ~]# vim onekey_install_yingboshuyuan_nginx_vts.sh 
#!/bin/bash

#解决软件的依赖关系,需要安装的软件包
#yum install epel-release -y
yum -y install zlib unzip zlib-devel openssl openssl-devel pcre pcre-devel gcc gcc-c++ autoconf automake make psmisc net-tools lsof vim  wget -y

#新建wangguang用户和组
id  wangguang|| useradd wangguang -s /sbin/nologin

#下载nginx软件
mkdir  /wangguang -p
cd /wangguang
wget  https://nginx.org/download/nginx-1.24.0.tar.gz

#解压软件
tar xf nginx-1.24.0.tar.gz 
#进入解压后的文件夹
cd nginx-1.24.0
#解压vts模块包nginx-module-vts-master.zip
cp /root/nginx-module-vts-master.zip .

unzip nginx-module-vts-master.zip
#编译前的配置,添加了vts模块解压后的绝对路径
./configure --prefix=/usr/local/wangguang  --user=wangguang --group=wangguang  --with-http_ssl_module   --with-threads  --with-http_v2_module  --with-http_stub_status_module  --with-stream   --with-http_gunzip_module  --add-module=/wangguang/nginx-1.24.0/nginx-module-vts-master

#如果上面的编译前的配置失败,直接退出脚本
if (( $? != 0));then
	exit
fi
#编译,启动2个进程去编译,这样速度快
make -j 2
#编译安装
make  install

#修改PATH变量
echo  "PATH=$PATH:/usr/local/wangguang/sbin" >>/etc/bashrc

#firewalld and selinux

#stop firewall和设置下次开机不启动firewalld
service firewalld stop
systemctl disable firewalld

#临时停止selinux和永久停止selinux
setenforce 0
sed  -i '/^SELINUX=/ s/enforcing/disabled/' /etc/selinux/config

#开机启动
chmod +x /etc/rc.d/rc.local
echo  "/usr/local/wangguang/sbin/nginx" >>/etc/rc.local


#启动nginx
/usr/local/wangguang/sbin/nginx
 执行脚本

 注意:这里which nginx显示说明已经nginx写入了PATH变量,后续需要操作nginx -t和nginx -s reload操作找不到脚本一定是没有写入PATH变量的问题!

[root@web2 ~]# bash  onekey_install_yingboshuyuan_nginx_vts.sh 
[root@web2 ~]# su
[root@web2 ~]# which nginx
/usr/local/wangguang/sbin/nginx
 添加vts的配置

 [root@web2 ~]# cd /usr/local/wangguang/conf/

[root@web2 conf]# cat nginx.conf|egrep -v "^$|^#| +#"

 修改配置文件,添加VTS模块

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
keepalive_timeout  65;
#添加vts功能的配置
vhost_traffic_status_zone;
vhost_traffic_status_filter_by_host on;

    server {
        listen       80;
        server_name  vts.sc.com;
        location / {
            root   html;
            index  index.html index.htm;
        }
	#添加vts功能的配置
	location /status {
		vhost_traffic_status_display;
		vhost_traffic_status_display_format html;	
	}
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

##注释下面的是需要添加的,一个是http语法块需要添加一个是server语法块也需要添加 

测试
测试:nginx.conf配置文件是否有语法错误

[root@web2 conf]# nginx  -t

nginx: the configuration file /usr/local/wangguang/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/wangguang/conf/nginx.conf test is successful

[root@web2 conf]# nginx  -s reload

 测试:windows机器上访问效果

 修改windows机器里的hosts文件,添加域名解析记录

C:\Windows\System32\drivers\etc\hosts 为路径

#添加一条到内网的A记录

192.168.203.149   vts.sc.com

 在浏览器里输入http://tvs.sc.com/status

注意不是https开头  如果使用ip和域名去访问都是一样的界面说明操作成功

ip访问

 域名访问

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值