在 GitLab 中“监控 CentOS”通常有两种常见理解,我分别说明,并给出可落地的做法。
这是最常见场景:通过 GitLab Runner 在 CentOS 上执行监控脚本,并展示结果。
CentOS 服务器
└── 安装 GitLab Runner
└── 定时执行 .gitlab-ci.yml
└── 检查 CPU / 内存 / 磁盘 / 服务
# 添加官方仓库
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | bash
# 安装
yum install -y gitlab-runner
# 注册 Runner
gitlab-runner register
注册时:
https://gitlab.com 或私有 GitLab 地址例如:monitor.sh
#!/bin/bash
echo "===== CentOS 监控 ====="
echo "时间: $(date)"
echo "CPU 负载:"
uptime
echo "内存使用:"
free -h
echo "磁盘使用:"
df -h
echo "关键服务状态:"
systemctl status sshd | grep Active
chmod +x monitor.sh
.gitlab-ci.yml 定时监控stages:
- monitor
centos_monitor:
stage: monitor
only:
- schedules
script:
- bash monitor.sh
tags:
- centos
在 GitLab 中:
✅ 优点:
这是 运维 GitLab 本身 的场景。
top
htop
free -h
df -h
GitLab 提供 Prometheus + Grafana(默认启用)
查看:
gitlab-ctl status
gitlab-ctl tail
访问:
http://gitlab-ip/-/grafana
# 查看服务状态
gitlab-ctl status
# 查看资源使用
gitlab-ctl top
# 查看日志
gitlab-ctl tail nginx
gitlab-ctl tail postgresql
这是专业级做法。
CentOS
└── node_exporter
↑
Prometheus(GitLab 内置)
↓
Grafana
node_exporter✅ 适合:
| 需求 | 推荐方案 |
|---|---|
| 简单监控 | GitLab CI + Runner |
| 运维 GitLab | GitLab 自带 Prometheus |
| 企业级 | GitLab + node_exporter + Grafana |
| 报警 | GitLab Pipeline Failed / Alertmanager |
如果你愿意,可以告诉我:
我可以直接给你一套完整配置示例。