在日常运维或开发中,了解 Linux 服务器的运行状态至关重要。然而,命令行输出的数据往往不够直观。本教程将带你从零开始,使用开源工具搭建一个Linux监控可视化面板,让你轻松掌握 CPU、内存、磁盘、网络等关键指标。
传统的 top、htop、iostat 等命令虽然强大,但信息分散且难以长期追踪。通过系统可视化,你可以:
我们将使用以下三个开源组件组合搭建监控系统:
首先,在你要监控的 Linux 服务器上安装 Node Exporter。以 Ubuntu/Debian 为例:
# 下载最新版 Node Exporter(请访问 https://github.com/prometheus/node_exporter/releases 获取最新链接)wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz# 解压tar xvfz node_exporter-1.7.0.linux-amd64.tar.gz# 进入目录并启动cd node_exporter-1.7.0.linux-amd64./node_exporter &
启动后,Node Exporter 默认监听 9100 端口。你可以通过浏览器访问 http://你的服务器IP:9100/metrics 查看原始指标数据。
在另一台机器(或同一台)上安装 Prometheus。下载并解压后,编辑其配置文件 prometheus.yml:
global: scrape_interval: 15sscrape_configs: - job_name: 'linux-server' static_configs: - targets: ['你的服务器IP:9100']
保存后启动 Prometheus:
./prometheus --config.file=prometheus.yml
访问 http://Prometheus服务器IP:9090,在“Status > Targets”中应能看到你的 Linux 主机状态为“UP”。
安装 Grafana(支持多种 Linux 发行版,这里以 Ubuntu 为例):
sudo apt-get install -y apt-transport-https software-properties-common wgetwget -q -O - https://apt.grafana.com/gpg.key | sudo apt-key add -echo "deb https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.listsudo apt-get updatesudo apt-get install grafanasudo systemctl start grafana-server
访问 http://Grafana服务器IP:3000(默认账号密码均为 admin)。
添加数据源:
http://localhost:9090然后导入现成的仪表盘模板(推荐 ID:1860,这是社区广泛使用的 Node Exporter 模板):
恭喜!你现在拥有了一个功能齐全的服务器状态监控面板,包含 CPU 使用率、内存占用、磁盘 IO、网络流量等核心指标。
通过本教程,你学会了如何利用 Prometheus + Node Exporter + Grafana 构建一套完整的性能监控工具链。这套方案免费、开源、可扩展,适用于个人项目、中小企业甚至大型生产环境。建议定期备份配置,并根据实际需求添加告警规则(可通过 Alertmanager 实现)。
现在,你再也不用盯着终端敲命令了——一切尽在可视化面板之中!
本文由主机测评网于2025-12-01发表在主机测评网_免费VPS_免费云服务器_免费独立服务器,如有疑问,请联系我们。
本文链接:https://vpshk.cn/2025121723.html