云原生

Prometheus架构从入门到实践(4) --promethe

2021-12-05  本文已影响0人  負笈在线


1.安装组件一览

prometheus       监视server                port:9090

node_exporter   linux node exporter   port:9100

wmi_exporter     Win node exporter    port:9182

Grafana              监视展示                   port:3000

Alertmanager     监视告警                    port:9093

2.prometheus install

官网地址

      https://prometheus.io/docs/introduction/overview/

安装包取得

      # wget https://github.com/prometheus/prometheus/releases/download/v2.25.0/prometheus-2.25.0.linux-amd64.tar.gz

环境调整

      # tar -zxvf prometheus-2.25.0.linux-amd64.tar.gz

      # cp -p /etc/profile /etc/profile.`date +%Y%m%d`

      # vi /etc/profile

PATH=$PATH

PATH=$PATH:/root/prometheus-2.25.0.linux-amd64

export PATH

      # prometheus

配置文件设置

      # cp -p  /root/prometheus-2.25.0.linux-amd64/prometheus.yml /root/prometheus-2.25.0.linux-amd64/prometheus.yml.`date +%Y%m%d`

      # vi /root/prometheus-2.25.0.linux-amd64/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']

  - job_name: 'node1'

    scrape_interval: 10s

    static_configs:

    - targets: ['192.168.8.100:9100']

  - job_name: 'node2'

    scrape_interval: 10s

    static_configs:

    - targets: ['192.168.8.101:9100']

      # grep -v '^#' /srv/prometheus/prometheus.yml

启动文件制作

      # cd /usr/lib/systemd/system

      # vi prometheus.service

[Unit]

Description=prometheus

After=network.target

[Service]

User=root

Group=root

WorkingDirectory=/root/prometheus-2.25.0.linux-amd64

ExecStart=/root/prometheus-2.25.0.linux-amd64/prometheus --config.file=/root/prometheus-2.25.0.linux-amd64/prometheus.yml

[Install]

WantedBy=multi-user.target

      # systemctl daemon-reload

prometheus启动

      # systemctl start prometheus

      # systemctl status prometheus

设置prometheus自动启动

      # systemctl enable prometheus

      # prometheus --version

prometheus, version 2.25.0 (branch: HEAD, revision: a6be548dbc17780d562a39c0e4bd0bd4c00ad6e2)

  build user:      root@615f028225c9

  build date:      20210217-14:17:24

  go version:      go1.15.8

  platform:        linux/amd64

Web端确认

      URL:http://192.168.8.124:9090/

3.node_exporter install

官方网址

      https://github.com/prometheus/node_exporter/releases

安装包获取并解压

      # wget https://github.com/prometheus/node_exporter/releases/download/v1.1.1/node_exporter-1.1.1.linux-amd64.tar.gz

      # tar -zxvf node_exporter-1.1.1.linux-amd64.tar.gz

      # cd node_exporter-1.1.1.linux-amd64/

node_exporter自启动文件制作

      # vi /usr/lib/systemd/system/node_exporter.service

#Prometheus Node Exporter Upstart script

[Unit] /root/node_exporter-1.1.1.linux-amd64/node_exporter --help

Description=Node Exporter

Wants=network-online.target

After=network-online.target

[Service]

User=root

ExecStart=/root/node_exporter-1.1.1.linux-amd64/node_exporter

[Install]

WantedBy=default.target

      # systemctl daemon-reload

设置node_exporter自启动

      # systemctl enable node_exporter

启动node_exporter

      # systemctl start node_exporter

      # systemctl status node_exporter

Web端确认

      URL:http://192.168.8.124:9100/metrics

4.wmi_exporter install

      https://github.com/prometheus-community/windows_exporter/releases

      下载地址:https://github.com/martinlindhe/wmi_exporter/releases/download/v0.3.3/wmi_exporter-0.3.3-amd64.msi

      Windows默认9182端口。直接双击安装即可。

      访问http://IP:9182/metrics;显示数据说明数据采集器安装成功

Web端确认

      http://192.168.8.108:9182/metrics

5.Grafana install

官方地址

      https://grafana.com/

Grafana repo文件制作

      # vi /etc/yum.repos.d/grafana.repo

[grafana]

name=grafana

baseurl=https://packages.grafana.com/oss/rpm

repo_gpgcheck=1

enabled=1

gpgcheck=1

gpgkey=https://packages.grafana.com/gpg.key

sslverify=1

sslcacert=/etc/pki/tls/certs/ca-bundle.crt

YUM 安装grafana

      # yum -y install grafana

启动grafana

      # systemctl start grafana-server

      # systemctl status grafana-server

设置grafana自动启动

      # systemctl enable grafana-server

Web确认

      http://192.168.8.124:3000/login

6.alertmanager install

官方网址

      https://github.com/prometheus/alertmanager/releases

alertmanager安装包获取及解压

      # wget https://github.com/prometheus/alertmanager/releases/download/v0.21.0/alertmanager-0.21.0.linux-amd64.tar.gz

      # tar -zxvf alertmanager-0.21.0.linux-amd64.tar.gz

alertmanager自启动文件制作

      # vi /usr/lib/systemd/system/alertmanager.service

[Unit]

Description=Alertmanager

Documentation=https://prometheus.io/

After=network.target

[Service]

Type=simple

ExecStart=/root/alertmanager-0.21.0.linux-amd64/alertmanager --config.file=/root/alertmanager-0.21.0.linux-amd64/alertmanager.yml

Restart=on-failure

[Install]

WantedBy=multi-user.target

      # systemctl daemon-reload

设置alertmanager自动启动

      # systemctl enable alertmanager

启动alertmanager

      # systemctl start alertmanager

      # systemctl status alertmanager

      # netstat -lntup |grep alertmanager

tcp6      0      0 :::9093                :::*                    LISTEN      4090/alertmanager

tcp6      0      0 :::9094                :::*                    LISTEN      4090/alertmanager

udp6      0      0 :::9094                :::*                                4090/alertmanager

Web确认

      URL:http://192.168.8.124:9093/

7.prometheus联携Alertmanager配置

      # cp -p  /root/prometheus-2.25.0.linux-amd64/prometheus.yml /root/prometheus-2.25.0.linux-amd64/prometheus.yml.XXXXXX

      # vi /root/prometheus-2.25.0.linux-amd64/prometheus.yml

变更前:

# Alertmanager configuration

alerting:

  alertmanagers:

  - static_configs:

    - targets:

      # - alertmanager:9093

变更后:

alerting:

  alertmanagers:

  - static_configs:

    - targets: ['192.168.8.124:9093']

      # systemctl restart prometheus

      # systemctl status prometheus

上一篇下一篇

猜你喜欢

热点阅读