# 安装Prometheus
#!/bin/bash# 防止报错先 删除用户和目录
userdel prometheus
rm -rf /var/lib/prometheus
rm -rf /usr/local/prometheus/#下载解压
#wget https://github.com/prometheus/prometheus/releases/download/v2.19.2/prometheus-2.19.2.linux-amd64.tar.gz
tar zxvf prometheus-2.12.0.linux-amd64.tar.gz
mv prometheus-2.12.0.linux-amd64 /usr/local/prometheus#创建用户
groupadd prometheus
useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
chown prometheus.prometheus -R /usr/local/prometheus# 创建systemd服务
cat > /etc/systemd/system/prometheus.service <[Unit]
Description&#61;prometheus
After&#61;network.target
[Service]
Type&#61;simple
User&#61;prometheus
ExecStart&#61;/usr/local/prometheus/prometheus --config.file&#61;/usr/local/prometheus/prometheus.yml --storage.tsdb.path&#61;/var/lib/prometheus/data
Restart&#61;on-failure
[Install]
WantedBy&#61;multi-user.target
EOF# 启动Prometheus
systemctl daemon-reload
systemctl start prometheus
systemctl status prometheus
systemctl enable prometheus
# 安装 node_exporter
#!/bin/bash# 防止报错先 删除用户和目录
userdel prometheus
rm -rf /var/lib/prometheus
rm -rf /usr/local/prometheus/
rm -rf /usr/local/node_exporter#下载解压
#wget https://github.com/prometheus/prometheus/releases/download/v2.19.2/prometheus-2.19.2.linux-amd64.tar.gz
tar -zxvf node_exporter-0.18.1.linux-amd64.tar.gz
mv node_exporter-0.18.1.linux-amd64 /usr/local/node_exporter#创建用户
groupadd prometheus
useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
chown prometheus.prometheus -R /usr/local/prometheus# 创建systemd服务
cat > /etc/systemd/system/node_exporter.service <[Unit]
Description&#61;node_exporter
After&#61;network.target
[Service]
Type&#61;simple
User&#61;prometheus
ExecStart&#61;/usr/local/node_exporter/node_exporter
Restart&#61;on-failure
[Install]
WantedBy&#61;multi-user.target
EOF# 启动node_exporter
systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter
systemctl status node_exporter
# 查看配置文件
grep -v "#" /usr/local/prometheus/prometheus.yml |grep -v "^$"
global:
alerting:alertmanagers:- static_configs:- targets:
rule_files:
scrape_configs:- job_name: &#39;node&#39;static_configs:- targets:- &#39;10.69.15.78:9100&#39;- &#39;10.69.15.67:9100&#39;- &#39;10.69.15.30:9100&#39;- &#39;10.69.15.20:9100&#39;- &#39;10.69.15.21:9100&#39;
# grafana使用模板 linux 9276 docker使用 193 附 监控docker 插件和命令 暂未测试
# 推荐漂亮容器模板 8919