wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -zxvf nginx-1.20.1.tar.gz -C /usr/local
cd /usr/local/nginx-1.20.1
从git上拉取nginx-module-vts源码
git clone git://github.com/vozlt/nginx-module-vts.git
./configure --add-module=/usr/local/nginx-1.20.1/nginx-module-vts
nginx error: the HTTP rewrite module requires the PCRE library.
yum -y install pcre-devel
yum -y install openssl openssl-devel
make && make install
vim /usr/local/nginx/conf/nginx.conf
编辑nginx.conf,在http和server中加入配置信息。
http {
vhost_traffic_status_zone;
vhost_traffic_status_filter_by_host on; # 根据host分别进行流量统计
...
server {
...
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
}
}
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
设置开机自启动
systemctl daemon-reload
systemctl enable nginx
systemctl start nginx
systemctl status nginx
下载
wget https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.9.1/nginx-vts-exporter-0.9.1.linux-amd64.tar.gz
解压
tar -zxvf nginx-vts-exporter-0.9.1.linux-amd64.tar.gz
修改目录名称
mv nginx-vts-exporter-0.9.1.linux-amd64 /usr/local/nginx-vts-exporter
vim /usr/lib/systemd/system/nginx_vts_exporter.service
[Unit]
Description=prometheus_nginx_vts
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/nginx-vts-exporter/nginx-vts-exporter -nginx.scrape_uri http://192.168.1.1/status/format/json
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable nginx_vts_exporter
systemctl start nginx_vts_exporter
systemctl status nginx_vts_exporter
配置nginx指标节点nginx-vts-exporter
nginx-vts-exporter默认的端口为9913
#添加个节点
vim /usr/local/prometheus/prometheus.yml
...
- job_name: 'nginx' # 添加node配置
static_configs:
- targets:
- '192.168.1.1:9913'
...