Prometheus+Grafana+Alertmanager+钉钉报警

测试环境   172.16.139.186

1、安装prometheus客户端

[root@172-16-139-186 1-prometheus]#tar -xf prometheus-2.33.3.linux-amd64.tar.gz   #解压软件包

[root@172-16-139-186 1-prometheus]#mv prometheus-2.33.3.linux-amd64/ /usr/local/prometheus #将软件包移动到安装软件的目录并改名

[root@172-16-139-186 1-prometheus]#cd /usr/local/prometheus/

[root@172-16-139-186 1-prometheus]#./prometheus --version

 

[root@172-16-139-186 1-prometheus]#sed -i '$s/"localhost:/"172.16.139.186:/' prometheus.yml #修改配置文件,IP为本机地址

[root@172-16-139-186 1-prometheus]#./promtool check config ./prometheus.yml #检查配置文件语法

[root@172-16-139-186 1-prometheus]#vim /usr/lib/systemd/system/prometheus.service

[root@172-16-139-186 1-prometheus]#systemctl daemon-reload

[root@172-16-139-186 1-prometheus]#systemctl enable prometheus.service --now

[root@172-16-139-186 1-prometheus]#ss -tunlp |grep 9090

此时通过浏览器访问:172.16.139.186:9090 ;确保prometheus正常

<think>嗯,用户想在Ubuntu上配置PrometheusGrafana,并设置钉钉告警。首先,我需要回忆一下PrometheusGrafana的安装步骤。Prometheus通常是通过下载二进制包,解压然后配置服务文件来安装的。Grafana的话,可能得添加APT仓库然后用apt安装,或者下载deb包。 然后,钉钉告警的话,PrometheusAlertmanager需要配置webhook指向钉钉机器人。记得钉钉机器人需要生成一个webhook地址,这个地址要放在Alertmanager的配置里。同时,Grafana本身也支持钉钉告警,可能需要配置通知渠道,不过用户可能更倾向于用PrometheusAlertmanager来做,所以得确认一下步骤。 接下来,用户提到的引用中有关于Prometheus配置的内容,比如引用[2]里的scrape_configs,可能需要配置目标。还有引用[4]提到Pushgateway,但用户的问题里暂时没提到这个,可能暂时不需要考虑,但可以留作扩展。 安装Prometheus的步骤应该是:下载、解压、创建用户和目录、配置systemd服务。然后验证是否运行在9090端口。Grafana的话,安装后要启动服务,默认端口3000,然后添加Prometheus数据源。 然后是Alertmanager的配置,下载安装,配置钉钉的webhook。需要创建一个alertmanager.yml文件,里面设置接收器和路由。同时,Prometheus的配置文件需要指向Alertmanager,并配置告警规则。 钉钉机器人方面,用户需要在钉钉群里添加自定义机器人,获取webhook URL,可能还需要设置关键词或IP安全设置。然后把这个URL放到Alertmanager的配置里,用Prometheus的模板生成告警信息。 测试部分,可能需要手动触发一个告警,比如让某个节点的exporter停止,看是否能够收到通知。或者使用一个测试的告警规则,比如up状态为0时触发。 注意事项方面,防火墙要开放相关端口,PrometheusAlertmanagerGrafana的端口分别是9090、9093、3000。权限问题,可能涉及文件权限和SELinux,但Ubuntu默认可能没开SELinux,所以主要检查文件权限和目录所有权。 还有,用户可能需要配置Prometheus的scrape_configs来监控目标,比如节点导出器,或者应用指标。这部分在引用[2]里有提到静态配置,可以指导用户如何添加监控目标。 最后,生成相关问题的时候,可以考虑扩展监控目标的添加、高可用部署、与其他通知集成的可能性,或者性能优化等问题。</think>### 分步指南:Ubuntu 系统搭建 Prometheus + Grafana 并集成钉钉告警 --- #### 一、安装 Prometheus 1. **下载并解压** ```bash wget https://github.com/prometheus/prometheus/releases/download/v2.53.2/prometheus-2.53.2.linux-amd64.tar.gz tar xvfz prometheus-*.tar.gz mv prometheus-* /opt/prometheus ``` 2. **创建系统用户与配置文件** ```bash sudo useradd --no-create-home --shell /bin/false prometheus sudo mkdir /etc/prometheus sudo cp /opt/prometheus/prometheus.yml /etc/prometheus/ ``` 3. **配置 systemd 服务** 创建文件 `/etc/systemd/system/prometheus.service`: ```ini [Unit] Description=Prometheus After=network.target [Service] User=prometheus ExecStart=/opt/prometheus/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus/data Restart=always [Install] WantedBy=multi-user.target ``` 启动服务: ```bash sudo systemctl daemon-reload sudo systemctl start prometheus sudo systemctl enable prometheus ``` --- #### 二、安装 Grafana 1. **添加仓库并安装** ```bash sudo apt-get install -y apt-transport-https wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add - echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list sudo apt-get update sudo apt-get install grafana ``` 2. **启动服务** ```bash sudo systemctl start grafana-server sudo systemctl enable grafana-server ``` 3. **访问 Grafana** 浏览器打开 `http://<服务器IP>:3000`,默认账号/密码:`admin/admin`。 --- #### 三、配置钉钉告警 1. **创建钉钉机器人** - 在钉钉群设置中选择「机器人」→「自定义」→ 设置关键词(如 `Alert`)并记录 Webhook URL[^4]。 2. **安装 Alertmanager** ```bash wget https://github.com/prometheus/alertmanager/releases/download/v0.27.0/alertmanager-0.27.0.linux-amd64.tar.gz tar xvfz alertmanager-*.tar.gz mv alertmanager-*/alertmanager /usr/local/bin/ ``` 3. **配置 Alertmanager** 创建 `/etc/alertmanager/alertmanager.yml`: ```yaml route: group_by: ['alertname'] receiver: 'dingtalk' receivers: - name: 'dingtalk' webhook_configs: - url: 'https://oapi.dingtalk.com/robot/send?access_token=YOUR_TOKEN' send_resolved: true ``` 4. **修改 Prometheus 告警规则** 在 `prometheus.yml` 中添加: ```yaml alerting: alertmanagers: - static_configs: - targets: ['localhost:9093'] rule_files: - /etc/prometheus/alert_rules.yml ``` 示例告警规则文件 `/etc/prometheus/alert_rules.yml`: ```yaml groups: - name: example rules: - alert: InstanceDown expr: up == 0 for: 1m labels: severity: critical annotations: summary: "Instance {{ $labels.instance }} down" ``` 5. **重启服务** ```bash sudo systemctl restart prometheus alertmanager ``` --- #### 四、验证告警 1. **触发测试告警** 停止某个被监控的 Exporter(如 Node Exporter),观察钉钉是否收到消息。 2. **Grafana 告警集成(可选)** 在 Grafana添加钉钉通知渠道: - 进入「Alerting」→「Notification channels」→ 选择「DingDing」类型并填写 Webhook URL。 --- #### 注意事项 1. **防火墙开放端口**:确保 `9090`(Prometheus)、`3000`(Grafana)、`9093`(Alertmanager)端口开放。 2. **权限问题**:若使用非默认路径,需确保目录权限归属正确[^2]。 3. **高可用扩展**:可通过 Pushgateway 处理短生命周期任务的指标采集[^4]。 --- §§ 1. 如何添加自定义监控目标到 Prometheus? 2. Prometheus 如何实现高可用部署? 3. Grafana 支持哪些其他告警通知渠道? 4. 如何优化 Prometheus 的存储性能? [^1]: [Grafana 作为可视化工具的优势](#) [^2]: [Prometheus 配置文件重载方法](#) : [Pushgateway 的作用与配置](#)
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值