在反向代理后面运行Prometheus¶
在反向代理后面采用 sub-path
的Prometheus¶
在 CentOS 7环境Prometheus快速起步 采用 Nginx反向代理 ,使用的是 sub-path
模式,也就是说我的访问域名 onesre.cloud-atlas.io
的子路径 http://onesre.cloud-atlas.io/prometheus/
反向代理到运行 Prometheus快速起步 部署的服务器:
配置
/etc/nginx/conf.d/onesre-core.conf
设置反向代理:
upstream prometheus {
server 192.168.8.151:9090;
}
server {
listen 80;
server_name onesre onesre.cloud-atlas.io;
location / {
include proxy_params;
proxy_pass http://prometheus;
}
}
此时访问页面会报错的,需要修订
/etc/systemd/system/prometheus.service
添加--web.external-url
运行参数:
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
StartLimitIntervalSec=500
StartLimitBurst=5
[Service]
User=prometheus
Group=prometheus
Type=simple
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/home/data/prometheus \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries \
--web.listen-address=0.0.0.0:9090 \
--web.external-url=/prometheus/ \
--web.enable-lifecycle
[Install]
WantedBy=multi-user.target
重启 prometheus.service
之后,就能正常通过 http://onesre.cloud-atlas.io/prometheus/
反向代理访问新部署的 CentOS 7环境Prometheus快速起步