找两台还没回收的服务器(虚拟机),使用centos7.*系统
一台作为监控端,一台作为被监控端。
wget https://github.com/prometheus/prometheus/releases/download/v2.42.0/prometheus-2.42.0.linux-amd64.tar.gz
[root@localhost ~]# mkdir /data
[root@localhost ~]# tar xf prometheus-2.42.0.linux-amd64.tar.gz -C /data/
[root@localhost ~]# cd /data/
[root@localhost data]# ls
prometheus-2.42.0.linux-amd64
[root@localhost data]# ln -s prometheus-2.42.0.linux-amd64/ prometheus
添加Prometheus为系统服务开机启动(注意user、group、IP用自己的)
vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus server daemon
After=network.target[Service]
Type=simple
User=root
Group=root
ExecStart=/data/prometheus/prometheus \--config.file "/data/prometheus/prometheus.yml" \--storage.tsdb.path "/data/prometheus/data" \--storage.tsdb.retention=15d \--web.console.templates="/data/prometheus/consoles" \--web.console.libraries="/data/prometheus/console_libraries" \--web.max-connections=512 \--web.external-url "http://192.168.10.2:9090" \--web.listen-address "0.0.0.0:9090"
Restart=on-failure[Install]
WantedBy=multi-user.target
[root@localhost prometheus]# systemctl daemon-reload
[root@localhost prometheus]# systemctl start prometheus.service
[root@localhost prometheus]# systemctl enable prometheus.service
wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
[root@node-centos ~]# mkdir /data
[root@node-centos ~]# tar xf node_exporter-1.5.0.linux-amd64.tar.gz -C /data/
[root@node-centos ~]# cd /data/
[root@node-centos data]# ls
node_exporter-1.5.0.linux-amd64
[root@node-centos data]# ln -s node_exporter-1.5.0.linux-amd64/ node_exporter
依然将服务加入到开机启动
vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https:// prometheus.io/
After=network-online.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/data/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
[root@node-centos data]# systemctl daemon-reload
[root@node-centos data]# systemctl start node_exporter.service
[root@node-centos data]# systemctl enable node_exporter.service
[root@node-centos data]# systemctl status node_exporter.service
修改服务端配置文件,将被监控端加入服务端(在scrape_configs: 块下加入以下内容,注意ip是自己的
)
vim /data/prometheus/prometheus.yml
- job_name: "node_exporter"static_configs:- targets: ["192.168.10.3:9100"
[root@localhost ~]# systemctl restart prometheus.service
以下操作在服务端进行
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.3.6-1.x86_64.rpm
sudo yum install grafana-enterprise-9.3.6-1.x86_64.rpm
[root@localhost ~]# systemctl start grafana-server.service
[root@localhost ~]# grafana-cli plugins install grafana-piechart-panel
[root@localhost ~]# systemctl restart grafana-server.service
static_configs:- targets: ["192.168.10.3:9100"]- targets: ["192.168.10.2:9100"]
[root@localhost prometheus]# systemctl restart prometheus.service