1,安装部署
1,环境准备。
IP地址 | 角色 |
---|---|
192.168.75.11 | Prometheus Server |
192.168.75.10 | node_exporter |
版本:
- 测试通过系统:CentOS Linux release 7.7.1908 (Core)
- Prometheus:prometheus-2.19.0.linux-amd64.tar.gz
- Alertmanager:alertmanager-0.20.0.linux-amd64.tar.gz
- node_exporter:node_exporter-1.0.0.linux-amd64.tar.gz
软件包下载地址:https://prometheus.io/download/
2,部署Prometheus Server
1,下载安装包
cd /usr/local/src/
wget https://github.com/prometheus/prometheus/releases/download/v2.19.0/prometheus-2.19.0.linux-amd64.tar.gz
wget https://github.com/prometheus/alertmanager/releases/download/v0.20.0/alertmanager-0.20.0.linux-amd64.tar.gz
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.0/node_exporter-1.0.0.linux-amd64.tar.gz
2,安装 Prometheus
创建prometheus用户
groupadd prometheus
useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
解压安装包
tar -zxv -f prometheus-2.19.0.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv prometheus-2.19.0.linux-amd64/ prometheus
创建启动脚本:
vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --storage.tsdb.retention.time=15d --log.level=info
Restart=on-failure
[Install]
WantedBy=multi-user.target
3,安装 node_exporter
在 Prometheus 节点
和另一台节点
上分别安装 node_exporter。
注意:node_exporter 的运行用户也是 prometheus 用户需要在每台节点上都创建该用户。
groupadd prometheus
useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
tar -zxv -f node_exporter-1.0.0.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv node_exporter-1.0.0.linux-amd64/ node_exporter
chown -R prometheus.prometheus node_exporter/
创建 node_exporter 启动脚本:
vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_export
Documentation=https://github.com/prometheus/node_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动 node_exporter 服务:
systemctl enable node_exporter.service
systemctl start node_exporter.service
systemctl status node_exporter.service
ss -tulnp | grep 9100
2,配置 Prometheus 添加监控目标
cd /usr/local/prometheus
vim prometheus.yml
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: '192.168.75.11'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090','localhost:9100'] # 对本机node_exporter 监控
# 新添加的对其它node节点抓取数据
- job_name: '192.168.75.10'
#重写了全局抓取间隔时间,由15秒重写成5秒。
scrape_interval: 5s
static_configs:
- targets: ['192.168.75.10:9100']
启动 Prometheus 服务:
chown -R prometheus.prometheus prometheus/
systemctl enable prometheus.service
systemctl start prometheus.service
systemctl status prometheus.service
注意
:要留意启动之前的目录权限更改,否则可能会在启动的时候报错Feb 11 16:08:41 localhost alertmanager: level=error ts=2019-02-11T08:08:41.419390133Z caller=main.go:179 msg="Unable to create data directory" err="mkdir data/: permission denied"
。
3,访问
访问 Prometheus WEB 查看我们定义的目标主机:http://192.168.75.11:9090/targets