二进制部署

    1. 官方下载二进制包
    2. wget https://github.com/prometheus/prometheus/releases/download/v2.29.2/prometheus-2.29.2.linux-amd64.tar.gz
    3. 解压并移动
    4. tar -xf prometheus-2.29.2.linux-amd64.tar.gz -C /usr/local/

    配置

    1. global:
    2. scrape_interval: 15s
    3. evaluation_interval: 15s
    4. query_log_file: /var/log/prometheus.log
    5. external_labels:
    6. monitor: 'prometheus-02'
    7. # Alertmanager configuration
    8. alerting:
    9. alertmanagers:
    10. - static_configs:
    11. - targets:
    12. # - alertmanager:9093
    13. # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
    14. rule_files:
    15. # - "first_rules.yml"
    16. # - "second_rules.yml"
    17. # A scrape configuration containing exactly one endpoint to scrape:
    18. # Here it's Prometheus itself.
    19. scrape_configs:
    20. - job_name: "prometheus-01"
    21. static_configs:
    22. - targets: ["192.168.168.156:9090"]
    23. - job_name: "prometheus-02"
    24. static_configs:
    25. - targets: ["192.168.168.158:9090"]

    这里需要声明 external_labels,标注你的地域。如果你是多副本运行,需要声明你的副本标识,如 0 号,1,2 三个副本采集一模一样的数据,另外 2 个 Prometheus 就可以同时运行,只是 replica 值不同而已。这里的配置和官方的 Federation 方案差不多。

    直接启动

    1. ./prometheus --config.file="prometheus.yml" --web.listen-address="0.0.0.0:9090" --web.external-url="prometheus.devops.com" --web.enable-lifecycle --storage.tsdb.path="/prometheus-data" --storage.tsdb.min-block-duration=2h --storage.tsdb.max-block-duration=2h --storage.tsdb.retention.time=20d &

    —config.file 指定主配置文件 —web.enable-lifecycle 可以使用curl -X POST http://ip:port/-/reload 热加载 —storage.tsdb.retention.time 设置prometheus 本地保存天数 https://www.icode9.com/content-4-751399.html 配置解释

    浏览器访问:
    ip:port:9090