步骤:
root@zookeeper-1:/opt# tar xf nginx-1.20.2.tar.gz
root@zookeeper-1:/opt# cd nginx-1.20.2/
root@zookeeper-1:/opt/nginx-1.20.2# git clone https://github.com/vozlt/nginx-module-vts.git
Cloning into 'nginx-module-vts'...
remote: Enumerating objects: 903, done.
remote: Counting objects: 100% (96/96), done.
remote: Compressing objects: 100% (52/52), done.
remote: Total 903 (delta 56), reused 64 (delta 44), pack-reused 807
Receiving objects: 100% (903/903), 1.18 MiB | 742.00 KiB/s, done.
Resolving deltas: 100% (606/606), done.
编译时除了常用的模块,需要加入nginx-module-vts模块
尽量每一步都用echo $?确认是否成功
root@zookeeper-1:/opt/nginx-1.20.2# ./configure --prefix=/apps/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/nginx-1.20.2/nginx-module-vts/
root@zookeeper-1:/opt/nginx-1.20.2# echo $?
0
root@zookeeper-1:/opt/nginx-1.20.2# make -j 4
root@zookeeper-1:/opt/nginx-1.20.2# echo $?
0
root@zookeeper-1:/opt/nginx-1.20.2# make install
root@zookeeper-1:/opt/nginx-1.20.2# echo $?
0
确认nginx已经加入了nginx-module-vts
root@zookeeper-1:/opt/nginx-1.20.2# ln -sf /apps/nginx/sbin/nginx /usr/bin/nginx
root@zookeeper-1:/opt/nginx-1.20.2# nginx -V
nginx version: nginx/1.20.2
built by gcc 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
built with OpenSSL 1.1.1f 31 Mar 2020
TLS SNI support enabled
configure arguments: --prefix=/apps/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/nginx-1.20.2/nginx-module-vts/
编辑/apps/nginx/conf/nginx.conf,加入以下配置打开状态页
http {
vhost_traffic_status_zone;
...
server {
...
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
}
}
启动Nginx服务后,通过/status访问到状态页
root@zookeeper-1:/opt/nginx-1.20.2# cd /apps/
root@zookeeper-1:/apps# wget https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.0/nginx-vts-exporter-0.10.0.linux-amd64.tar.gz
root@zookeeper-1:/apps# tar xf nginx-vts-exporter-0.10.0.linux-amd64.tar.gz
root@zookeeper-1:/apps# ln -sf /apps/nginx-vts-exporter-0.10.0.linux-amd64/nginx-vts-exporter /usr/bin/
/etc/systemd/system/nginx-vts-exporter.service
[Unit]
Description=Nginx
After=network.target
[Service]
ExecStart=/usr/bin/nginx-vts-exporter -nginx.scrape_uri=http://192.168.31.121/status/format/json
[Install]
WantedBy=multi-user.target
开启nginx_exporter,正常开启后9913端口被打开
systemctl enable --now nginx-vts-exporter.service
root@zookeeper-1:/apps# ss -tnl|grep 9913
LISTEN 0 4096 *:9913 *:*
尝试访问/metrics页,可以看到nginx开头的键值,如果没有,检查service文件
prometheus.yaml
- job_name: "Nginx-exporter-9913"
metrics_path: /metrics
static_configs:
- targets: ["192.168.31.121:9913"]
启动之后
2949