在现代运维体系中,RockyLinux告警规则配置是保障系统稳定运行的关键环节。本文将从零开始,详细讲解如何在 Rocky Linux 系统上配置基于 Prometheus 和 Alertmanager 的 Linux系统监控 告警机制。无论你是刚接触 Linux 运维的新手,还是有一定经验的工程师,都能轻松掌握。
当服务器 CPU 使用率飙升、磁盘空间不足或服务宕机时,如果没有及时通知,可能会导致业务中断甚至数据丢失。通过配置 RockyLinux监控告警 规则,我们可以实现实时监控 + 自动通知,极大提升故障响应速度。

确保你的 Rocky Linux 系统已安装以下组件:
若尚未安装,可参考官方文档或使用以下命令快速部署 Node Exporter:
# 下载并启动 Node Exporterwget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gztar xvfz node_exporter-1.7.0.linux-amd64.tar.gzcd node_exporter-1.7.0.linux-amd64./node_exporter &Prometheus 的告警规则通过 YAML 文件定义。我们将在 /etc/prometheus/rules/ 目录下创建一个名为 alerts.yml 的文件。
groups:- name: system-alerts rules: - alert: HighCpuUsage expr: 100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 85 for: 5m labels: severity: warning annotations: summary: "High CPU usage on {{ $labels.instance }}" description: "CPU usage is above 85% for more than 5 minutes." - alert: DiskSpaceLow expr: (node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"}) * 100 < 10 for: 10m labels: severity: critical annotations: summary: "Low disk space on {{ $labels.instance }}" description: "Available disk space is less than 10%." - alert: InstanceDown expr: up == 0 for: 1m labels: severity: critical annotations: summary: "Instance {{ $labels.instance }} is down" description: "The instance has been unreachable for more than 1 minute."以上规则分别监控:CPU 使用率过高、磁盘空间不足 和 实例宕机。这些是 Prometheus告警规则 中最常用的基础规则。
编辑 Prometheus 配置文件(通常为 /etc/prometheus/prometheus.yml),添加以下内容:
rule_files: - "rules/alerts.yml"alerting: alertmanagers: - static_configs: - targets: - localhost:9093保存后重启 Prometheus 服务:
sudo systemctl restart prometheusAlertmanager 负责将告警发送到邮箱、企业微信、钉钉等。以下是一个简单的邮件通知配置示例(/etc/alertmanager/alertmanager.yml):
global: smtp_smarthost: 'smtp.example.com:587' smtp_from: 'alert@example.com' smtp_auth_username: 'alert@example.com' smtp_auth_password: 'your_password'route: receiver: 'email-notifications'receivers:- name: 'email-notifications' email_configs: - to: 'admin@example.com'启动 Alertmanager:
sudo systemctl start alertmanagersudo systemctl enable alertmanager1. 访问 Prometheus Web UI(默认 http://your-server:9090)
2. 点击 “Alerts” 菜单,查看是否有触发的告警
3. 模拟高 CPU 负载(如运行 stress --cpu 4)测试 HighCpuUsage 规则
如果一切配置正确,你将在几分钟内收到邮件告警通知。
通过本教程,你已经掌握了在 Rocky Linux 上配置完整的 RockyLinux告警规则配置 流程。这套方案基于开源工具 Prometheus + Alertmanager,灵活、可靠且易于扩展。建议根据实际业务需求,逐步完善更多维度的监控指标(如内存、网络、应用健康检查等)。
记住:好的监控不是“有没有”,而是“快不快、准不准”。祝你在 Linux系统监控 的道路上越走越稳!
本文由主机测评网于2025-12-10发表在主机测评网_免费VPS_免费云服务器_免费独立服务器,如有疑问,请联系我们。
本文链接:https://www.vpshk.cn/2025125817.html