被监控机器环境搭建&配置
- nginx-module-vts下载地址:
[root@nc-zhangfr1]# https://github.com/vozlt/nginx-module-vts
- nginx-module-vts安装
[root@nc-zhangfr1]# mv nginx-module-vts-master /usr/local/
- 编译环境
[root@nc-zhangfr1]# yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
- 安装nginx
[root@nc-zhangfr1]# wget nginx.org/download/nginx-1.15.7.tar.gz
--2021-03-17 14:25:15-- http://nginx.org/download/nginx-1.15.7.tar.gz
Resolving nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5704::6, ...
Connecting to nginx.org (nginx.org)|3.125.197.172|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1026732 (1003K) [application/octet-stream]
Saving to: ‘nginx-1.15.7.tar.gz’
100%[==================================================================================================================================================>] 1,026,732 325KB/s in 3.1s
2021-03-17 14:25:19 (325 KB/s) - ‘nginx-1.15.7.tar.gz’ saved [1026732/1026732]
- 解压
[root@nc-zhangfr1]# tar -zxvf nginx-1.15.7.tar.gz
- 编译安装nginx
[root@nc-zhangfr1 nginx-1.15.7]./configure --prefix=/home/nginx-1.15.7
[root@nc-zhangfr1 nginx-1.15.7] make && make install
- 检查与排错
出现下述错误,可以在nginx的路径下创建logs文件夹即可。mkdir logs
[root@nc-zhangfr1 nginx-1.15.7]# sbin/nginx -t
nginx: [alert] could not open error log file: open() "/home/nginx-1.15.7/logs/error.log" failed (2: No such file or directory)
nginx: the configuration file /home/nginx-1.15.7/conf/nginx.conf syntax is ok
2021/03/17 15:26:31 [emerg] 23660#0: open() "/home/nginx-1.15.7/logs/nginx.pid" failed (2: No such file or directory)
nginx: configuration file /home/nginx-1.15.7/conf/nginx.conf test failed
- 编译nginx-module-vts模块
[root@nc-zhangfr1 nginx-1.15.7]# ./configure --prefix=/home/nginx-1.15.7 --add-module=/usr/local/nginx-module-vts/
[root@nc-zhangfr1 nginx-1.15.7]# make && make install
- 修改nginx配置文件
增加如下内容
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;
}
... #默认配置
}
}
- 启动nginx
[root@nc-zhangfr1]# /home/nginx-1.15.7/sbin/nginx
- 查看nginx监控模块
-
安装nginx-vts-exporter
[root@nc-zhangfr1]# wget -c https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.9.1/nginx-vts-exporter-0.9.1.linux-amd64.tar.gz
[root@nc-zhangfr1]# tar -zxvf nginx-vts-exporter-0.9.1.linux-amd64.tar.g
- 启动nginx-vts-exporter
[root@nc-zhangfr1 nginx-vts-exporter-0.9.1.linux-amd64]# nohup ./nginx-vts-exporter -nginx.scrape_uri http://IP/status/format/json &
- 修改prometheus配置文件
- job_name: 'nginx'
static_configs:
- targets: ['IP:9913']
labels:
instance: web1
重启prometheus。
- Grafana导入模版