一、环境介绍
系统:centos7.8
软件:监控端–>prometheus-2.40.0-rc.0.linux-amd64.tar.gz
web展示:grafana-enterprise-9.2.3-1.x86_64.rpm
被监控端 --> node_exporter-1.4.0.linux-amd64.tar.gz
grafana官网下载 :https://grafana.com/grafana/download
prometheus官网下载: https://prometheus.io/download/
二、prometheus安装配置
1、监控端配置prometheus
tar zxf prometheus-2.40.0.linux-amd64.tar.gz -C /opt/
ln -sv /opt/prometheus-2.40.0.linux-amd64/ /opt/prometheus
groupadd prometheus
useradd -g prometheus -m -d /opt/prometheus/ -s /sbin/nologin prometheus
mkdir /opt/prometheus/data
chown -R prometheus:prometheus /opt/prometheus/*
cd /opt/prometheus
./promtool check config prometheus.yml #检测语法
./prometheus --config.file=prometheus.yml #启动服务
编辑文件配置(制作系统服务)
[root@localhost /opt]# cat /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus Monitoring System
Documentation=Prometheus Monitoring System
[Service]
Restart=on-failure
ExecStart=/opt/prometheus/prometheus
–config.file=/opt/prometheus/prometheus.yml
–storage.tsdb.path=/usr/local/prometheus/data
–web.listen-address=:9090
[Install]
WantedBy=multi-user.target
[root@localhost /opt]#
网页访问测试
http://ip地址:9090/
2、被监控端配置node_exporter
下载被监控端软件地址:https://github.com/prometheus/node_exporter/releases/tag/v1.4.0
tar -zxf node_exporter-1.4.0.linux-amd64.tar.gz -C /opt/
cd /opt/node_exporter-1.4.0.linux-amd64/
nohup ./node_exporter &
http://x.x.x.x:9100/metrics
3、将 node_exporter客户端加入prometheus.yml配置中
策略:允许指定ip地址访问本机端口
firewall-cmd --permanent --add-rich-rule ‘rule family=ipv4 source address=192.168.0.1/2 port port=9100 protocol=tcp accept’
或者开放9100端口
firewall-cmd --zone=public --add-port=9100/tcp --permanent
举个例子:
- job_name: ‘Linux’
static_configs:- targets: [‘192.168.142.132:9100’,‘192.168.142.134:9100’] 可以是多个,可以单个,逗号隔开
labels:
group: ‘client-node-exporter’
- targets: [‘192.168.142.132:9100’,‘192.168.142.134:9100’] 可以是多个,可以单个,逗号隔开
重启服务
systemctl restart prometheus.service
三、grafana安装配置
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.2.3-1.x86_64.rpm
yum install grafana-enterprise-9.2.3-1.x86_64.rpm
systemctl daemon-reloadsystemctl enable grafana-server.service
systemctl start grafana-server.service
http://ip地址:3000/ #访问页面