Prometheus 部署

文章详细介绍了如何在Linux上安装Prometheus2.39.1,包括下载安装包、解压、配置yaml文件、设置监控目标以及创建系统服务。此外,还提供了自定义服务脚本以实现启动、停止和重启Prometheus服务,并通过web界面查看监控状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Prometheus 安装

安装包下载

Prometheus 官网下载地址
包含Prometheus软件及各种exporter插件

Prometheus2.39.1.linux安装包

解压安装

tar -xvf  prometheus-2.39.1.linux-amd64.tar.gz

配置文件

vi prometheus.yml
# mglobal 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: ['localhost:9093']

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
    - "/monitor/prometheus-2.39.1.linux-amd64/alerts/*.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'
    static_configs:
      - targets: ['localhost:9100']

  - job_name: 'db-server-windows-sqlserver'
    static_configs:
      - targets: ['10.16.1.9:9182']

  - job_name: 'db-server-windows-oracle'
    static_configs:
      - targets: ['172.16.1.89:9182']

  - job_name: 'db-server-linux-oracle'
    static_configs:
      - targets: ['172.17.8.32:9100']





注册服务

可参考
linux 自定义服务

vi /etc/init.d/promethues
#!/bin/bash
#Create by:zhangyongze
#为什么不问问神奇的海螺呢丶
# chkconfig: 2345 55 25
# description: Prometheus-server
#

RETVAL=0
PROG="prometheus"
EXEC="/monitor/prometheus-2.39.1.linux-amd64/prometheus"
LOCKFILE="/var/lock/subsys/$PROG"
OPTIONS="--web.listen-address=:7746  --config.file=/monitor/prometheus-2.39.1.linux-amd64/prometheus.yml"

# Source function library.
if [ -f /etc/rc.d/init.d/functions ]; then
  . /etc/rc.d/init.d/functions
else
  echo "/etc/rc.d/init.d/functions does not exist"
  exit 0
fi

start() {
  if [ -f $LOCKFILE ]
  then
    echo "$PROG is already running!"
  else
    echo -n "Starting $PROG: "
    nohup $EXEC $OPTIONS >/dev/null 2>&1 &
    RETVAL=$?
    [ $RETVAL -eq 0 ] && touch $LOCKFILE && success || failure
    echo
    return $RETVAL
  fi
}

stop() {
  echo -n "Stopping $PROG: "
  killproc $EXEC
  RETVAL=$?
  [ $RETVAL -eq 0 ] && rm -r $LOCKFILE && success || failure
  echo
}

restart ()
{
  stop
  sleep 1
  start
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status $PROG
    ;;
  restart)
    restart
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
esac
exit $RETVAL




修改执行权限

chmod 775  /etc/init.d/promethues

设置chkconfig 管理服务
根据服务文件中 # chkconfig: 2345 55 25 设置启动级别

chkconfig  --add promethues

检查现有服务启动级别

chkconfig --list

运行Prometheus 服务

service prometheus  start  

web页面查看

浏览器访问 服务器地址+端口号(服务中配置的)

例如 http://192.168.1.21:7746/

在这里插入图片描述

targets 可查看所有监控中exporter

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

为什么不问问神奇的海螺呢丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值