1 安装node_exporter
1.官网下载node_exporter (https://prometheus.io/download/) ,根据不同版本下面文件名需对应修改,这里选用1.3.1
2.把node_exporter-1.3.1.linux-amd64.tar.gz放到 /opt (可按自己需求调整目录) ,然后解压
tar -zxvf /opt/node_exporter-1.3.1.linux-amd64.tar.gz -C /opt/
3.添加node-exporter.service服务
cat > /usr/lib/systemd/system/node-exporter.service << EOF
[Unit]
Description=node_exporter
After=network.target
[Service]
Type=simple
ExecStart=/opt/node_exporter-1.3.1.linux-amd64/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload && systemctl enable node-exporter.service && systemctl restart node-exporter.service && systemctl status node-exporter.service
4. 访问服务器 http://IP:9100/metrics
2 安装Prometheus
1.官网下载Prometheus(https://prometheus.io/download/) ,根据不同版本下面文件名需对应修改,这里选用2.36.2,https://github.com/prometheus/prometheus/releases/download/v2.36.2/prometheus-2.36.2.linux-amd64.tar.gz
2.把prometheus-2.36.2.linux-amd64.tar.gz放到 /opt (可按自己需求调整目录) ,然后解压
tar -zxvf /opt/prometheus-2.36.2.linux-amd64.tar.gz -C /opt/
3.向prometheus.yml 添加配置
4.添加node-exporter.service服务
cat > /usr/lib/systemd/system/prometheus.service << EOF
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
Restart=on-failure
ExecStart=/opt/prometheus-2.36.1.linux-amd64/prometheus --config.file=/opt/prometheus-2.36.1.linux-amd64/prometheus.yml
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload && systemctl enable prometheus.service && systemctl restart prometheus.service && systemctl status prometheus.service
4. 访问服务器 http://IP:9090/targets
3 安装Grafana
1.官网下载Grafana(https://grafana.com/grafana/download) ,有多种安装方式,这里选用CentOS方式安装
#下载目录自行选择, 这里使用/opt存放下载文件
cd /opt
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.0.2-1.x86_64.rpm
sudo yum install grafana-enterprise-9.0.2-1.x86_64.rpm
sudo systemctl daemon-reload && sudo systemctl start grafana-server && sudo systemctl enable grafana-server
2.登录grafana-server
#查看grafana-server启动情况
sudo systemctl status grafana-server
登录grafana-server : 账号密码自行设置
http://IP:3000/
3.添加Prometheus数据源
3.添加grafana模板
登录 https://grafana.com/grafana/dashboards/
可选第一个最多人用的,也可以选用其他比较贡献者的,更新比较频繁的有可能比最多人用的好,主要看个人需求
可用ID导入或下载JSON文件导入
使用Json文件则下载文件,把内容考进去点击Load
选择对应数据库Import即可