返回顶部

一键部署prometheus和granfana

一键部署prometheus和granfana

 基于shell脚本进行二进制安装prometheus和grafana

#cat prometheus_grafana.sh
#!/bin/bash
#********************************************************************
#Author:        wei
#********************************************************************
. /etc/rc.d/init.d/functions
set -e

Useradd () {
useradd  -s /sbin/nologin -M prometheus
}

Package_install () {

#准备prometheus-2.23.0.linux-amd64.tar.gz 和 grafana-enterprise-7.3.2.linux-amd64.tar.gz
[ -f ./prometheus-2.23.0.linux-amd64.tar.gz ] || wget https://github.com/prometheus/prometheus/archive/refs/tags/v2.23.0.tar.gz

[ -f ./grafana-enterprise-7.3.2.linux-amd64.tar.gz ] || wget https://dl.grafana.com/enterprise/release/grafana-enterprise-7.3.2.linux-amd64.tar.gz

tar xvf prometheus-2.23.0.linux-amd64.tar.gz  -C /data
chown -R prometheus:prometheus /data/prometheus-2.23.0.linux-amd64
echo 'export PATH=/data/prometheus-2.23.0.linux-amd64:$PATH' >> /etc/profile && source /etc/profile
cat > /usr/lib/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
User=prometheus
ExecStart=/data/prometheus-2.23.0.linux-amd64/prometheus --config.file=/data/prometheus-2.23.0.linux-amd64/prometheus.yml --storage.tsdb.path=/data/prometheus-2.23.0.linux-amd64/data
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl restart prometheus
systemctl enable  prometheus

tar -xvf grafana-enterprise-7.3.2.linux-amd64.tar.gz -C  /data

cat > /usr/lib/systemd/system/grafana-server.service <<EOF
[Unit]
Description=Grafana
After=network.target

[Service]
Type=notify
ExecStart=/data/grafana-7.3.2/bin/grafana-server -homepath /data/grafana-7.3.2
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start grafana-server
systemctl enable  grafana-server
}

Useradd
Package_install && action "prometheus grafana 安装成功"

访问验证

浏览器访问IP:port

 

 

 添加节点监控

监控节点指标

#wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz

#tar xvf node_exporter-1.3.1.linux-amd64.tar.gz -C /data

#cat << EOF > /usr/lib/systemd/system/node_exporter.service
[Service]
User=prometheus
Group=prometheus
ExecStart=/data/node_exporter-1.3.1.linux-amd64/node_exporter

[Install]
WantedBy=multi-user.target

[Unit]
Description=node_exporter
After=network.target
EOF

#systemctl daemon-reload
#systemctl status node_exporter
添加prometheus.yml配置 #egrep
-v '^#|^$|^[ ]+#' /data/prometheus-2.23.0.linux-amd64/prometheus.yml global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. alerting: alertmanagers: - static_configs: - targets: rule_files: scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] - job_name: 'node' #添加要监控的主机和端口 metrics_path: '/metrics' static_configs: - targets: - 'localhost:9090' - '10.0.0.117:9100' - '10.0.0.127:9100' - '10.0.0.137:9100'

 

 

官方链接

https://prometheus.io/download/

https://grafana.com/grafana/download

https://github.com/prometheus/node_exporter/releases/download

posted @ 2022-03-27 15:22  九尾cat  阅读(418)  评论(0编辑  收藏  举报