目录
- 1. 安装Prometheus Server
- 1.1 下载解压
- 1.2 修改配置文件prometheus.yml
- 1.3 启动Prometheus Server
- 2. 安装Pushgateway
- 2.1 下载解压
- 2.2 启动Pushgateway
- 3. 安装Node Exporter
- 3.1 下载解压
- 3.2 启动Node Exporter
- 4. 安装Alertmanager
- 4.1 下载解压
- 4.2 启动Alertmanager
1. 安装Prometheus Server
1.1 下载解压
[root@bigdata001 opt]# wget https://github.com/prometheus/prometheus/releases/download/v2.36.1/prometheus-2.36.1.linux-amd64.tar.gz
[root@bigdata001 opt]#
[root@bigdata001 opt]# tar -zxvf prometheus-2.36.1.linux-amd64.tar.gz
[root@bigdata001 opt]#
[root@bigdata001 opt]# cd prometheus-2.36.1.linux-amd64
[root@bigdata001 prometheus-2.36.1.linux-amd64]#
[root@bigdata001 prometheus-2.36.1.linux-amd64]# cat 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:
# - "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: ["localhost:9090"]
[root@bigdata001 prometheus-2.36.1.linux-amd64]#
1.2 修改配置文件prometheus.yml
修改scrape_configs配置项后的内容如下:
[root@bigdata001 prometheus-2.36.1.linux-amd64]# cat 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:
# - "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: ["bigdata001:9090"]
# 添加PushGateway监控配置
- job_name: 'pushgateway'
static_configs:
- targets: ['bigdata001:9091']
labels:
instance: pushgateway
# 添加Node Exporter监控配置
- job_name: 'node exporter'
static_configs:
- targets: ['bigdata002:9100', 'bigdata003:9100']
[root@bigdata001 prometheus-2.36.1.linux-amd64]#
Prometheus可以在运行时动态加载配置的。启动时需要添加:--web.enable-lifecycle
。配置说明:
-
global:控制Prometheus Server的全局配置
- scrape_interval:配置Retrieval拉取数据的时间间隔,默认为1分钟
- evaluation_interval:规则验证(生成 alert)的时间间隔,默认为1分钟
-
rule_files:规则配置文件
-
scrape_configs:配置采集目标相关。Prometheus可以通过HTTP(http://bigdata001:9090/metrics)采集自身的运行信息进行监控
- job_name:监控作业的名称
- static_configs:配置从某个target拉取数据
- targets:指定从哪儿拉取数据进行监控
1.3 启动Prometheus Server
[root@bigdata001 prometheus-2.36.1.linux-amd64]# nohup /opt/prometheus-2.36.1.linux-amd64/prometheus --config.file=/opt/prometheus-2.36.1.linux-amd64/prometheus.yml > /opt/prometheus-2.36.1.linux-amd64/prometheus.log 2>&1 &
[1] 30125
[root@bigdata001 prometheus-2.36.1.linux-amd64]#
启动时可以添加--web.listen-address="0.0.0.0:9090"
参数,修改Prometheus的端口
等启动Pushgateway、Node Exporter、AlertManager后,查看http://bigdata001:9090/targets,可以看到各个组件的状态都是正常的
2. 安装Pushgateway
对于监控生命周期较短的作业,需要PushGateway中转组件。通过配置生命周期较短的作业将metric推到PushGateway,Prometheus再从PushGateway拉取监控数据
2.1 下载解压
[root@bigdata001 opt]# wget https://github.com/prometheus/pushgateway/releases/download/v1.4.3/pushgateway-1.4.3.linux-amd64.tar.gz
[root@bigdata001 opt]#
[root@bigdata001 opt]# tar -zxvf pushgateway-1.4.3.linux-amd64.tar.gz
[root@bigdata001 opt]#
[root@bigdata001 opt]# cd pushgateway-1.4.3.linux-amd64
[root@bigdata001 pushgateway-1.4.3.linux-amd64]#
2.2 启动Pushgateway
[root@bigdata001 pushgateway-1.4.3.linux-amd64]# nohup /opt/pushgateway-1.4.3.linux-amd64/pushgateway --web.listen-address :9091 > /opt/pushgateway-1.4.3.linux-amd64/pushgateway.log 2>&1 &
[2] 30159
[root@bigdata001 pushgateway-1.4.3.linux-amd64]#
3. 安装Node Exporter
Exporter负责实际的监控样本数据收集。而Node Exporter可以对服务器的CPU、内存、磁盘等使用数据进行收集。Prometheus周期性的从Exporter暴露的HTTP服务地址/metrics拉取监控数据
分别在bigdata002和bigdata003两台服务器安装Node Exporter
3.1 下载解压
[root@bigdata002 opt]# wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
[root@bigdata002 opt]#
[root@bigdata002 opt]# tar -zxvf node_exporter-1.3.1.linux-amd64.tar.gz
[root@bigdata002 opt]#
[root@bigdata002 opt]# cd node_exporter-1.3.1.linux-amd64
[root@bigdata002 node_exporter-1.3.1.linux-amd64]#
3.2 启动Node Exporter
编写systemd服务管理文件node-exporter.service,内容如下:
[root@bigdata002 opt]# cat /etc/systemd/system/node-exporter.service
[Unit]
Description=node-exportor
Documentation=https://github.com/prometheus/node_exporter
After=network.service
[Service]
Type=simple
ExecStart=/opt/node_exporter-1.3.1.linux-amd64/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
[root@bigdata002 opt]#
然后启动node-exporter,并设置开机启动
[root@bigdata002 opt]# systemctl enable node-exporter --now
Created symlink from /etc/systemd/system/multi-user.target.wants/node-exporter.service to /etc/systemd/system/node-exporter.service.
[root@bigdata002 opt]#
访问http://bigdata002:9100/metrics,可以看到bigdata002上的node exporter获取
到的bigdata002服务器的所有监控数据
4. 安装Alertmanager
4.1 下载解压
[root@bigdata001 opt]# wget https://github.com/prometheus/alertmanager/releases/download/v0.24.0/alertmanager-0.24.0.linux-amd64.tar.gz
[root@bigdata001 opt]#
[root@bigdata001 opt]# tar -zxvf alertmanager-0.24.0.linux-amd64.tar.gz
[root@bigdata001 opt]#
[root@bigdata001 opt]# cd alertmanager-0.24.0.linux-amd64
[root@bigdata001 alertmanager-0.24.0.linux-amd64]#
4.2 启动Alertmanager
[root@bigdata001 alertmanager-0.24.0.linux-amd64]# nohup /opt/alertmanager-0.24.0.linux-amd64/alertmanager --config.file=/opt/alertmanager-0.24.0.linux-amd64/alertmanager.yml > /opt/alertmanager-0.24.0.linux-amd64/alertmanager.log 2>&1 &
[3] 30199
[root@bigdata001 alertmanager-0.24.0.linux-amd64]#