prometheus安装

1、下载安装包并解压到相关目录

#创建prometheus用户
useradd prometheus
cd /home/prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.26.0/prometheus-2.26.0.linux-amd64.tar.gz

tar -xf prometheus-2.26.0.linux-amd64.tar.gz -C /home/prometheus/
cd /home/prometheus
mv prometheus-2.26.0.linux-amd64 prometheus

2、使用systemd接管prometheus
–web.enable-lifecycle这个参数要配置上,可以使用curl直接重载配置文件而不用重启服务

重载配置两种方法
# 第一种,向prometheus进行发信号
kill -HUP  pid

# 第二种,向prometheus发送HTTP请求
# /-/reload只接收POST请求,并且需要在启动prometheus进程时,指定 --web.enable-lifecycle
curl -XPOST http://localhost:9090/-/reload
cat <<EOF > /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Type=simple
ExecStart=/home/prometheus/prometheus/prometheus \
    --config.file=/home/prometheus/prometheus/prometheus.yml \
    --web.enable-lifecycle
#    --storage.tsdb.path /var/lib/prometheus/ \
#    --web.console.templates=/etc/prometheus/consoles \
#    --web.console.libraries=/etc/prometheus/console_libraries \
#    --web.listen-address=:9090
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

prometheus.yml

cat <<EOF > /home/prometheus/prometheus/prometheus.yml
# my global config
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
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: ['localhost:9090']
 
  - job_name: "gitlab-runner"
    static_configs:
    - targets: ['172.16.14.127:9100']
EOF
systemctl start prometheus
netstat -tunlp|grep 9090

访问
http://ip:9090/

按照上面的步骤会遇到的问题
使用prometheus用户的service时,启动时会报错
jenkins prometheus: level=error ts=2021-11-01T12:15:36.698Z caller=query_logger.go:87 component=activeQueryTracker msg=“Error opening query log file” file=data/queries.active err=“open data/queries.active: permission denied”

在这里插入图片描述
原因是prometheus启动时,会创建/data目录,但是启动时用的是prometheus用户,权限不够,方法,先用root用户创建/data目录,再使用chown prometheus:prometheus /data即可
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值