企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] 推荐使用 `2.37.9` 的版本,是长期支持版本 prometheus是多副本。仅Prometheus配置文件的 `external_labels` 值不一样,其他步骤都是都是一样的 ## 下载Prometheus ```shell curl -L -o /usr/local/src/prometheus-2.37.9.linux-amd64.tar.gz https://github.com/prometheus/prometheus/releases/download/v2.37.9/prometheus-2.37.9.linux-amd64.tar.gz tar xf /usr/local/src/prometheus-2.37.9.linux-amd64.tar.gz -C /opt ``` ## 创建数据目录 ```shell mkdir -p /data/prometheus /app/prometheus cp -r /opt/prometheus-2.37.9.linux-amd64/console* /app/prometheus cp /opt/prometheus-2.37.9.linux-amd64/prometheus /opt/prometheus-2.37.9.linux-amd64/promtool /usr/local/bin/ ``` ## 修改配置文件 ```shell cp /opt/prometheus-2.37.9.linux-amd64/prometheus.yml /app/prometheus # global字段下添加标签,每个Prometheus的replica值都需要设置不一致 vim /app/prometheus/prometheus.yml global: ... external_labels: replica: A ``` ## 修改权限 ```shell chown -R ops. /data/prometheus /app/prometheus ``` ## 创建systemd服务 ```shell cat <<-EOF | sudo tee /usr/lib/systemd/system/prometheus.service > /dev/null [Unit] Description=prometheus Documentation=https://prometheus.io/ After=network.target [Service] Type=simple User=ops Group=ops ExecStartPre=/usr/local/bin/promtool check config /app/prometheus/prometheus.yml ExecStart=/usr/local/bin/prometheus \\ --config.file=/app/prometheus/prometheus.yml \\ --web.listen-address=127.0.0.1:9090 \\ --web.enable-lifecycle --web.enable-admin-api \\ --web.console.templates=/app/prometheus/consoles \\ --web.console.libraries=/app/prometheus/console_libraries \\ --storage.tsdb.path=/data/prometheus/ \\ --storage.tsdb.min-block-duration=2h \\ --storage.tsdb.max-block-duration=2h \\ --storage.tsdb.retention.time=2h \\ --log.level=info --log.format=json ExecReload=/usr/bin/curl -s -X POST http://127.0.0.1:9090/-/reload TimeoutStartSec=20s Restart=always LimitNOFILE=20480000 [Install] WantedBy=multi-user.target EOF ``` ## 启动服务 ```shell systemctl daemon-reload systemctl enable prometheus --now systemctl is-active prometheus.service ``` ## 验证 ```shell $ curl 127.0.0.1:9090/-/healthy Prometheus Server is Healthy. ``` ## 参考文档 二进制安装Prometheus:https://prometheus.io/docs/prometheus/latest/installation/#using-pre-compiled-binaries 下载Prometheus地址:https://prometheus.io/download/