Skip to content

Commit bdce133

Browse files
author
zhang
committed
Prometheus
1 parent b5c52a9 commit bdce133

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

markdown-file/Nginx-Install-And-Settings.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ http {
102102

103103
-------------------------------------------------------------------
104104

105+
## Nginx 源码编译安装(带 Prometheus 模块)
106+
107+
```
108+
./configure \
109+
--prefix=/usr/local/nginx \
110+
--pid-path=/var/local/nginx/nginx.pid \
111+
--lock-path=/var/lock/nginx/nginx.lock \
112+
--error-log-path=/var/log/nginx/error.log \
113+
--http-log-path=/var/log/nginx/access.log \
114+
--with-http_gzip_static_module \
115+
--http-client-body-temp-path=/var/temp/nginx/client \
116+
--http-proxy-temp-path=/var/temp/nginx/proxy \
117+
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
118+
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
119+
--with-http_ssl_module \
120+
--with-http_stub_status_module \
121+
--http-scgi-temp-path=/var/temp/nginx/scgi \
122+
--add-module=/usr/local/nginx-module-vts
123+
```
124+
105125

106126
## Nginx 源码编译安装(带监控模块)
107127

markdown-file/Prometheus-Install-And-Settings.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ systemctl status node_exporter
110110
```
111111
修改prometheus.yml,加入下面的监控目标:
112112
113-
vim /usr/local/prometheus/prometheus.yml
113+
vim /data/docker/prometheus/config/prometheus.yml
114114
115115
scrape_configs:
116116
- job_name: 'centos7'
117117
static_configs:
118-
- targets: ['127.0.0.1:9100']
118+
- targets: ['192.168.1.3:9100']
119119
labels:
120120
instance: centos7_node1
121121
@@ -143,9 +143,17 @@ git clone --depth=1 https://github.com/vozlt/nginx-module-vts.git
143143
./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/opt/nginx-module-vts
144144
145145
make(已经安装过了,就不要再 make install)
146+
```
147+
148+
149+
```
150+
也有人做好了 docker 镜像:
151+
https://hub.docker.com/r/xcgd/nginx-vts
146152
153+
docker run --name nginx-vts -p 80:80 -v /data/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro -d xcgd/nginx-vts
147154
```
148155

156+
149157
```
150158
修改Nginx配置
151159
@@ -168,7 +176,8 @@ http {
168176
}
169177
170178
171-
验证nginx-module-vts模块:http://IP/status
179+
验证nginx-module-vts模块:http://192.168.1.3/status,会展示:
180+
Nginx Vhost Traffic Status 统计表
172181
173182
```
174183

@@ -185,11 +194,13 @@ server {
185194
- 安装 nginx-vts-exporter
186195

187196
```
188-
wget -O nginx-vts-exporter-0.5.zip https://github.com/hnlq715/nginx-vts-exporter/archive/v0.5.zip
189-
unzip nginx-vts-exporter-0.5.zip
190-
mv nginx-vts-exporter-0.5 /usr/local/prometheus/nginx-vts-exporter
191-
chmod +x /usr/local/prometheus/nginx-vts-exporter/bin/nginx-vts-exporter
197+
官网版本:https://github.com/hnlq715/nginx-vts-exporter/releases
198+
199+
wget https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.3/nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
192200
201+
tar zxvf nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
202+
203+
chmod +x /usr/local/nginx-vts-exporter-0.10.3.linux-amd64/nginx-vts-exporter
193204
```
194205

195206
```
@@ -204,7 +215,7 @@ After=network.target
204215
[Service]
205216
Type=simple
206217
User=root
207-
ExecStart=/usr/local/prometheus/nginx-vts-exporter/bin/nginx-vts-exporter -nginx.scrape_uri=http://localhost/status/format/json
218+
ExecStart=/usr/local/nginx-vts-exporter-0.10.3.linux-amd64/nginx-vts-exporter -nginx.scrape_uri=http://192.168.1.3/status/format/json
208219
Restart=on-failure
209220
210221
[Install]
@@ -215,18 +226,21 @@ WantedBy=multi-user.target
215226
```
216227
启动nginx-vts-exporter
217228
systemctl start nginx_vts_exporter.service
229+
systemctl daemon-reload
218230
systemctl status nginx_vts_exporter.service
219231
```
220232

221233

222234
```
223-
修改prometheus.yml,加入下面的监控目标:
235+
修改 prometheus.yml,加入下面的监控目标:
236+
vim /data/docker/prometheus/config/prometheus.yml
224237
225-
- job_name: nginx
238+
scrape_configs:
239+
- job_name: 'nginx'
226240
static_configs:
227-
- targets: ['127.0.0.1:9913']
228-
labels:
229-
instance: web1
241+
- targets: ['192.168.1.3:9913']
242+
labels:
243+
instance: nginx1
230244
231245
```
232246

0 commit comments

Comments
 (0)