当前位置: 首页 > article >正文

Prometheus的详细部署

普罗米修斯下载网址: Download | Prometheus

准备两台机器:

192.168.58.152    prometheus

192.168.58.142    node_exporter

关闭防火墙和selinux:

[root@localhost ~]# setenforce 0 && systemctl stop firewalld

[root@localhost ~]# setenforce 0 && systemctl stop firewalld

给服务器改名:

[root@localhost ~]# hostnamectl set-hostname prometheus

[root@localhost ~]# hostnamectl set-hostname node_exporter

服务端操作: 

下载安装prometheus

# 下载prometheus
[root@prometheus ~]#  wget https://github.com/prometheus/prometheus/releases/download/v2.47.2/prometheus-2.47.2.linux-amd64.tar.gz
[root@prometheus ~]# tar xvfz prometheus-2.47.2.linux-amd64.tar.gz -C /usr/local/
[root@prometheus ~]# cd /usr/local/
[root@prometheus local]# mv prometheus-2.47.2.linux-amd64 prometheus
[root@prometheus local]# cd prometheus
[root@prometheus prometheus]# ls
console_libraries  consoles  data  LICENSE  NOTICE  prometheus  prometheus.yml  promtool

# 查看版本信息
[root@prometheus prometheus]# ./prometheus --version
prometheus, version 2.47.2 (branch: HEAD, revision: 3f3172cde1ee37f1c7b3a5f3d9b031190509b3ad)
  build user:       root@79f2ad339b75
  build date:       20231012-16:07:10
  go version:       go1.21.3
  platform:         linux/amd64
  tags:             netgo,builtinassets,stringlabels
# 查看帮助
[root@prometheus prometheus]# ./prometheus --help
prometheus, version 2.47.2 (branch: HEAD, revision: 3f3172cde1ee37f1c7b3a5f3d9b031190509b3ad)
  build user:       root@79f2ad339b75
  build date:       20231012-16:07:10
  go version:       go1.21.3
  platform:         linux/amd64
  tags:             netgo,builtinassets,stringlabels
  …………

prometheus.yml 配置文件解释

[root@prometheus prometheus]# cat prometheus.yml
# my global config
global:
  # 默认情况下,每15s拉取一次目标采样点数据。
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  # 每15秒评估一次规则。默认值为每1分钟。
  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:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # job名称会增加到拉取到的所有采样点上,同时还有一个instance目标服务的host:port标签也会增加到采样点上
  - job_name: 'prometheus'

    # 覆盖global的采样点,拉取时间间隔5s
    scrape_interval: 5s
    static_configs:
    - targets: ['localhost:9090']

 启动prometheus

[root@prometheus prometheus]# ./prometheus --config.file=prometheus.yml

可指定的启动参数

# 指定配置文件
--config.file="prometheus.yml"
# 默认指定监听地址端口,可修改端口
--web.listen-address="0.0.0.0:9090" 
# 最大连接数
--web.max-connections=512
# tsdb数据存储的目录,默认当前data/
--storage.tsdb.path="data/"
# premetheus 存储数据的时间,默认保存15天
--storage.tsdb.retention=15d 
# 通过命令热加载无需重启 curl -XPOST 192.168.2.45:9090/-/reload
--web.enable-lifecycle
# 可以启用 TLS 或 身份验证 的配置文件的路径
--web.config.file=""

启动选项了解:./prometheus --help

浏览器访问: http://192.168.58.152:9090/

浏览器访问: http://192.168.58.152:9090/metrics

将Prometheus配置为systemd管理

# 配置Prometheus启动文件
[root@prometheus ~]# vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=https://prometheus.io

[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.listen-address=:9090

[Install]                      
WantedBy=multi-user.target

# 重新加载system配置
[root@prometheus ~]# systemctl daemon-reload
[root@prometheus ~]# systemctl start prometheus
[root@prometheus ~]# ss -tlanp |grep 9090
LISTEN     0      1024      [::]:9090                  [::]:*                   users:(("prometheus",pid=9318,fd=7))

 客户端操作:

配置服务发现监控linux主机及相关服务

# 安装node_exporter
[root@node ~]# wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
[root@node ~]# tar -xr node_exporter-1.7.0.linux-amd64.tar.gz -C /usr/local/
[root@node ~]# cd /usr/local/
[root@node local]# mv node_exporter-1.7.0.linux-amd64/ node_exporter
[root@node local]# cd node_exporter/
[root@node node_exporter]# ls
LICENSE  node_exporter  NOTICE
[root@node node_exporter]# ./node_exporter &
	…………
ts=2023-11-16T09:52:04.979Z caller=tls_config.go:274 level=info msg="Listening on" address=[::]:9100
ts=2023-11-16T09:52:04.979Z caller=tls_config.go:277 level=info msg="TLS is disabled." http2=false address=[::]:9100

[root@node node_exporter]# ss -tlnp  | grep 9100
LISTEN     0      1024      [::]:9100                  [::]:*                   users:(("node_exporter",pid=8414,fd=3))

配置node_exporter为systemd管理

[root@node node_exporter]# vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
After=network.target 

[Service]
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure

[Install]
WantedBy=multi-user.target

[root@node node_exporter]# systemctl daemon-reload
[root@node node_exporter]# systemctl start node_exporter
[root@node node_exporter]# ss -tlnp  | grep 9100
LISTEN     0      1024      [::]:9100                  [::]:*                   users:(("node_exporter",pid=8675,fd=3))

服务端配置文件添加监控项:

普罗米修斯服务端配置文件添加监控项

[root@prometheus prometheus]# vim prometheus.yml 
……
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]
  
# 添加以下内容
  - job_name: "node_exporter"
    static_configs:
    # 如果有多个机器,用','分开
    - targets: ['192.168.58.142:9100']

# 重启prometheus服务
[root@prometheus prometheus]# systemctl restart prometheus

浏览器刷新查看

 监控mysql(mysqld-exporter):

客户端安装mysql:

# 安装mysqld-exporter
[root@node ~]# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.0/mysqld_exporter-0.15.0.linux-amd64.tar.gz
[root@node ~]# tar xf mysqld_exporter-0.15.0.linux-amd64.tar.gz -C /usr/local/
[root@node ~]# cd  /usr/local
[root@node local]# mv mysqld_exporter-0.15.0.linux-amd64 mysqld_exporter
[root@node local]# cd  mysqld_exporter
[root@node mysqld_exporter]# vim my.cnf
[client]
user=root
password=123456

# 启动mysqld-exporter
[root@node mysqld_exporter]# ./mysqld_exporter --config.my-cnf="/usr/local/mysqld_exporter/my.cnf" &
[root@node mysqld_exporter]# ps -ef |grep mysqld_exporter
root       3447   3398  0 01:31 pts/1    00:00:02 ./node_exporter
root       4647   3398  0 02:13 pts/1    00:00:00 ./mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/my.cnf

[root@node /usr/local/mysqld_exporter]# ss -lntp |grep 4647
LISTEN     0      128         :::9104                    :::*                   users:(("mysqld_exporter",pid=4647,fd=3))
# 启动后会监听9104端口

普罗米修斯服务端配置文件添加监控项

[root@prometheus prometheus]# vim prometheus.yml 
  - job_name: 'mysql'
    static_configs:
    - targets: ['192.168.58.142:9104']
[root@prometheus prometheus]# systemctl restart prometheus

使用Grafana展示Prometheus 数据

 下载并安装Grafana安装包

[root@prometheus ~]# wget https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/Packages/grafana-10.0.0-1.x86_64.rpm
[root@prometheus ~]# yum install initscripts fontconfig -y
[root@prometheus ~]# yum install -y grafana-10.0.0-1.x86_64.rpm
[root@prometheus ~]# systemctl status grafana-server.service 
[root@prometheus ~]# systemctl start grafana-server.service
[root@prometheus ~]# ss -tlnp |grep grafana |grep LISTEN
LISTEN     0      128       [::]:3000                  [::]:*                   users:(("grafana",pid=40768,fd=9))

浏览器访问:192.168.58.152:3000

用户名: admin     密码: admin

​​​​​​​登录成功之后添加数据源

填写prometheus的地址,然后点击最下面的save & test

  • dashboards查找地址:https://grafana.com/grafana/dashboards/

  • 例如:8919,12227;输入id: 然后点击Load

在仪表盘导入

 


http://www.kler.cn/a/149022.html

相关文章:

  • vscode下nuget包的本地引入方法
  • 将python下载的依赖包传到没网的服务器
  • 【Elasticsearch入门到落地】1、初识Elasticsearch
  • 物联网(RFID)全景:被装信息化监控应用与挑战
  • 5G 现网信令参数学习(3) - RrcSetup(1)
  • MySQL中的事务与锁
  • spring boot spring-retry重试机制
  • 算法 离散化
  • CVE-2022-4886 ingress命令注入复现与分析
  • 设计模式—依赖倒置原则(DIP)
  • Android frameworks 开发总结之十一
  • 郑州数字孪生技术推进制造业升级,工业物联网可视化应用加速
  • YOLO改进系列之SKNet注意力机制
  • GitHub 2023排名前十的最佳开源项目
  • 微信小程序+中草药分类+爬虫+torch
  • Linux命令(136)之zcat
  • 芯知识 | 混音播报语音芯片的优势:革新音频应用的新力量
  • 使用 Mybatis 的 TypeHandler 存取 Postgresql jsonb 类型
  • 【数学】旋转矩阵
  • xv6 磁盘中断流程和启动时调度流程
  • Java中实现精度准确的浮点数运算
  • SpringBoot——模板引擎及原理
  • RK3568平台开发系列讲解(Linux系统篇)通过OF函数获取设备树中断信息实验
  • 2023年国赛试题:配置inux1 为 CA 服务器
  • Linux dd命令详解:如何从标准输入或文件中读取、转换并输出数据(附实例教程和注意事项)
  • 7.5 Windows驱动开发:监控Register注册表回调