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@79f2ad339b75build date:       20231012-16:07:10go version:       go1.21.3platform:         linux/amd64tags:             netgo,builtinassets,stringlabels
# 查看帮助
[root@prometheus prometheus]# ./prometheus --help
prometheus, version 2.47.2 (branch: HEAD, revision: 3f3172cde1ee37f1c7b3a5f3d9b031190509b3ad)build user:       root@79f2ad339b75build date:       20231012-16:07:10go version:       go1.21.3platform:         linux/amd64tags:             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的采样点,拉取时间间隔5sscrape_interval: 5sstatic_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.hqwc.cn/news/228641.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Baby-Step Giant-Step Homomorphic DFT

参考文献&#xff1a; [CT65] Cooley J W, Tukey J W. An algorithm for the machine calculation of complex Fourier series[J]. Mathematics of computation, 1965, 19(90): 297-301.[Shoup95] Shoup V. A new polynomial factorization algorithm and its implementation[…

【数据结构 —— 二叉树的链式结构实现】

数据结构 —— 二叉树的链式结构实现 1.树的概念及其结构1.1.树概念1.2.树的结构1.3树的相关概念1.4.树的表示1.5. 树在实际中的运用&#xff08;表示文件系统的目录树结构&#xff09; 2.二叉树的概念及其结构2.1二叉树的概念2.2.现实中的二叉树&#xff1a;2.3. 特殊的二叉树…

国产操作系统-银河麒麟V10

一、介绍 银河麒麟操作系统隶属于麒麟软件&#xff0c;麒麟软件是专业从事国产操作系统研发和产业化的企业&#xff0c;面向通用和专用领域打造安全创新的国产操作系统产品和相应解决方案&#xff0c;旗下拥有银河麒麟、中标麒麟、星光麒麟三大产品品牌。 麒麟软件官方网站地…

Shell条件变量练习

1.算数运算命令有哪几种&#xff1f; (1) "(( ))"用于整数运算的常用运算符&#xff0c;效率很高 [rootshell scripts]# echo $((24*5**2/8)) #(( ))2452814 14 (2) "$[ ] "用于整数运算 [rootshell scripts]# echo $[24*5**2/8] #[ ]也可以运…

Windows10系统卸载服务和删除服务

记录一下Windows10系统卸载服务和删除服务 最近在使用自己win电脑的时候 发现服务里存在很久之前就没有使用的应用&#xff0c;对应的文件夹也都已经删除了&#xff0c;但是在win服务里一直存在&#xff0c;不知道会不会影响性能&#xff0c;看着吧还是强迫自己删掉好一些&…

解决:SyntaxError: Non-UTF-8 code starting with À in file but no encoding declared

解决&#xff1a;SyntaxError: Non-UTF-8 code starting with in file but no encoding declared 文章目录 解决&#xff1a;SyntaxError: Non-UTF-8 code starting with in file but no encoding declared背景报错问题报错翻译报错原因解决方法使用utf-8格式使用gbk格式今天…

Linux新加磁盘的完整步骤

目录 新加磁盘的完整步骤磁盘分区磁盘文件命名经典分区方案fdiskparted 分区格式化挂载分区 新加磁盘的完整步骤 物理连接 --> 分区 --> 格式化 --> 挂载 --> 更新/etc/fstab文件实现永久挂载 磁盘分区 主分区primary用来安装操作系统、存放数据&#xff0c;可以…

【攻防世界-misc】hong

1.下载解压文件&#xff0c;是个音频文件&#xff0c;但打不开 2.复制到kali中先拆分看音频里面有隐含文件没有 用到的命令是&#xff1a;foremost 桌面/hong.mp3 点击桌面上的主文件夹 点击“output”文件夹&#xff0c; 点击文件中的jpg文件夹&#xff0c;有两张图片&#…

【古月居《ros入门21讲》学习笔记】14_参数的使用与编程方法

目录 说明&#xff1a; 1. 参数模型&#xff08;全局字典&#xff09; 2. 实现过程&#xff08;C&#xff09; 创建功能包 参数命令行的使用 YAML参数文件 rosparam命令 使用示例 编程方法&#xff08;C&#xff09; 配置代码编译规则 编译并运行 编译 运行 3. 实…

uni-app x生成的安卓包,安装时,提示不兼容。解决方案

找到 manifest.json 进入&#xff1a;源码视图 代码 {"name" : "xxx康养","appid" : "__xxx6","description" : "xxx康养","versionName" : "1.0.12","versionCode" : 100012,&…

【CAD二次开发】标注箭头,获取修改标注箭头图块

常见的的标注箭头有以下种类 public static List<string> ArrowBlock = new List<string>(){" ","_CLOSEDBLANK&

ABAP算法 模拟退火

模拟退火算法 算法原理及概念本文仅结合实现过程做简述 模拟退火算法是一种解决优化问题的算法。通过模拟固体退火过程中的原子热运动来寻找全局最优解。在求解复杂问题时&#xff0c;模拟退火算法可以跳出局部最优解获取全局最优解。 模拟退火算法包含退火过程和Metropolis算法…