夜莺集成 Prometheus 时序库:Remote Write 配置与多数据源实践
在云原生监控架构中,Prometheus 不仅是采集器,也可以作为时序存储后端。当我们需要将夜莺(Nightingale)的指标数据持久化到 Prometheus 时,关键在于启用 Remote Write 接收功能并正确配置双向对接。
一、部署支持 Remote Write 的 Prometheus
1. 安装准备
下载对应版本的二进制包并解压至指定目录。注意路径中不要包含空格或特殊字符。
mkdir -p /usr/local/prometheus
cd /usr/local/prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.54.0/prometheus-2.54.0.linux-amd64.tar.gz
tar zxvf prometheus-2.54.0.linux-amd64.tar.gz
2. 开启接收器参数
Prometheus 默认不监听写入请求,必须通过启动参数显式开启。不同版本参数略有差异,建议先查看帮助确认:
./prometheus --help | grep receiver
通常新版本使用 --web.enable-remote-write-receiver,老版本可能需 --enable-feature=remote-write-receiver。这里以新版为例。
3. 配置 Systemd 服务
创建 /etc/systemd/system/prometheus.service 文件,确保启动参数中包含远程写入开关及生命周期管理选项:
[Unit]
Description=prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/prometheus/prometheus-2.54.0.linux-amd64/prometheus \
--config.file=/usr/local/prometheus/prometheus-2.54.0.linux-amd64/prometheus.yml \
--storage.tsdb.path=/usr/local/prometheus/data \
--web.enable-lifecycle \
--web.enable-remote-write-receiver
Restart=on-failure
SuccessExitStatus=0
LimitNOFILE=65536
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=prometheus
=multi-user.target


