Ubuntu 22.04 + APT 原生仓库 部署 Prometheus + Grafana【笔记】 - 实践

使用 Ubuntu 22.04 + APT 原生仓库 部署 Prometheus + Grafana 的详细完整步骤。内容包括:系统准备、APT 加速、安装 Prometheus、安装 Grafana、启动服务、验证访问、常用配置路径等。


一、准备工作
sudo apt update
sudo apt upgrade -y
❗国内加速(可选但强烈推荐)

Ubuntu 默认仓库访问国外服务器较慢,可改为国内源,例如清华源:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo sed -i 's@http://.*archive.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list
sudo sed -i 's@http://.*security.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list
sudo apt update

二、安装 Prometheus(APT 原生)

Ubuntu 22.04 官方仓库已内置 Prometheus 组件:

组件APT 包名
Prometheus 主服务prometheus
Node Exporterprometheus-node-exporter
Alertmanagerprometheus-alertmanager
1. 安装 Prometheus
sudo apt install prometheus -y

安装后产生的关键路径:

项目路径
配置文件/etc/prometheus/prometheus.yml
数据目录/var/lib/prometheus/
Systemd 服务prometheus.service
2. 启动并设置开机自启
sudo systemctl enable --now prometheus
3. 查看运行状态
sudo systemctl status prometheus
4. 浏览器访问(默认端口 9090)
http://服务器IP:9090

三、安装 Node Exporter(监控服务器本身使用)
sudo apt install prometheus-node-exporter -y
sudo systemctl enable --now prometheus-node-exporter

Node Exporter 默认端口 9100

http://服务器IP:9100/metrics
让 Prometheus 抓取 Node Exporter

编辑 Prometheus 配置:

posted @ 2026-01-18 13:03  gccbuaa  阅读(2)  评论(0)    收藏  举报