Prometheus系列————Linux系统安装,配置后台启动方式

Prometheus简介

Prometheus是最初在SoundCloud上构建的开源系统监视和警报工具包。 自2012年成立以来,许多公司和组织都采用了Prometheus,该项目拥有非常活跃的开发人员和用户社区。它是一个独立的开源项目,并且独立于任何公司进行维护。 为了强调这一点并阐明项目的治理结构,Prometheus在2016年加入了Cloud Native Computing Foundation,这是继Kubernetes之后的第二个托管项目。

Prometheus架构

在这里插入图片描述
Prometheus服务,可以直接通过目标拉取数据,或者间接地通过中间网关拉取数据。它在本地存储抓取的所有数据,并对这些数据运行规则,以汇总和记录现有数据中的新时间序列,或生成警报。 Grafana或其他API使用者可用于可视化收集的数据。

组件

  • 服务器抓取并存储时间序列数据客户端库以检测应用程序代码
  • 一个支持短暂工作的推送网关
  • 支持以下HAProxy,StatsD,Graphite等服务接口
  • 告警

大多数Prometheus组件都是用Go编写的,因此易于构建和部署为静态二进制文件。

场景

适用场景
Prometheus非常适合记录任何纯数字时间序列。它既适用于面向服务器等硬件指标的监控,也适合于高度动态的面向服务的体系结构的监视。 在微服务世界中,它对多维数据收集和查询的支持是一种特别的优势。

Prometheus的设计旨在提高可靠性,使其成为中断期间要使用的系统,以使您能够快速诊断问题。 每个Prometheus服务器都是独立的,而不依赖于网络存储或其他远程服务。 当服务出现故障时,它可以使你快速定位和诊断问题。它的搭建过程对硬件和服务没有很强的依赖关系

不适用场景
Prometheus,主要在于可靠性,在很恶劣的环境下,都可以随时访问它和查看系统服务各种指标的统计信息。 如果你对统计数据需要100%的精确,它并不适用,例如:实时计费系统

安装方式(Linux)

官网获取下载链接地址:https://prometheus.io/download/

1、创建安装目录
[root@localhost ~]# mkdir -p /appdata/prometheus

切换目录

[root@localhost ~]# cd /appdata/prometheus
2、获取安装包
[root@localhost prometheus]# wget https://github.com/prometheus/prometheus/releases/download/v2.17.1/prometheus-2.17.1.linux-amd64.tar.gz

如果下载慢,可以选择国内镜像

[root@localhost prometheus]# wget https://mirrors.tuna.tsinghua.edu.cn/github-release/prometheus/prometheus/2.17.1%20_%202020-03-26/prometheus-2.17.1.linux-amd64.tar.gz
3、解压
[root@localhost prometheus]# tar -xvfz prometheus*.gz
4、运行

切换目录

[root@localhost prometheus]# cd prometheus-*

默认的端口号是9090,因此要开放9090端口号

[root@localhost prometheus]# sudo firewall-cmd --add-port=9090/tcp --permanent

重载防火墙

 [root@localhost prometheus]# sudo firewall-cmd --reload

运行,指定配置文件

[root@localhost prometheus-2.17.1.linux-amd64]# ./prometheus --config.file=prometheus.yml

在网页输入地址:
服务器ip:9090
在这里插入图片描述
出现以下网页,可以输入以下指令:

rate(promhttp_metric_handler_requests_total{code="200"}[1m])

在这里插入图片描述

5、后台启动方式

创建日志文件

[root@localhost prometheus-2.17.1.linux-amd64]#  mkdir -p /applog/prometheus && touch  /applog/prometheus/prometheus.log

方式 一

[root@localhost prometheus-2.17.1.linux-amd64]# nohup ./prometheus --config.file=prometheus.yml --web.enable-lifecycle > /applog/prometheus/prometheus.log 2>&1 &

方式二 (systemctl 启动方式)

启动脚本

[root@localhost prometheus-2.17.1.linux-amd64]# vi /appdata/prometheus/prometheus-2.17.1.linux-amd64/prometheus.sh

添加以下内容:

#!/bin/bash
/appdata/prometheus/prometheus-2.17.1.linux-amd64/prometheus --web.enable-lifecycle --config.file=/appdata/prometheus/prometheus-2.17.1.linux-amd64/prometheus.yml &>> /applog/prometheus/prometheus.log

授权脚本

[root@localhost prometheus-2.17.1.linux-amd64]# chmod 755 prometheus.sh

新增prometheus.service

[root@localhost prometheus-2.17.1.linux-amd64]# vi /usr/lib/systemd/system/prometheus.service

添加以下内容:

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
# 启动脚本
ExecStart=/appdata/prometheus/prometheus-2.17.1.linux-amd64/prometheus.sh

[Install]
WantedBy=multi-user.target

验证启动

[root@localhost prometheus-2.17.1.linux-amd64]# systemctl daemon-reload

配置开机加载

[root@localhost prometheus-2.17.1.linux-amd64]#  systemctl enable prometheus.service  

启动普罗米修斯

[root@localhost prometheus-2.17.1.linux-amd64]#  systemctl start prometheus.service  

查看是启动状态

[root@localhost prometheus-2.17.1.linux-amd64]#  systemctl status prometheus         

6、启动端口号修改

启动参数新增,如果配置了脚本,在脚本中添加–web.listen-address=:8091 (你要修改成的端口号)改参数即可

[root@localhost prometheus-2.17.1.linux-amd64]# prometheus --config.file=prometheus.yml --web.listen-address=:8091

7、重载配置模式

需配置参数 –web.enable-lifecycle ,上面后台脚本已经添加

[root@localhost prometheus-2.17.1.linux-amd64]# curl -X POST http://127.0.0.1:9090/-/reload
  • 7
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值