设为首页 加入收藏

TOP

Prometheus安装部署(主体)
2023-07-23 13:40:50 】 浏览:20
Tags:Prometheus 安装部 主体

Prometheus安装部署

一,下载安装包并解压

下载地址:https://github.com/prometheus/prometheus/releases

因为服务器上下载速度太慢,所以可以提前在物理机上下载上传到服务器,本次安装使用的版本为:prometheus-2.37.5.linux-amd64

image-20230224163940244

1,根据服务器情况选择安装目录,上传安装包。

cd /prometheus
#解压
tar -xvzf prometheus-2.37.5.linux-amd64.tar.gz
mv prometheus-2.37.5.linux-amd64 prometheus
cd prometheus

image-20230224165437505

2,移动可执行程序,并查看版本,无误后开始下一步操作

cp prom* /usr/bin/
prometheus --version

image-20230224165646427

二,启动Prometheus,并进行相关配置

  • 常用启动参数可参考如下
–config.file="/data/prometheus/prometheus.yml" //指定配置文件路径
–web.enable-lifecycle //开启web热加载配置
–storage.tsdb.path= //指定tsdb数据库路径,默认在/data
–storage.tsdb.retention.time= //指定tsdb保留数据的时长,默认15d
  • 默认配置文件如下

image-20230224165858253

  • 指定默认配置文件并查看是否启动成功
prometheus --config.file="/prometheus/prometheus/prometheus.yml" --web.enable-lifecycle 

image-20230224170224368

三,启动无误,输入ctrl+c关闭服务,然后进行系统service编写

  • 创建 prometheus.service 配置文件
cd /usr/lib/systemd/system
vim prometheus.service
  • prometheus.service 文件填入如下内容后保存 :wq
[Unit]
Description=https://prometheus.io

[Service]
Restart=on-failure
ExecStart=/prometheus/prometheus/prometheus --config.file=/prometheus/prometheus/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/prometheus/prometheus/data

[Install]
WantedBy=multi-user.target
  • 因为服务默认启动用户为root,所以此处一定要注意,prometheus安装目录一定要有root的读写权限,如果没有,则需要执行:
chmod -R 777 /prometheus/
chown -R root /prometheus/
  • 否则服务启动时会报错

image-20230224171253593

  • 具体的错误信息可以通过下面的命令查看:
journalctl -u prometheus.service
  • 写好prometheus.service文件后,刷新服务配置并启动服务
systemctl daemon-reload
systemctl start prometheus.service
  • 查看是否启动成功,检查进程是否存在
systemctl status prometheus.service
ps -ef | grep prometheus

image-20230224171734219

image-20230224172534834

  • 设置开机自启动
systemctl enable prometheus.service

image-20230224172626532

四,访问系统

image-20230224173020556

  • 查看主机信息

image-20230224173257013

image-20230224173312937

  • 默认为localhost,我们将其改为正确的服务器ip地址
vim /prometheus/prometheus/prometheus.yml 

image-20230224173438956

  • 执行动态刷新API,post地址为服务器ip
curl -XPOST [your ip]:9090/-/reload
  • 稍等片刻刷新系统,就可以看到ip地址已经变更成功

    image-20230224173651426

  • 点击Endpoint地址,查看数据返回

    image-20230224173710250

后记

  • 以上流程走完没有遇到问题则说明Prometheus已经部署成功,后续就可以开始搭建监控系统了
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇vagrant搭建centos7 下一篇Linux-Nginx负载均衡与代理

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目