原创

prometheus安装教程

温馨提示:
本文最后更新于 2022年06月07日,已超过 661 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我

下载解压

可以直接下载二进制包,也可以自己下载源码包编译,下载地址:https://prometheus.io/download/

wget https://github.com/prometheus/prometheus/releases/download/v2.36.0/prometheus-2.36.0.linux-amd64.tar.gz
tar -zvxf prometheus-2.36.0.linux-amd64.tar.gz 
cd prometheus-2.36.0.linux-amd64

配置项:

# 全局配置
global:
  scrape_interval: 15s # 设置抓取间隔,默认1分钟,配置是15秒
  evaluation_interval: 15s # 估算规则的默认周期,默认1分钟,配置是15秒
  # scrape_timeout # 抓取超时时间,默认10秒

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# 规则文件列表,使用  evaluation_interval 间隔去抓取
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# 抓取节点配置,使用 scrape_interval 间隔去抓取
scrape_configs:
  # prometheus默认的节点配置
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9091"]

运行

./prometheus --config.file=./prometheus.yml --web.listen-address=0.0.0.0:9091 --storage.tsdb.path=/usr/local/prometheus-2.36.0.linux-amd64/data

启动成功截图:

仙士可博客

转为服务开机自启动

# vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
ExecStart=/usr/local/prometheus-2.36.0.linux-amd64/prometheus --config.file=/usr/local/prometheus-2.36.0.linux-amd64/prometheus.yml --storage.tsdb.path=/usr/local/prometheus-2.36.0.linux-amd64/data --web.listen-address=0.0.0.0:9091
WorkingDirectory=/usr/local/prometheus-2.36.0.linux-amd64/
Restart=on-failure
[Install]
WantedBy=multi-user.target

启动服务

 systemctl start prometheus
 systemctl status prometheus
 systemctl enable prometheus

仙士可博客

查看

访问:localhost:9090 即可看到prometheus自带的ui:

仙士可博客

正文到此结束
本文目录