1.Prometheus 安装部署

1.官方网站下载对应版本包

下载地址:https://prometheus.io/download/

2.下载后上传到服务器上,进行解压

tar zxcf prometheus-2.22.0.linux-amd64.tar.gz

3.  ./prometheus -h 命令行常用参数:

  • --config.file="prometheus.yml"   #指定配置文件
  • --web.listen.address="0.0.0.0:9090"   #监听地址和端口
  • --log.level=info    #日志级别
  • --alertmanager.timeout=10s   #与报警组件的超时时间
  • --storage.tsdb.path="/data/"   #数据目录
  • --storage.tsdb.retention.time=15d   #数据保存时间,默认15天

4.启动:

./prometheus   直接不加任何参数即可启动。  启动后通过http://ip:9090 可访问界面,说明启动成功。

5.  通过docker启动:

docker run \

    -p 9090:9090

    -v $PWD/prometheus.yml:/etc/prometheus/prometheus.yml \

    prom/prometheus

6.配置Prometheus yaml文件:

vim /data/prometheus/prometheus.yml

# my global config
global:
scrape_interval: 30s # 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:
- 10.8****:9093
- static_configs:
- targets:
- 10.85******:9083
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
#- "first_rules.yml"
#- "second_rules.yml"
- /data/prometheus/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: 'cdp2-dev-aliyun-exporter'
scrape_timeout: 30s
static_configs:
- targets:
- 127.0.0.1:9525

- job_name: 'cdp2-dev-other-aliyun-exporter'
scrape_timeout: 30s
static_configs:
- targets:
- 127.0.0.1:9526
- job_name: 'cdp2-test-aliyun-exporter'
scrape_timeout: 30s
static_configs:
- targets:
- 127.0.0.1:9527

 

 

7.设置开机自动启动:

vim /etc/systemd/system/prometheus.service

[Unit]
Description=Prometheus Monitoring System
Documentation=Prometheus Monitoring System

[Service]
ExecStart=/data/prometheus/prometheus \
--config.file=/data/prometheus/prometheus.yml \
--storage.tsdb.retention.time=360d \
--web.listen-address=:9090

[Install]
WantedBy=multi-user.target

##########

systemctl enable prometheus 

systemctl start prometheus

 

posted @ 2021-10-25 15:47  DevOps-Annn  阅读(192)  评论(0)    收藏  举报