二进制部署
官方下载二进制包
wget https://github.com/prometheus/prometheus/releases/download/v2.29.2/prometheus-2.29.2.linux-amd64.tar.gz
解压并移动
tar -xf prometheus-2.29.2.linux-amd64.tar.gz -C /usr/local/
配置
global:
scrape_interval: 15s
evaluation_interval: 15s
query_log_file: /var/log/prometheus.log
external_labels:
monitor: 'prometheus-02'
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
- job_name: "prometheus-01"
static_configs:
- targets: ["192.168.168.156:9090"]
- job_name: "prometheus-02"
static_configs:
- targets: ["192.168.168.158:9090"]
这里需要声明 external_labels,标注你的地域。如果你是多副本运行,需要声明你的副本标识,如 0 号,1,2 三个副本采集一模一样的数据,另外 2 个 Prometheus 就可以同时运行,只是 replica 值不同而已。这里的配置和官方的 Federation 方案差不多。
直接启动
./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