Server-prometheus
安装
普罗米修斯的安装分为两部分、1. 服务端 2.客户端 3.添加监控项
服务端安装
-
下载prometheus服务端软件
普罗米修斯下载网址:https://prometheus.io/download/
-
下载完成后解压、改名文件夹、移动文件夹到
/usr/local/tar zxvf prometheus-2.25.0.linux-amd64.tar.gz mv prometheus-2.25.0.linux-amd64/ prometheus mv prometheus /usr/local -
配置 prometheus.yml 配置文件
# my global config global: # 默认情况下,每15s拉取一次目标采样点数据。 scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. # 每15秒评估一次规则。默认值为每1分钟。 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: # - 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: # job名称会增加到拉取到的所有采样点上,同时还有一个instance目标服务的host:port标签也会增加到采样点上 - job_name: 'prometheus' # 覆盖global的采样点,拉取时间间隔5s scrape_interval: 5s static_configs: - targets: ['localhost:9090'] -
将prometheus配置为系统服务
-
进入 /usr/lib/systemd/system 目录
-
创建
prometheus.service配置文件[Unit] Description=https://prometheus.io [Service] Restart=on-failure ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.listen-address=:9090 [Install] WantedBy=multi-user.target -
生效配置文件
systemctl daemon-reload
-
-
启动prometheus服务
systemctl restart prometheus.serviceprometheus服务会占用9090端口,注意端口使用情况
客户端安装
这里以监控linux为例,监控Linux 安装常用node_exporter
-
下载客户端软件
-
下载完成后解压、改名文件夹、移动文件夹到
/usr/local/tar zxvf node_exporter-1.1.2.linux-amd64.tar.gz mv node_exporter-1.1.2.linux-amd64/ node_exporter mv node_exporter /usr/local -
将node_exporter配置为系统服务
-
进入 /usr/lib/systemd/system 目录
-
创建
node_exporter.service配置文件[Unit] Description=node_exporter After=network.target [Service] ExecStart=/usr/local/node_exporter/node_exporter Restart=on-failure [Install] WantedBy=multi-user.target
-
-
启动node_exporter服务
systemctl restart node_exporter.servicenode_exporter服务会占用9100端口,注意端口使用情况
添加监控项
修改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).
## Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
## Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['192.168.2.45:9090']
- job_name: 'linux'
static_configs:
- targets: ['192.168.2.44:9100','192.168.2.43:9100'] # 多个用,分开
## 添加上面三行