Linux部署Prometheus

本文详细介绍了如何在Linux上部署Prometheus,包括下载、解压、配置、启动、检查配置文件、设置为系统服务及开机启动,并强调了启用配置热加载的重要性,最后讲解了如何重载配置。
摘要由CSDN通过智能技术生成

下载

1、下载地址:https://prometheus.io/download/
2、根据实际版本进行下载,当前下载
在这里插入图片描述

部署

1、将安装包上传到服务器/data目录
2、解压
tar -zxvf prometheus-2.28.1.linux-amd64.tar.gz
在这里插入图片描述
3、修改目录
mv prometheus-2.28.1.linux-amd64 prometheus
在这里插入图片描述

检查配置文件

该步骤非必须,但修改prometheus.yml文件后都建议执行该操作进行检查
1、进入prometheus安装目录
2、检查./promtool check config prometheus.yml
在这里插入图片描述

启动

安装目录下启动./prometheus --config.file=prometheus.yml
在这里插入图片描述

访问prometheus

地址:http://ip:port/graph,其中默认端口9090
在这里插入图片描述

设置prometheus系统服务,并配置开机启动

创建prometheus.service文件

输入如下命令:
touch /usr/lib/systemd/system/prometheus.service
vim /usr/lib/systemd/system/prometheus.service

将以下配置内容写入prometheus.service

[Unit]
Description=Prometheus
After=network.target
[Service]
Type=simple
ExecStart=/data/prometheus/prometheus --config.file=/data/prometheus/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/data/prometheus/data --storage.tsdb.retention=60d
Restart=on-failure
[Install]
WantedBy=multi-user.target
在这里插入图片描述
参数说明:
–config.file – 指明prometheus的配置文件路径
–web.enable-lifecycle – 指明prometheus配置更改后可以进行热加载
–storage.tsdb.path – 指明监控数据存储路径
–storage.tsdb.retention --指明数据保留时间

设置开机启动

—重新加载服务配置文件
systemctl daemon-reload
—设置开机自启
systemctl enable prometheus.service
— 启动prometheus
systemctl start prometheus.service
—查看 prometheus状态
systemctl status prometheus.service
说明: prometheus在2.0之后默认的热加载配置没有开启, 配置修改后,需要重启prometheus server才能生效, 这对于生产环境的监控是不可容忍的,所以我们需要开启prometheus server的配置热加载功能。在启动prometheus时加上参数 web.enable-lifecycle , 可以启用配置的热加载, 配置修改后, 热加载配置。

重载prometheus配置

curl -X POST http://ip:9090/-/reload
比如,添加target后验证重载配置是否生效,则访问prometheus查看targets
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值