devops/prometheus/install-prometheus.sh

43 lines
1.4 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -euo pipefail
echo "开始安装 Prometheus..."
sudo chown -R 65534:65534 /opt/prometheus/data
kubectl apply -f prometheus-configmap.yaml
kubectl apply -f prometheus-rbac.yaml
kubectl apply -f prometheus-deployment.yaml
kubectl apply -f prometheus-service.yaml
kubectl apply -f prometheus-ingress.yaml
echo "等待 Prometheus 启动..."
kubectl wait --for=condition=available --timeout=300s deployment/prometheus
echo "Prometheus 安装完成!"
echo "查看状态: kubectl get pods -l app=prometheus"
echo ""
echo "=========================================="
echo "Prometheus 与 Alertmanager 集成配置"
echo "注意:此部分需要在安装完 Alertmanager 后执行"
echo "=========================================="
echo "应用告警规则配置..."
kubectl apply -f prometheus-rules-configmap.yaml
echo "更新 Prometheus 配置以集成 Alertmanager..."
kubectl apply -f prometheus-configmap.yaml
kubectl apply -f prometheus-deployment.yaml
echo "等待 Prometheus 重新启动..."
kubectl wait --for=condition=available --timeout=300s deployment/prometheus
echo "=========================================="
echo "Prometheus 与 Alertmanager 集成完成!"
echo "=========================================="
echo "访问地址: https://prometheus-ops.t-aaron.com"
echo "告警管理: https://alertmanager-ops.t-aaron.com"
echo "已集成 Alertmanager告警规则已加载"
echo "=========================================="