6.2.3.3章节启动docker容器并挂载配置文件,配置文件上一章节二进制部署正好有,可以直接使用
注意:⚠️ 若二进制章节部署后,需要执行systemctl stop prometheus.service关闭服务,否则会造成端口冲突,或者docker的端口映射改为 -p 9091:9090 也可
~~~shell
[root@JD prometheus]# docker run --name prometheus -d -p 9090:9090 -v /data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -v /data/prometheus/rules:/etc/prometheus/rules prom/prometheus --config.file=/etc/prometheus/prometheus.yml --web.enable-lifecycle
~~~
若没有操作过二进制部署,可以通过下面的文本手动创建配置文件 prometheus.yml
~~~yaml
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
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:
# 这里改为服务器ip以及分配的端口号
- targets: ['11x.xx.xx.7:9090']
~~~