Prometheus 安装

发布时间: 更新时间: 总字数:476 阅读时间:1m 作者: IP上海 分享 网址

下面介绍几种Prometheus Server的安装方式,如RPM安装、Docker安装、二进制安装、kubernetes 安装等。

Prometheus Server 安装部署

Prometheus 介绍:

  • 默认监听端口:9090
  • 访问:http://<ip>:9090/
    • /graph
    • /alerts
    • /config
    • /targets
    • /tsdb-status

二进制安装

  • 解压软件包
cd /usr/local/
tar -zxvf prometheus-2.19.2.linux-amd64.tar.gz -C /usr/local/
ln -s /usr/local/prometheus-2.19.2.linux-amd64 prometheus

# tsdb 目录
mkdir /var/lib/prometheus

# 创建用户
useradd -r -s /sbin/nologin prometheus
chown -R prometheus.prometheus /usr/local/prometheus/
chown -R prometheus.prometheus /var/lib/prometheus
  • 配置 PATH
$ cat /etc/profile.d/prometheus.sh
export PROMETHEUS_HOME=/usr/local/prometheus/
export PATH=${PROMETHEUS_HOME}:$PATH
  • 配置 service 文件
$ cat /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
After=network.target

[Service]
User=prometheus
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml  --storage.tsdb.path=/var/lib/prometheus --web.external-url=http://100.80.0.128:9090
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -KILL $MAINPID
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target
  • 查看配置
$ grep -Ev "^ *#|^$" /usr/local/prometheus/prometheus.yml
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
alerting:
  alertmanagers:
  - static_configs:
    - targets:
rule_files:
  # - "rules/*.yml"
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']
  - job_name: 'prometheus'
    # basic_auth 认证
    basic_auth:
      username: ""
      password: ""
    static_configs:
    - targets: ['localhost:9090']
  • 检查配置
cd /usr/local/prometheus/
promtool check config prometheus.yml

# 检查规则
promtool check rules rules/target.yml
  • 启动服务
systemctl daemon-reload
systemctl start prometheus
systemctl status prometheus
systemctl enable prometheus

RPM 包安装

rpm 源参考:https://github.com/lest/prometheus-rpm

docker 安装

docker run -d --name prometheus --restart always -p 9090:9090 prom/prometheus

kubernetes 安装

配置

添加静态配置主机

  • 修改 /usr/local/prometheus/prometheus.yml,新增一个 job_name: 'monitor-node'
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']
  - job_name: 'monitor-node'
    static_configs:
    - targets: ['<host1>:9090', '<host2>:9090', '<host3>:9090']
  • 检查配置
check config /usr/local/prometheus/prometheus.yml
  • 重启 prometheus 服务

Prometheus exporter 安装

数据展示

Grafana

Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数