一.prometheus
Prometheus 服务端负责数据的收集,因此我们应该首先安装并运行 Prometheus Server。
1、下载
2.解压
tar -zxf prometheus-2.34.0.linux-amd64
3.准备工作
cd prometheus-2.35.0.linux-amd64
cp prometheus promtool /usr/local/bin/ mkdir -p /etc/prometheus/ cp prometheus.yml /etc/prometheus/
4.查看版本
prometheus --version
prometheus.yml配置文件
prometheus.yml:
global:全局配置
scrape_interval:设置prometheus守护进程拉取agent信息时间间隔
evaluation_interval:设置根据后面rule_files字段定义的规则计算的时间间隔
alerting:告警配置
用于配置告警信息,需要通过alertmanagers插件实现,这里暂时未配置
rule_files:规则配置
主要用于触发告警,这里也暂未配置
scrape_configs:抓取目标机器配置
job_name:标识这条记录,也就是这个配置内的记录都会添加上该字段
targets:设置目标机地址
# my global config 全局配置
# scrape_interval:设置prometheus守护进程拉取agent信息时间间隔
# evaluation_interval:设置根据后面rule_files字段定义的规则计算的时间间隔
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 告警配置,用于配置告警信息,需要通过alertmanagers插件实现,这里暂时未配置
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: ["localhst:9090"]
- targets: ["localhost:9090"] # 默认是localhost,可以修改localhost为自己的本机IP
创建tsdb的数据库存储目录,载启动时指定tsdb存储目录
mkdir -p /data/prometheus_tsdb
5.添加系统服务
vim /etc/systemd/system/prometheus.service
将以下内容写入文件中
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/prometheus --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus_tsdb
Restart=on-failure
[Install]
WantedBy=multi-user.target
6.启动服务,设置开机自启,并检查服务开启状态
systemctl daemon-reload
systemctl enable prometheus
7.启动服务
systemctl start prometheus
8.检测服务状态
systemctl status prometheus
到这里就搭建基础的Prometheus的服务,通过访问http://yourip:9090访问Prometheus
grafana的安装配置