1.拉取镜像
docker pull prom/prometheus
2.创建配置文件
cd /root/prometheus
touch prometheus.yml
touch first_rules.yml
3.配置文件内容
- 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).
remote_write: # 使用远程存储,VictoriaMetrics时序数据库- url: http://xxx.xxx.xx.xxx:8480/insert/0/prometheusremote_read: # 使用远程读取,VictoriaMetrics时序数据库- url: http://xxx.xxx.xx.xxx:8481/select/0/prometheus# Alertmanager configuration
alerting:alertmanagers:- static_configs:- targets: # 告警push到alertmanager集群- xxx.xxx.xx.xxx:9093- xxx.xxx.xx.xxx:9093# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:- "/etc/prometheus/rules/first_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"]
- first_rule.yml配置文件内容
groups:
- name: default_grouprules:- alert: sqlserver-defaultannotations:description: sqlserver-exporter............summary: sqlserver-exporter............expr: up{job="sqlserver-exporter"}<1for: 1mlabels:namespace: amcprom_id: "3"severity: emergency
4.prometheus容器启动
docker run -d --name=prometheus --restart=always -p 9090:9090 \
-v /root/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
-v /root/prometheus/first_rules.yml:/etc/prometheus/rules/first_rules.yml \
prom/prometheus --config.file=/etc/prometheus/prometheus.yml --web.enable-lifecycle
- 挂载prometheus.yml到/etc/prometheus/prometheus.yml
- 挂载first_rules.yml到/etc/prometheus/prometheus.yml
- –config.file=/etc/prometheus/prometheus.yml指定配置文件(不指定热加载配置项有问题)
- –web.enable-lifecycle热加载
5.注意点
容器部署的prometheus在执行热加载的时候没有生效,二进制部署就不会出现。