Prometheus学习路程(1)- 基础安装篇

官方文档:Overview | Prometheus

一.prometheus

Prometheus 服务端负责数据的收集,因此我们应该首先安装并运行 Prometheus Server。

1、下载

https://github.com/prometheus/prometheus/releases/download/v2.35.0/prometheus-2.35.0.linux-amd64.tar.gz

2.解压

tar -zxf prometheus-2.34.0.linux-amd64

3.准备工作

cd prometheus-2.35.0.linux-amd64

cp prometheus promtool /usr/local/bin/ mkdir -p /etc/prometheus/ cp prometheus.yml /etc/prometheus/

4.查看版本

prometheus --version

prometheus.yml配置文件

prometheus.yml:

global:全局配置

scrape_interval:设置prometheus守护进程拉取agent信息时间间隔

evaluation_interval:设置根据后面rule_files字段定义的规则计算的时间间隔

alerting:告警配置

用于配置告警信息,需要通过alertmanagers插件实现,这里暂时未配置

rule_files:规则配置

主要用于触发告警,这里也暂未配置

scrape_configs:抓取目标机器配置

job_name:标识这条记录,也就是这个配置内的记录都会添加上该字段

targets:设置目标机地址

# my global config 全局配置
# scrape_interval:设置prometheus守护进程拉取agent信息时间间隔
# evaluation_interval:设置根据后面rule_files字段定义的规则计算的时间间隔
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  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 告警配置,用于配置告警信息,需要通过alertmanagers插件实现,这里暂时未配置
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:
  # 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: ["localhst:9090"]
      - targets: ["localhost:9090"]  # 默认是localhost,可以修改localhost为自己的本机IP

创建tsdb的数据库存储目录,载启动时指定tsdb存储目录

mkdir -p /data/prometheus_tsdb

5.添加系统服务

vim /etc/systemd/system/prometheus.service

将以下内容写入文件中

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/prometheus --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus_tsdb
Restart=on-failure
[Install]
WantedBy=multi-user.target

6.启动服务,设置开机自启,并检查服务开启状态

systemctl daemon-reload

systemctl enable prometheus

7.启动服务

systemctl start prometheus

8.检测服务状态

systemctl status prometheus

到这里就搭建基础的Prometheus的服务,通过访问http://yourip:9090访问Prometheus

grafana的安装配置

参考:https://www.cnblogs.com/sanduzxcvbnm/p/13606261.html

参考文章:https://www.cnblogs.com/shuai666/p/15905562.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值