Prometheus监控部署

 

版本:v2.35.0

 

 

官方文档:https://prometheus.io/docs/

下载地址:https://prometheus.io/download/

参考来源:http://dockone.io/article/2434457

 

一、Prometheus是什么?

监控:数据采集,数据存储,数据分析,数据展示,数据告警。

Prometheus本质上是一个度量数据的收集和分析工具,包含3个核心组件:

● 时间序列数据库,用于保存所有度量数据。

● 数据收集器,负责从外部来源拉取指标并将其推入数据库。

● Web服务器,为配置和查询存储的数据提供简单的Web界面。

 

二、Prometheus的优势:

配置灵活;

监控多样性;

高效的存储;

 

三、Prometheus的架构:

 

  说明:

PromSQL,是用于从Prometheus中检索指标的查询语言。

AlertManager(告警管理),允许我们根据Prometheus采样的指标定义告警(比如内存/ CPU使用率过高或请求时延达到峰值)。

Pushgateway(推送网关),允许应用和服务将指标推送到Prometheus,而非标准的由Prometheus主动拉取。

Service discocery(服务发现),Prometheus在一开始就被设计为只需极少配置即可完成初始安装,以及适于在诸如Kubernetes之类的动态环境中运行。因此它可以对正在运行的服务进行自动发现,并尝试对其应监视的内容作出最佳的猜测。

 

四、prometheus安装

https://prometheus.io/download/下载相应版本,官网提供的是二进制版,解压就能用,不需要编译。

上传prometheus包,并解压

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

mv prometheus-2.35.0.linux-amd64 /usr/local/prometheus

cd /usr/local/prometheus/

#启动

./prometheus &

 

#查看相关进程及端口

ps -ef |grep prometheus

ss -anltp |grep 9090

netstat -nltp |grep prometheus

浏览器访问验证Prometheus,直接输入服务器IP:9090即可。

 

 >>>prometheus部署非常简单,无需做任何配置即可轻松部署。

查看监控目标,Status-->Targets,默认只监控本机。

 

五、监控远程主机

监控远程主机需要下载并安装node_exporter组件服务,安装也特别简单,将node_exporter组件安装包上传至要被监控的服务器上,解压后里面就一个启动程序node_exporter,可以直接启动,node_exporter默认端口9100。

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

cd /usr/local/

mv node_exporter-1.3.1.linux-amd64/  node_exporter

nohup /usr/local/node_exporter/node_exporter &

#查看进程及端口

ps -ef |grep node_exporter

netstat -nltp |grep 9100

 

 通过浏览器访问 http://被监控端IP:9100/metrics 就可以查看到 node_exporter在被监控端收集的监控信息。

 

回到Prometheus服务器的配置文件里添加被监控机器的配置段。在主配置文件最后加上下面三行。

vim /usr/local/prometheus/prometheus.yml

 

- job_name: 'node1'       # 取一个job名称来代表被监控的机器

static_configs:

- targets: ['10.226.1.2:9100']       # 这里改成被监控机器的IP,后面端口接9100

 

 

 改完配置文件并保存后,重启prometheus服务。

ps -ef |grep prometheus

kill -9 <进程ID>

nohup /usr/local/prometheus/prometheus &

#启动方式还可以追加指定默认配置文件

/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &

 

回到prometheus Web管理界面 --》点Status --》点Targets --》可以看到多了一台监 控目标。

 

 

---

 

posted @   i潘小潘  阅读(263)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示