下面介绍几种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
$ cat /etc/profile.d/prometheus.sh
export PROMETHEUS_HOME=/usr/local/prometheus/
export PATH=${PROMETHEUS_HOME}:$PATH
$ 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
其他安装方式
配置
添加静态配置主机
- 修改
/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 exporter 安装
数据展示
Grafana