在当今的云计算时代,对服务器进行实时、高效的监控是保障业务稳定运行的关键。本文将带你从零开始,在 RockyLinux 系统上搭建一套完整的云环境配置与RockyLinux监控体系。无论你是运维新手还是有一定经验的开发者,都能轻松上手。
RockyLinux 是一个社区驱动的、与 RHEL(Red Hat Enterprise Linux)100% 兼容的开源操作系统,具有高度稳定性、安全性和长期支持特性,非常适合部署在云环境中作为监控节点或被监控主机。
通过合理的系统监控工具组合,你可以实时掌握 CPU、内存、磁盘、网络等关键指标,及时发现异常并预警。
首先,确保系统是最新的,并安装一些常用工具:
sudo dnf update -ysudo dnf install -y wget curl vim net-tools
Prometheus 是一个开源的服务器性能监控系统,而 Node Exporter 负责采集主机的硬件和操作系统指标。
1. 创建专用用户:
sudo useradd --no-create-home --shell /bin/false prometheussudo useradd --no-create-home --shell /bin/false node_exporter
2. 下载并安装 Node Exporter:
cd /tmpwget 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.gzsudo cp node_exporter-1.7.0.linux-amd64/node_exporter /usr/local/binsudo chown node_exporter:node_exporter /usr/local/bin/node_exporter
3. 创建 systemd 服务文件:
sudo tee /etc/systemd/system/node_exporter.service <4. 启动服务:
sudo systemctl daemon-reloadsudo systemctl start node_exportersudo systemctl enable node_exporter此时,访问
http://你的服务器IP:9100/metrics应能看到采集到的指标数据。步骤三:安装 Prometheus Server
1. 下载 Prometheus:
cd /tmpwget https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gztar xvfz prometheus-2.45.0.linux-amd64.tar.gzsudo cp prometheus-2.45.0.linux-amd64/prometheus /usr/local/bin/sudo cp prometheus-2.45.0.linux-amd64/promtool /usr/local/bin/2. 创建配置目录并设置权限:
sudo mkdir /etc/prometheus /var/lib/prometheussudo chown prometheus:prometheus /var/lib/prometheus3. 编写 Prometheus 配置文件
/etc/prometheus/prometheus.yml:global: scrape_interval: 15sscrape_configs: - job_name: 'node' static_configs: - targets: ['localhost:9100']4. 创建 systemd 服务:
sudo tee /etc/systemd/system/prometheus.service <5. 启动 Prometheus:
sudo systemctl daemon-reloadsudo systemctl start prometheussudo systemctl enable prometheus现在访问
http://你的服务器IP:9090即可进入 Prometheus Web 界面。步骤四(可选):集成 Grafana 实现可视化
Grafana 能将 Prometheus 的数据以图表形式展示,大幅提升可读性。安装命令如下:
sudo dnf install -y grafanasudo systemctl start grafana-serversudo systemctl enable grafana-server访问
http://你的服务器IP:3000,默认账号密码为 admin/admin,首次登录会提示修改密码。添加 Prometheus 作为数据源后,即可导入官方提供的 Node Exporter Dashboard 模板(ID: 1860),快速获得专业监控视图。总结
通过本教程,你已经成功在 RockyLinux 上搭建了一套完整的云环境监控系统。这套方案结合了 RockyLinux监控、云环境配置、系统监控工具 和 服务器性能监控 四大核心要素,适用于个人项目、中小企业甚至大型生产环境。
建议定期备份配置文件,并根据实际需求调整采集频率和告警规则。安全方面,务必配置防火墙(如 firewalld)限制外部访问端口,或通过反向代理添加身份认证。
祝你监控顺利,系统稳定!
本文由主机测评网于2025-12-13发表在主机测评网_免费VPS_免费云服务器_免费独立服务器,如有疑问,请联系我们。
本文链接:https://www.vpshk.cn/2025127363.html