windows安装请参考: https://blog.csdn.net/qq_41554118/article/details/118309457
https://github.com/prometheus/prometheus 【官网】
https://prometheus.io/download/ 【Prometheus 各模块下载 】
docker安装参考:https://www.cnblogs.com/momoyan/p/11520676.html
node_exporter安装
二进制包安装
#创建目录
mkdir -p /opt/exporter
cd /opt/exporter
#下载安装包
wget https://github.com/prometheus/prometheus/releases/tag/v2.28.0/node_exporter-1.1.2.linux-arm64.tar.gz
#解压
tar -xvzf node_exporter-1.1.2.linux-arm64.tar.gz
#修改名称
mv nnode_exporter-1.1.2.linux-arm64 node_exportercd /opt/exporter/node_exporter
#修改权限
chmod 777 node_exporter
#后台启动服务
nohup /opt/exporter/node_exporter/node_exporter &
#访问
curl http://IP:9100/metrics
推荐自启动安装:下载包上传解压后
###
cd /etc/systemd/system/
vim node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=root
ExecStart=/media/monitor/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
systemctl status node_exporter.service
systemctl stop node_exporter.service
service node_exporter restart
###浏览器输入地址访问
http://127.0.0.1:9100/metrics
2、prometheus 安装
cd /media/monitor/prometheus
mkdir {data,cfg,logs,bin} -p
mv prometheus promtool bin/
mv prometheus.yml cfg/
cd /media/monitor/prometheus/cfg
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: 'node_exporter'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9100']
vim /etc/profile
#prometheus
export PROMETHEUS_HOME=/usr/grafana/prometheus-2.10.0
export PATH=$PATH:${PROMETHEUS_HOME}/bin
source /etc/profile
cd /etc/systemd/system/
vim prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/grafana/prometheus-2.10.0/bin/prometheus --config.file=/usr/grafana/prometheus-2.10.0/cfg/prometheus.yml --storage.tsdb.path=/usr/grafana/prometheus-2.10.0/data
Restart=on-failure
[Install]
#下面两者选择一个,我也不知道哪个是绝对正确的。
#因为我装了两台服务器,第一台服务器用第一个配置可以正常运行,
#第二胎服务器就必须用第二个配置才能运行
WantedBy=multi-user.target
#WantedBy=default.target
systemctl daemon-reload
systemctl enable prometheus.service
systemctl start prometheus.service
systemctl status prometheus.service
systemctl stop prometheus.service
service prometheus restart
###浏览器输入地址访问
http://127.0.0.1:9090/
3、grafana
3.1、安装
下载:https://grafana.com/grafana/download
Linux安装
wget https://dl.grafana.com/oss/release/grafana-8.0.3.linux-arm64.tar.gz
tar -zxvf grafana-8.0.3.linux-amd64.tar.gz
cd /media/monitor//grafana
tar -zxvf grafana-8.0.3.linux-arm64.tar.gz
/media/monitor/grafana/bin/
./grafana-server
//设置脚本启动没有成功,报错:code=exited, status=1/FAILURE
vim grafana.service
[Unit]
Description=grafana
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=root
ExecStart=/media/monitor/grafana-8.0.3/bin/grafana-server
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl enable grafanaservice
systemctl start grafana.service
systemctl status grafana.service
systemctl stop grafana.service
service grafana restart
###浏览器输入地址访问
http://127.0.0.1:3000/
3.2、配置
(1)配置数据库
(2)导入模板
模板下载地址:https://github.com/starsliao/Prometheus/tree/master/node_exporter
中文模版
最终效果如下: