一、环境介绍
系统:centos7.9
软件:监控端-->prometheus-2.33.5.linux-amd64.tar.gz grafana-8.4.3-1.x86_64.rpm
被监控端 --> node_exporter-1.3.1.linux-amd64.tar.gz
grafana官网下载 : https://grafana.com/grafana/download
prometheus官网下载: https://prometheus.io/download/
二、prometheus安装配置
1、监控端配置prometheus
groupadd prometheus
useradd -g prometheus -m -d /opt/prometheus/ -s /sbin/nologin prometheus
tar zxf prometheus-2.33.5.linux-amd64.tar.gz -C /opt/
ln -sv /opt/prometheus-2.33.5.linux-amd64/ /opt/prometheus
mkdir /opt/prometheus/data
chown -R prometheus:prometheus /opt/prometheus/*
cd /opt/prometheus
./promtool check config prometheus.yml #检测语法
./prometheus --config.file=prometheus.yml #启动服务
--------------------------配置prometheus服务开机启动-------------------------------
touch /usr/lib/systemd/system/prometheus.service
chown prometheus:prometheus /usr/lib/systemd/system/prometheus.service
vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
# --storage.tsdb.path是可选项,默认数据目录在运行目录的./dada目录中
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/opt/prometheus/data --storage.tsdb.retention=60d
Restart=on-failure
[Install]
WantedBy=multi-user.target
参数说明:
--config.file -- 指明prometheus的配置文件路径
--web.enable-lifecycle -- 指明prometheus配置更改后可以进行热加载
--storage.tsdb.path -- 指明监控数据存储路径
--storage.tsdb.retention --指明数据保留时间
systemctl daemon-reload
systemctl enable prometheus.service
systemctl restart prometheus.service
2、被监控端配置node_exporter
groupadd prometheus
useradd -g prometheus -m -d /usr/local/node_exporter/ -s /sbin/nologin prometheus
tar -zxf node_exporter-1.3.1.linux-amd64.tar.gz -C /usr/local/
ln -sv /usr/local/node_exporter-1.3.1.linux-amd64/ /usr/local/node_exporter
------------------------------配置node_exporter开机启动---------------------------
touch /usr/lib/systemd/system/node_exporter.service
chown prometheus:prometheus /usr/lib/systemd/system/node_exporter.service
chown -R prometheus:prometheus /usr/local/node_exporter
vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=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
systemctl daemon-reload
systemctl enable node_exporter.service
systemctl start node_exporter.service
访问:http://node_exporter的:9100/metrics
3、将 node_exporter加入prometheus.yml配置中
vim /opt/prometheus/prometheus.yml
# my global config
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.
# scrape_timeout is set to the global default (10s).
# 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:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: 'Linux'
static_configs:
- targets: ['192.168.142.132:9100']
labels:
group: 'client-node-exporter'
curl -X POST http://localhost:9090/-/reload #重新加载prometheus配置
http://192.168.142.132:9090/targets
三、grafana安装配置
1、安装配置
wget https://dl.grafana.com/oss/release/grafana-8.4.3-1.x86_64.rpm
sudo yum install grafana-8.4.3-1.x86_64.rpm
systemctl daemon-reload
systemctl enable grafana-server.service
systemctl start grafana-server.service
http://192.168.142.132:3000/ #访问页面