Prometheus部署

2021-04-14 17:56:38 浏览数 (1)

一、环境准备

1、 防火墙配置

代码语言:txt复制
这里做了防火墙关闭,或者可以在防火墙开启9100、9093端口
[root@Prometheus ~]# systemctl stop firewall
[root@Prometheus ~]# systemctl disable firewalld

2、selinux配置

代码语言:txt复制
[root@Prometheus ~]# vim /etc/selinux/config
SELINUX=disabled
[root@Prometheus ~]# setenforce 0

3、更新yum

代码语言:txt复制
[root@Prometheus ~]# yum update

二、Prometheus部署

1、下载安装包

下载链接:https://prometheus.io/download/

2、包解压

代码语言:txt复制
tar xvfz prometheus-*.tar.gz

3、配置Prometheus监控

代码语言:txt复制
cd prometheus-*
[root@Prometheus prometheus-2.26.0.linux-amd64]# vi 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:
      - 172.16.1.x:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  - "rules/*_rules.yml"
  - "rules/*_alerts.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']
  - job_name: 'linux172.16.1.4x'
    static_configs:
    - targets: ['172.16.1.4x:9100']
      labels:
        instance: linux172.16.1.4x

4、部署node_exporter

下载地址:https://prometheus.io/download/

代码语言:txt复制
下载上传安装包:node_exporter-1.1.2.linux-amd64.tar.gz
[root@qxxx prometheus]# tar -xzvf node_exporter-1.1.2.linux-amd64.tar.gz
$ 配置node开机自启动
[root@qxxx node_exporter-1.1.2.linux-amd64]# sudo groupadd -r prometheus
[root@qxxx node_exporter-1.1.2.linux-amd64]# sudo useradd -r -g prometheus -s /sbin/nologin -M -c "prometheus Daemons" prometheus
[root@qxxx node_exporter-1.1.2.linux-amd64]# cat << EOF > /usr/lib/systemd/system/node_exporter.service
[Service]
User=prometheus
Group=prometheus
ExecStart=/opt/prometheus/node_exporter-1.1.2.linux-amd64/node_exporter

[Install]
WantedBy=multi-user.target

[Unit]
Description=node_exporter
After=network.target 
EOF
$ 启动,查看状态,配置开机启动
systemctl start node_exporter
systemctl status node_exporter
systemctl enable node_exporter

5、Master节点编辑“prometheus.yml”增加“node_exporter”IP

代码语言:txt复制
[root@Prometheus plugins]# vi prometheus.yml
  - job_name: 'linux172.16.1.4x'
    static_configs:
    - targets: ['172.16.1.4x:9100']
      labels:
        instance: 172.16.1.4x

6、热更新Prometheus.yml

代码语言:txt复制
curl -XPOST http://localhost:9090/-/reload

7、Web访问Prometheus地址:localhost:9090/targets

image.pngimage.png

0 人点赞