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.mfbz.cn/a/199759.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Ubuntu:安装Powershell

Powershell的安装与使用&#xff1a; 1&#xff09;安装Powershell&#xff1a;在终端依次运行以下命令即可&#xff1a; $ sudo apt-get update $ sudo apt-get install -y wget apt-transport-https software-properties-common $ wget -q "https://packages.microsof…

基于ArcGIS Pro、R、INVEST等多技术融合下生态系统服务权衡与协同动态分析实践应用

生态系统服务是指生态系统所形成的用于维持人类赖以生存和发展的自然环境条件与效用&#xff0c;是人类直接或间接从生态系统中得到的各种惠益。联合国千年生态系统评估&#xff08;Millennium ecosystem assessment&#xff0c;MA&#xff09;提出生态系统服务包括供给、调节、…

【Vue】绝了!还有不懂生命周期的?

生命周期 Vue.js 组件生命周期&#xff1a; 生命周期函数&#xff08;钩子&#xff09;就是给我们提供了一些特定的时刻&#xff0c;让我们可以在这个周期段内加入自己的代码&#xff0c;做一些需要的事情; 生命周期钩子中的this指向是VM 或 组件实例对象 在JS 中&#xff0c;…

分层理解Java字符串常量池

Java是一门计算机编程语言&#xff0c;但我们脑海中所理解的Java不仅仅是一门语言。它还包括Java虚拟机&#xff08;JVM&#xff09;的一系列规定&#xff0c;及具体Java产品&#xff08;如Hotspot&#xff09;的实现原理。 不管我们日常在Java中用到的任何一种语法&#xff0…

Ubuntu Linux玩童年小霸王插卡游戏

1.下载安装模拟器 在Windows平台模拟器非常多&#xff0c;而且效果也很优秀&#xff0c;Linux平台的用户常常很羡慕&#xff0c;却因为系统的缘故&#xff0c;无法使用这样的模拟器&#xff0c;但是随着时代的发展&#xff0c;Linux平台也出现了许多优秀的模拟器&#xff0c;现…

选择更灵活的设计工具:SOLIDWORKS 软件网络版与单机版的比较

随着科技的飞速发展&#xff0c;工程设计领域对于高效、灵活的设计工具需求日益增加。SOLIDWORKS 作为一款广受欢迎的三维设计软件&#xff0c;提供了网络版和单机版两种选择。在本文中&#xff0c;我们将深入探讨这两个版本的区别&#xff0c;并为您详细介绍它们的价格差异。 …

基于单片机的烟雾检测报警装置(论文+源码)

1.系统设计 &#xff08;1&#xff09;利用传感器实现环境中温度、烟雾浓度的实时检测&#xff1b; &#xff08;2&#xff09;系统检测的各项数据信息通过液晶模块进行显示&#xff0c;提高设计可视化&#xff1b; &#xff08;3&#xff09;系统可以根据实际情况利用按键模…

20天GMV超过百万美金!桌下迷你跑步机在TikTok Shop美国站热销

上周总GMV达到1.59亿美元&#xff0c;达到历史新高&#xff0c;是美国站自开通以来首次单周出单达到亿级&#xff1b;日均出单1660万美元&#xff0c;单日出单最高达2820万美元&#xff1b; 截至11月19日&#xff0c;GMV Top 5 的商品分类排名依次为&#xff1a;美妆个护、女士…

《深入理解计算机系统》学习笔记 - 第三课 - 位,字节和整型

Lecture 03 Bits,Bytes, and Integer count 位&#xff0c;字节&#xff0c;整型 文章目录 Lecture 03 Bits,Bytes, and Integer count 位&#xff0c;字节&#xff0c;整型运算&#xff1a;加&#xff0c;减&#xff0c;乘&#xff0c;除加法乘法取值范围乘法结果 使用无符号注…

交流负载的功能实现原理

交流负载的功能实现原理主要涉及到电力电子技术、电机控制技术和电力系统保护技术等多个方面。 交流负载的功能实现需要通过电力电子器件进行电能的转换和控制&#xff0c;电力电子器件主要包括开关器件和电力电子变压器等。开关器件主要用于实现电能的通断控制&#xff0c;如晶…

消息队列进阶-1.消息队列的应用场景与选型

&#x1f44f;作者简介&#xff1a;大家好&#xff0c;我是爱吃芝士的土豆倪&#xff0c;24届校招生Java选手&#xff0c;很高兴认识大家&#x1f4d5;系列专栏&#xff1a;Spring源码、JUC源码、Kafka原理&#x1f525;如果感觉博主的文章还不错的话&#xff0c;请&#x1f44…

vue el-table表格中每行上传文件(上传简历)操作

1、HTML中 <el-table :data"formInfo.userListDto" border stripe max-height"400"><el-table-column type"index" label"序号" width"50"> </el-table-column><el-table-column prop"realName&q…

【Udemy】AWS CLF - 01 题库 (英文版 + 中文版)目录

【挑战业余一周拿证】CSDN官方课程目录 【挑战业余一周拿证】AWS 认证云从业者 薅200美金羊毛 一、介绍 文章记录题库&#xff08;包含答案解释中文翻译&#xff09; 共计23章&#xff0c;每天更新 2-10 章习题&#xff0c;需要的客观请点赞收藏 来源Udemy&#xff0c;刷题…

Docker容器常用命令

文章目录 启动类命令帮助类命令镜像命令列出本地主机上的镜像在远程仓库中搜索镜像下载镜像保存镜像加载 tar 包为镜像查看占据的空间删除镜像 虚悬镜像命令自动补全新建启动容器启动交互式容器启动守护式容器 列出正在运行的容器容器其他启停操作启动已经停止的容器重启容器停…

【jupyter notebook中插件 nbextensions 安装失败分析与解决方法】

文章目录 问题描述分析与解决总结 问题描述 一开始在安装 notebook 中的插件 nbextensions 时根本没有注意到版本的适配问题&#xff0c;都是进行默认的安装&#xff0c;结果安装是最新版本的 notebook7.x&#xff0c;恰好 notebook7.x 版本不再适应插件 nbextensions&#xf…

智能优化算法应用:基于头脑风暴算法无线传感器网络(WSN)覆盖优化 - 附代码

智能优化算法应用&#xff1a;基于头脑风暴算法无线传感器网络(WSN)覆盖优化 - 附代码 文章目录 智能优化算法应用&#xff1a;基于头脑风暴算法无线传感器网络(WSN)覆盖优化 - 附代码1.无线传感网络节点模型2.覆盖数学模型及分析3.头脑风暴算法4.实验参数设定5.算法结果6.参考…

大数据平台/大数据技术与原理-实验报告--部署ZooKeeper集群和实战ZooKeeper

实验名称 部署ZooKeeper集群和实战ZooKeeper 实验性质 &#xff08;必修、选修&#xff09; 必修 实验类型&#xff08;验证、设计、创新、综合&#xff09; 综合 实验课时 2 实验日期 2023.11.04-2023.11.05 实验仪器设备以及实验软硬件要求 专业实验室&#xff08…

leetcode:用栈实现队列(先进先出)

题目描述 题目链接&#xff1a;232. 用栈实现队列 - 力扣&#xff08;LeetCode&#xff09; 题目分析 我们先把之前写的数组栈的实现代码搬过来 用栈实现队列最主要的是实现队列先进先出的特点&#xff0c;而栈的特点是后进先出&#xff0c;那么我们可以用两个栈来实现&…

flask 上传文件

from flask import Flask, request, render_template,redirect, url_for from werkzeug.utils import secure_filename import os from flask import send_from_directory # send_from_directory可以从目录加载文件app Flask(__name__)#UPLOAD_FOLDER media # 注意&#xff…

大数据——一文详解数据仓库概念(数据仓库的分层概念和维度建模详解)

1、ods是什么&#xff1f; ods层最好理解&#xff0c;基本上就是数据从源表拉过来&#xff0c;进行etl&#xff0c;比如MySQL映射到Hive&#xff0c;那么到了Hive里面就是ods层。ods全称是 Operational Data Store&#xff0c;操作数据存储——“面向主题的”&#xff0c;数据…