目录
1、环境准备
2、编译安装Nginx源码
2.1、安装依赖
2.2、编译安装Nginx
2.3验证Nginx安装
3、Nginx添加配置
3.11、Http模块下面添加
3.1.2、添加status访问页面
4、启动Nginx
4.3、访问前端页面
1、环境准备
参考Github
vts模块参考Github
nginx-1.20.2.tar.gz
vhost_traffic_status 相关的配置参数可以参考项目文档说明
/usr/local/nginx/sbin/nginx
2、编译安装Nginx源码
2.1、安装依赖
apt -y install gcc make libssl-dev zlib1g-dev libgd-dev libgeoip-dev libpcre2-dev libpcre3-dev apt install -y perl libperl-dev libgd3 libgd-dev libgeoip1 libgeoip-dev geoip-bin libxml2 libxml2-dev libxslt1.1 libxslt1-dev libssl-dev wget gnupg2 ca-certificates sudo apt-get -y install build-essential sudo apt-get -y install libtool
2.2、编译安装Nginx
1、模块存放路径,根据生产环境存放
/opt/suops/prometheus/pkgs/nginx_exporter/nginx-module-vts
2、安装路径
--prefix安装路径 /data/nginx/
./configure --prefix=/data/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-file-aio --with-stream --with-stream_ssl_module --with-stream_realip_module --add-module=/opt/suops/prometheus/pkgs/nginx_exporter/nginx-module-vts
make &&make install
2.3验证Nginx安装
2.3.1、版本验证
/data/nginx/sbin/nginx -V
可以看./configure 配置了什么,方便后续扩展
3、Nginx添加配置
3.11、Http模块下面添加
vhost_traffic_status_zone;
vhost_traffic_status_filter_by_host on;
3.1.2、添加status访问页面
server { # vts monitoring listen 3248; location /status { vhost_traffic_status_display; vhost_traffic_status_display_format html; } }
4、启动Nginx
4.1、添加系统启动
[Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/data/nginx/sbin/nginx ExecReload=/data/nginx/sbin/nginx -s reload ExecStop=/data/nginx/sbin/nginx -s stop PrivateTmp=true [Install] WantedBy=multi-user.target
4.2、验证Nginx
systemctl daemon-reload
systemctl enable nginx.service
systemctl start nginx
ps -ef |grep nginx
4.3、访问前端页面
搭配prometheus的nginx_exporter使用效果更佳