Prometheus+Grafana保姆笔记(1)——Prometheus的安装

Prometheus + Grafana 的组合在微服务项目中可以完成许多DevOps任务,它们共同提供了强大的监控和可视化功能。

我们陆续介绍Prometheus + Grafana 的相关用法。

首先介绍Prometheus+ Grafana的安装。

安装 Prometheus

Prometheus 是GO写的,并不依赖于 Java,所以不需要JDK的环境要求。你可以从Prometheus 的官方网站下载最新版本的文件。选选择版本2.53.1,并优先选择LTS版本下载

下载

可以直接wget

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

解压缩并选择安装目录:

 tar -zxvf prometheus-2.53.1.linux-amd64.tar.gz -C /usr/local/bin

很简单,没有别的什么花哨的东西,解压就算是安装结束了。下面开始简单的配置

新增用户(可选)

创建一个名为 prometheus 的系统用户,并禁止这个用户登录。

sudo useradd -r -s /bin/false prometheus

判断该用户是否创建成功或者是否存在,可以用

id prometheus
或者
grep prometheus /etc/passwd

给新用户增加文件夹权限

sudo chown -R prometheus:prometheus /usr/local/bin/prometheus

修改yml

配置文件在安装目录下usr/local/bin/prometheus/prometheus.yml,我们这一期先不讲如何修改,只说上业务后需要修改,浏览下yml的主要参数:

scrape_configs:     
    # 可选配置,根据需要进行调整  
    scrape_interval: 5s  # 缩短抓取间隔以获取更频繁的更新  
    scrape_timeout: 5s    # 设置抓取超时时间  
  - job_name: "prometheus"  
    static_configs:  
      - targets: ["localhost:9090"]

创建服务

最后,创建一个 Prometheus 的 systemd 服务文件 /etc/systemd/system/prometheus.service,并启动 Prometheus 服务。

[Unit]  
Description=Prometheus Server  
After=network.target  
  
[Service]  
Type=simple  
User=prometheus  
Group=prometheus  
ExecStart=/usr/local/bin/prometheus --config.file=/usr/local/bin/prometheus/prometheus.yml --storage.tsdb.path=/usr/local/bin/prometheus/  
Restart=always  
  
[Install]  
WantedBy=multi-user.target

 启动 Prometheus 服务,并设置开机自启动。

sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus
journalctl -u prometheus.service

 验证

浏览http://ip:9090/可以登录,代表启动成功啦。记得提前开放防火墙相关端口哟

安装 Grafana

直接rpm安装简单粗暴

sudo yum install -y https://dl.grafana.com/oss/release/grafana-11.1.3-1.x86_64.rpm

也可以用下载工具先下载下来再安装,因为有点小慢。

sudo rpm -ivh --prefix=/usr/local/grafana grafana-11.1.3-1.x86_64.rpm

安装过程中会提示

[root@localhost ~]# sudo rpm -ivh grafana-11.1.3-1.x86_64.rpm
警告:grafana-11.1.3-1.x86_64.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID 10458545: NOKEY
错误:依赖检测失败:
        fontconfig 被 grafana-11.1.3-1.x86_64 需要

直接安装fontconfig就行了

sudo yum install fontconfig

 然后我们再继续

sudo rpm -ivh --prefix=/usr/local/grafana grafana-11.1.3-1.x86_64.rpm

很顺利就会安装完毕

因为是rpm方式安装,不需要我们创建 systemd 服务文件,可以直接

sudo systemctl statusgrafana-server
sudo systemctl start grafana-server
sudo systemctl enable grafana-server

 安装好直接查看http://ip:3000端口验证

grafana默认的admin/admin,首次进去会强制修改密码,再进去就可以啦

好了,Prometheus + Grafana都安装好了,他们该怎么用呢?各个参数又该怎么配置?

我们下节课通过介绍Spring Boot Actuator来说明下,再见。

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

laolitou_1024

你的鼓励是我最大的动力

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

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

打赏作者

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

抵扣说明:

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

余额充值