1.官网下载
``https://github.com/prometheus/prometheus/releases
2.运行
#解压
tar -zxvf xxxxx.tar.gz
#后台启动并指定duan'kou
./prometheus --config.file=prometheus.yml --web.listen-address=:8091 &
3.查看
(二)安装node_exporter
在需要监控的目标服务器上安装【node_exporter】用以监控该服务器的各项指标。
1.下载安装包
https://github.com/prometheus/node_exporter/releases
2.运行
#解压
tar zxvf xxxxx.tar.gz
#后台启动并指定端口号
nohup ./node_exporter --web.listen-address=:8100 &
3.查看
http://localhost:8100/metrics
4.node_expertor与Promethues的交互配置
(三)安装Grafana
与prometheus原生UI相比,Granafa具有更强大的可视化功能。
1.下载安装
https://grafana.com/grafana/download
2.启动
sudo systemctl daemon-reload
sudo systemctl start grafana-server
sudo systemctl status grafana-server
3.卸载grafana及其依赖
sudo apt-get remove --auto-remove grafana
4.查看
http://localhost:3000/login
(四)安装alertmanage
1.下载安装包
https://prometheus.io/download/#alertmanager
2.修改配置
#解压
tar -xvf alertmanager-0.24.0.linux-amd64.tar.gz
#获取邮箱授权码
https://jingyan.baidu.com/article/ac6a9a5eb439f36b653eacc0.html
#修改alertmanager配置
vim /usr/local/alertmanager/alertmanager.yml
- 修改前
- 修改后
global:
resolve_timeout: 5m smtp_from: 3406747094@qq.com
smtp_auth_username: 3406747094@qq.com
smtp_auth_password: htvywgock(自己的)# 这里为第三方登录 QQ 邮箱的授权码 smtp_require_tls: false # 是否使用 tls,根据环境不同,来选择开启和关闭。如果提示报错 email.loginAuth failed: 530 Must issue a STARTTLS command first,那么就需要设置为 true。着重说明一下,如果开启了 tls,提示 报错 starttls failed: x509: certificate signed by unknown authority,需要在 email_configs 下配置 insecure_skip_verify: true 来跳过 tls 验证。
smtp_smarthost: 'smtp.qq.com:465' # 这里为 QQ 邮箱 SMTP 服务地址,官方地址为 smtp.qq.com 端口为 465 或 587,同时要设置开启 POP3/SMTP 服务。
route:
group_by: ['alertname']
group_wait: 5s
group_interval: 10s
repeat_interval: 2m
receiver: 'email-demo' receivers:
- name: 'email-demo'
email_configs:
send_resolved: true
- 检查配置
/usr/local/alertmanager/amtool check-config /usr/local/alertmanager/alertmanager.yml
vim /usr/local/alertmanager/alert.tmp
{{ define "email.from" }}3406747094@qq.com{{ end }}
{{ define "email.to" }}3406747094@qq.com{{ end }}
{{ define "email.to.html" }}
{{- if gt (len .Alerts.Firing) 0 -}}{{ range .Alerts }}@告警通知
告警程序: prometheus_alert
告警级别: {{ .Labels.severity }} 级
告警类型: {{ .Labels.alertname }}
故障主机: {{ .Labels.instance }}
告警主题: {{ .Annotations.summary }}
告警详情: {{ .Annotations.description }}
触发时间: {{ .StartsAt.Local.Format "2006-01-02 15:04:05" }}
{{ end }}{{ end -}}
{{- if gt (len .Alerts.Resolved) 0 -}}{{ range .Alerts }}
#修改Prometheus配置
vim /usr/local/prometheus/prometheus.yml
编辑告警规则
mkdir /usr/local/prometheus/rules
vim /usr/local/prometheus/rules/node_alerts.yml
groups:
- name: Host
rules:
- alert: HostCPU
expr: 100 * (1 - avg(irate(node_cpu_seconds_total{mode="idle"}[2m])) by(instance)) > 1
for: 5s
labels:
serverity: high
annotations:
summary: "{{labels.instance}}: High CPU Usage Detected" description: "{{labels.instance}}: CPU usage is {{$value}}, above 1%"
#检查配置文件
/usr/local/prometheus/promtool check config /usr/local/prometheus/prometheus.yml
#后台启动并指定服务端口号和集群端口号
./alertmanager --web.listen-address=":8093" --cluster.listen-address="127.0.0.1:8094" --config.file="alertmanager.yml" &
#启动prometheus
nohup ./node_exporter --web.listen-address=:8100 &
(五)更多告警方式
1.prometheus集成免费电话和短信告警
2.钉钉告警
二、参考资料
【01】普罗米修斯Prometheus安装和使用
【02】普罗米修斯入门系列教程
【03】如何搭建普罗米修斯 Prometheus
【04】如何更改prometheus监控系统启动的默认端口号
【05】无法访问github
【06】如何搭建node_exporter
【07】Prometheus Node_Exporter指定端口启动
【08】ubuntu 22.04 配置 Prometheus 和 Grafana 服务器监控
【09】如何搭建Grafana
【10】在ubuntu上安装grafana
【11】Prometheus如何集成免费电话和短信告警
【12】Alertmanager高可用,修改集群启动端口号
【13】Ubuntu 默认防火墙安装、启用、查看状态
【14】Linux(Ubuntu)关闭某个占用端口的进程
【15】Java项目中利用钉钉机器人Webhook向钉钉群推送告警通知