附:部署 Prometheus 作为时序库使用

Prometheus 的安装非常简单,就是一个二进制,下载启动就可以了。之所以还要单列一个章节来说明,是因为 Prometheus 要想作为时序库接收 remote write 协议的数据,即夜莺收到时序数据之后,要想转发给 Prometheus,需要 Prometheus 添加一个特定的启动参数 ,否则夜莺转发数据的时候会报 404,因为没有这个参数,Prometheus 就不会开启 /api/v1/write 接口的处理监听。这个启动参数是:

  • --enable-feature=remote-write-receiver 这是老版本的写法
  • --web.enable-remote-write-receiver 这是新版本的写法

要想确定你的 Prometheus 具体应该使用哪个写法,可以通过 help 信息来确认:

  1. ./prometheus --help | grep receiver

下面是一段小脚本,用于安装 Prometheus,供参考:

  1. version=2.45.3
  2. filename=prometheus-${version}.linux-amd64
  3. mkdir -p /opt/prometheus
  4. wget https://github.com/prometheus/prometheus/releases/download/v${version}/${filename}.tar.gz
  5. tar xf ${filename}.tar.gz
  6. cp -far ${filename}/* /opt/prometheus/
  7. # service
  8. cat <<EOF >/etc/systemd/system/prometheus.service
  9. [Unit]
  10. Description="prometheus"
  11. Documentation=https://prometheus.io/
  12. After=network.target
  13. [Service]
  14. Type=simple
  15. ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --storage.tsdb.path=/opt/prometheus/data --web.enable-lifecycle --web.enable-remote-write-receiver
  16. Restart=on-failure
  17. SuccessExitStatus=0
  18. LimitNOFILE=65536
  19. StandardOutput=syslog
  20. StandardError=syslog
  21. SyslogIdentifier=prometheus
  22. [Install]
  23. WantedBy=multi-user.target
  24. EOF
  25. systemctl enable prometheus
  26. systemctl restart prometheus
  27. systemctl status prometheus