Prometheus + Grafana 安装配置
安装文件下载
文件下载地址:
prometheus-2.37.1.linux-amd64.tar.gz
pushgateway-1.4.3.linux-amd64.tar.gz
node_exporter-1.3.1.linux-amd64.tar.gz
alertmanager-0.24.0.linux-amd64.tar.gz
grafana-9.1.5.linux-amd64.tar.gz
将所有文件下载存放到 /opt/prom 目录并解压
prometheus 服务端部署
创建服务
vi /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/opt/prom/prometheus-2.37.1.linux-amd64/prometheus --config.file=/opt/prom/prometheus-2.37.1.linux-amd64/prometheus.yml --web.listen-address=:9090 --web.enable-lifecycle
[Install]
WantedBy=multi-user.target
--web.enable-lifecycle
开启配置文件热加载,开启后修改 prometheus.yml 配置文件后不用重启 prometheus 服务,支持两种方式重新加载配置文件:
1、kill -HUP $(pidof prometheus)
2、curl -XPOST http://192.168.50.4:9090/-/reload
启动服务
systemctl daemon-reload
systemctl enable prometheus
systemctl start prometheus
执行 netstat
命令查看端口是否启动
netstat -nltup | grep 9090
浏览器访问:http://192.168.50.4:9090/
prometheus 推送网关部署
创建服务
vi /etc/systemd/system/pushgateway.service
[Unit]
Description=Prometheus Pushgateway
Documentation=https://prometheus.io/docs/instrumenting/pushing/
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/opt/prom/pushgateway-1.4.3.linux-amd64/pushgateway --web.listen-address=:9091
[Install]
WantedBy=multi-user.target
启动服务
systemctl daemon-reload
systemctl enable pushgateway
systemctl start pushgateway
配置推送网关
编辑 prometheus.yml 文件,在 scrape_configs 配置下新增一个 job
- job_name: "push-metrics"
static_configs:
- targets: ["192.168.50.4:9091"]
重新载入配置
kill -HUP $(pidof prometheus)
prometheus 节点导出器部署
创建服务
vi /etc/systemd/system/node_exporter.service
[Unit]
Description=Prometheus node_exporter
Documentation=https://prometheus.io/docs/instrumenting/exporters/
After=network.target
[Service]
Restart=on-failure
ExecStart=/opt/prom/node_exporter-1.3.1.linux-amd64/node_exporter --web.listen-address=:9100
[Install]
WantedBy=multi-user.target
启动服务
systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter
执行 netstat
命令查看端口是否启动
netstat -nltup | grep 9100
浏览器访问:http://192.168.50.4:9100/metrics
导出器配置
编辑 prometheus.yml 文件,在 scrape_configs 配置下新增一个 job
- job_name: "192.168.50.4"
static_configs:
- targets: ["192.168.50.4:9100"]
重新载入配置
kill -HUP $(pidof prometheus)
prometheus 告警管理器部署
创建服务
vi /etc/systemd/system/alertmanager.service
[Unit]
Description=Prometheus Alertmanager
Documentation=https://prometheus.io/docs/alerting/latest/overview/
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/opt/prom/alertmanager-0.24.0.linux-amd64/alertmanager --config.file=/opt/prom/alertmanager-0.24.0.linux-amd64/alertmanager.yml --web.listen-address=:9093
[Install]
WantedBy=multi-user.target
启动服务
systemctl daemon-reload
systemctl enable alertmanager
systemctl start alertmanager
执行 netstat
命令查看端口是否启动
netstat -nltup | grep 9093
浏览器访问:http://192.168.50.4:9093/
配置告警
将 prometheus.yml 文件的告警配置修改为如下内容:
alerting:
alertmanagers:
- static_configs:
- targets:
- 192.168.50.4:9093
重新载入配置
kill -HUP $(pidof prometheus)
Grafana 部署
创建服务
vi /etc/systemd/system/grafana.service
[Unit]
Description=Grafana Server
Documentation=https://grafana.com/docs/
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/opt/prom/grafana-9.1.5/bin/grafana-server --homepath /opt/prom/grafana-9.1.5 --config /opt/prom/grafana-9.1.5/conf/defaults.ini
[Install]
WantedBy=multi-user.target
通过 defaults.ini
配置文件中的 http_port
修改服务端口号,注释时使用英文分号,即 ;
启动服务
systemctl daemon-reload
systemctl enable grafana
systemctl start grafana
执行 netstat
命令查看端口是否启动
netstat -nltup | grep 3000
浏览器访问:http://192.168.50.4:3000/
初始账号密码:admin/admin
参考链接
https://prometheus.io/docs/prometheus/2.37/getting_started/
https://blog.csdn.net/qq_36546699/article/details/108316533
https://www.cnblogs.com/yjmyzz/p/how-to-install-prometheus-and-grafana.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?