一、Prometheus安装部署
1.1 官网地址
https://prometheus.io/
1.2 下载相关应用
- prometheus
- pushgateway/node_exporter
- alertmanager
1.3 环境
hostname |
ipaddr |
用途 |
vms31 |
192.168.26.31 |
prometheus |
vms10 |
192.168.26.10 |
k8s-master |
vms11 |
192.168.26.11 |
k8s-node |
vms12 |
192.168.26.12 |
k8s-node |
1.4 上传相关应用到vms31
[root@vms31 ~]# cd /opt/
[root@vms31 opt]# rz -y
[root@vms31 opt]# ls
alertmanager-0.23.0.linux-amd64.tar.gz node_exporter-1.2.2.linux-amd64.tar.gz prometheus-2.30.3.linux-amd64.tar.gz pushgateway-1.4.2.linux-amd64.tar.gz
1.5 安装配置prometheus
[root@vms31 opt]# tar xf prometheus-2.30.3.linux-amd64.tar.gz
[root@vms31 opt]# cd prometheus-2.30.3.linux-amd64/
[root@vms31 prometheus-2.30.3.linux-amd64]# cp prometheus /usr/local/bin/
[root@vms31 prometheus-2.30.3.linux-amd64]# vim prometheus.yml
...
# 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: ["192.168.26.31:9090"]
# 使用pushgateway模块获取
- job_name: "pushgateway"
static_configs:
- targets: ["192.168.26.31:9091"]
labels:
instance: pushgateway
# 使用node exporter模块获取
- job_name: "node exporter"
static_configs:
- targets: ["192.168.26.31:9100","192.168.26.10:9100","192.168.26.11:9100","192.168.26.12:9100"]
1.6 安装pushgateway
[root@vms31 opt]# cd /opt/
[root@vms31 opt]# tar xf pushgateway-1.4.2.linux-amd64.tar.gz
1.7 安装AlertManager
[root@vms31 pushgateway-1.4.2.linux-amd64]# cd /opt/
[root@vms31 opt]# tar xf alertmanager-0.23.0.linux-amd64.tar.gz
1.8 安装node exporter
[root@vms31 opt]# cd /opt/
[root@vms31 opt]# tar xf node_exporter-1.2.2.linux-amd64.tar.gz
1.9 将node exporter拷贝到其它设备并设置开机启动
for ip in 192.168.26.10 192.168.26.11 192.168.26.12; do scp node_exporter $ip:/usr/local/sbin/;done
[root@vms31 system]# vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
After=network.target
[Service]
ExecStart=/usr/local/sbin/node_exporter
User=root
Type=simple
[Install]
WantedBy=multi-user.target
for ip in 192.168.26.10 192.168.26.11 192.168.26.12; do scp /usr/lib/systemd/system/node_exporter.service $ip:/usr/lib/systemd/system/node_exporter.service;done
systemctl enable --now node_exporter
1.10 启动Prometheus和pushgateway
[root@vms31 ~]# cd /opt/prometheus-2.30.3.linux-amd64/
[root@vms31 prometheus-2.30.3.linux-amd64]# ./prometheus --config.file=promeths.yml &> ./prometheus.log &
[root@vms31 prometheus-2.30.3.linux-amd64]# cd /opt/pushgateway-1.4.2.linux-amd64/
[root@vms31 pushgateway-1.4.2.linux-amd64]# ./pushgateway --web.listen-address=":9091" &> ./pushgateway.log &