BlueXIII's Blog

热爱技术,持续学习

0%

Nginx监控部署笔记

SSL支持

参考文档

https://blog.51cto.com/u_13363488/2350495

安装SSL依赖

1
2
# 直接使用yum安装ssl相关devel依赖
yum -y install openssl openssl-devel pcre pcre-devel zlib zlib-devel

编译参数

1
--with-http_ssl_module \

Prometheus监控

参考文档

下载nginx-module-vts

1
git clone git://github.com/vozlt/nginx-module-vts.git

编译参数

1
2
--with-http_stub_status_module \
--add-module=/data/pkg/nginx-module-vts-master

nginx.conf配置

1
2
3
4
5
6
7
8
9
10
11
12
13
# http新增
vhost_traffic_status_zone;

# server新增
# http_stub_status_module status
location = /basic_status {
stub_status on;
}
# nginx-module-vts status
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}

验证

Prometheus

ssh root@10.193.21.4 # yourpass!

vi prometheus.yml

1
2
3
4
5
6
7
8
9
10
11
- job_name: 'ES集群'
static_configs:
- targets: ['10.193.10.51:9100','10.193.10.52:9100','10.193.10.53:9100']

- job_name: 'Nginx监控'
metrics_path: '/status/format/prometheus'
scheme: 'http'
static_configs:
- targets: ['10.193.10.54:80']
labels:
instance: dev-nginx

Grafana

导入模板: https://grafana.com/grafana/dashboards/13816


地址位置限制

参考文档

安装geoip-devel

1
yum -y install geoip-devel

下载geoip数据库

https://www.miyuru.lk/geoiplegacy
https://mirrors-cdn.liferay.com/geolite.maxmind.com/download/geoip/database/

编译参数

1
--with-http_geoip_module \

nginx.conf配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# http新增

geoip_country /data/geoip/GeoIP.dat;
geoip_city /data/geoip/GeoLiteCity.dat;

geo $lan-ip {
default no;
10.193.0.0/16 yes;
}

map $geoip_country_code $allowed_country {
default no;
CN yes;
}

map $geoip_city $allowed_region {
default no;
Jinan yes;
}

# server新增
if ($lan-ip = yes) {
set $allowed_country yes;
}
if ($allowed_country = no) {
return 405;
}
if ($allowed_region = no) {
return 405;
}

验证

curl http://58.59.15.8:45444
curl http://10.193.10.54:80


Nginx编译

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 下载源码包
wget https://nginx.org/download/nginx-1.20.2.tar.gz

# 安装gcc
yum install gcc -y

# 配置
./configure --prefix=/data/nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--add-module=/data/pkg/nginx-module-vts-master \
--with-http_geoip_module \
--with-stream \
--with-http_v2_module \
--with-http_realip_module


# 编译
make
make install

验证:
http://10.193.10.54:80