一元网络论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 178|回复: 0

Debian12系统中构建Prometheus与Grafana的配置指南

[复制链接]

1万

主题

1万

帖子

5万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
50059
发表于 2024-7-20 02:52:20 | 显示全部楼层 |阅读模式
大号探针实现效果呈现



系统搭建步骤如下:
首先,配置主服务器以运行Prometheus和Grafana,采用的操作系统为debian12。
安装Prometheus:
访问其GitHub仓库(https://github.com/prometheus/prometheus)并选择适合您操作系统的安装包。接着执行以下命令:
更新系统并安装必备软件:
```
apt-get update && apt-get dist-upgrade -y
apt install screen unzip wget curl net-tools git ntpdate -y
```
下载并解压Prometheus安装包:
```
wget https://github.com/prometheus/prometheus/releases/download/v2.53.1/prometheus-2.53.1.linux-amd64.tar.gz
tar zxf prometheus-2.53.1.linux-amd64.tar.gz -C /opt
mv /opt/prometheus-2.53.1.linux-amd64 /opt/prometheus
```
配置启动服务:
```
wget -P /lib/systemd/system http://d.junlin.li/prometheus/prometheus.service
systemctl daemon-reload
systemctl start prometheus
systemctl enable prometheus
```
验证Prometheus状态:
```
systemctl status prometheus
netstat -lnp
```
通过浏览器访问 http://ip:9090 检查服务是否正常运行。
接下来安装Grafana:
```
apt install apt-transport-https software-properties-common -y
wget -q -O - https://packages.grafana.com/gpg.key | apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | tee /etc/apt/sources.list.d/grafana.list
apt update -y && apt install grafana -y
```
配置Grafana服务:
```
systemctl daemon-reload
systemctl start grafana-server
systemctl enable grafana-server
```
确认Grafana在3000端口运行,并使用浏览器访问 http://ip:3000 。默认账号密码均为 'admin',登录后可跳过初次设置密码提示,通过设置界面将语言切换为中文。
安装配置node_exporter(用于监控目标服务器):
```
wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz
tar zxf node_exporter-1.8.2.linux-amd64.tar.gz -C /opt/
mv /opt/node_exporter-1.8.2.linux-amd64/ /opt/node_exporter
wget -P /lib/systemd/system http://d.junlin.li/prometheus/node_exporter.service
systemctl daemon-reload
systemctl start node_exporter
systemctl enable node_exporter
```
安装node_exporter插件并重启服务:
```
grafana-cli plugins install grafana-piechart-panel
grafana-cli plugins install digiapulssi-breadcrumb-panel
grafana-cli plugins install grafana-polystat-panel
systemctl restart grafana-server
```
验证node_exporter是否正常工作,访问 http://ip:9100/metrics 。
在Grafana中配置Prometheus数据源:
输入http://127.0.0.1:9090作为连接地址,点击Save&test。
导入Prometheus 2.0 Stats仪表板:
选择导入,然后从官方资源获取JSON文件。
导入第三方仪表板,确保已添加Prometheus数据源。
重启Grafana服务以应用更改。
在被监控的VPS上安装node_exporter并配置Prometheus监控:
编辑/opt/prometheus/prometheus.yml文件,添加新的job_name和target,例如:
```
- job_name: "test"
  static_configs:
    - targets: ["192.168.11.11:9100"]
```
重启prometheus服务并添加新的数据源到Grafana。
若需监控更多VPS,重复上述node_exporter安装和数据源添加步骤。完成之后,您可以在仪表板上查看所有被监控服务器的数据。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|一元网络论坛

GMT+8, 2024-9-10 13:26 , Processed in 0.095342 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表