Prometheus+grafana 搭建并使用

Prometheus 安装

Prometheus 是安时间存储数据因此 要保证每个节点的时间统一并且准确.

1.同步时间

下载时间同步

yum -y install ntpdate

同步阿里云时间

/usr/sbin/ntpdate ntp1.aliyun.com

2 安装Prometheus

下载Prometheus

 wget https://github.com/prometheus/prometheus/releases/download/v2.16.0/prometheus-2.16.0.linux-amd64.tar.gz

解压


tar -zxvf prometheus-2.16.0.linux-amd64.tar.gz

创建启动服务

vim /usr/lib/systemd/system/prometheus.service

保存以下内容,并保存

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target

重启 systemctl 服务

systemctl daemon-reload

设置开机自启动

systemctl enable prometheus.service

启动prometheus

systemctl start prometheus

访问 9090端口 进入UI页面
在这里插入图片描述

3.安装Node_Exporter

下载Node_Exporter 安装包

wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz

创建安装目录

mkdir  -p /usr/local/node_exporter

解压安装包

tar -zxvf node_exporter-0.18.1.linux-amd64.tar.gz  -C /usr/local/node_exporter

移动安装包

mv /usr/local/node_exporter/node_exporter-0.18.1.linux-amd64/*   /usr/local/node_exporter/

创建启动服务

vim /usr/lib/systemd/system/node_exporter.service

保存以下内容

[Unit]
Description=prometheus server daemon
[Service]
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target

重启daemon

systemctl daemon-reload

设置开机自启

systemctl enable node_exporter.service

启动服务

systemctl start node_exporter.service

查看状态

systemctl status node_exporter.service

修改prometheus配置文件 Prometheus.yml 添加监控信息

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']

  - job_name: 'linux'
    static_configs:
    - targets: ['localhost:9100','172.168.0.2:9100'] # 多个用,分开

重启prometheus 服务

systemctl reload prometheus.service

4.安装图像界面grafana

下载grafana 包

wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.5.2-1.x86_64.rpm

使用yum本地安装

yum localinstall grafana-enterprise-8.5.2-1.x86_64.rpm

添加启动服务

/sbin/chkconfig --add grafana-server

启动grafana

service grafana-server start

启动后访问地址:ip:3000(记得开放3000端口)
初始用户名和密码都是admin

登录后选择
在这里插入图片描述
填写url ,为prometheus 的url 默认为9090端口 ,确认
在这里插入图片描述返回首页
在这里插入图片描述
模板下载地址
https:/grafana.com/grafana/dashboards/

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是杨杨呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值