程序员

Prometheus部署

作者:admin 2021-04-17 我要评论

一、环境准备 1、 防火墙配置 这里做了防火墙关闭,或者可以在防火墙开启9100、9093端口[root@Prometheus ~]# systemctl stop firewall[root@Prometheus ~]# sys...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

一、环境准备

1、 防火墙配置

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

2、selinux配置

[root@Prometheus ~]# vim /etc/selinux/config
SELINUX=disabled
[root@Prometheus ~]# setenforce 0

3、更新yum

[root@Prometheus ~]# yum update

二、Prometheus部署

1、下载安装包

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

2、包解压

tar xvfz prometheus-*.tar.gz

3、配置Prometheus监控

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/

下载上传安装包: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

[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

curl -XPOST http://localhost:9090/-/reload

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

image.png

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 四两拨千斤——你不知道的VScode编码Ty

    四两拨千斤——你不知道的VScode编码Ty

  • 我是如何在 Vue 项目中做代码分割的

    我是如何在 Vue 项目中做代码分割的

  • position:sticky 粘性定位的几种巧妙应

    position:sticky 粘性定位的几种巧妙应

  • 从零到一搭建React组件库

    从零到一搭建React组件库

腾讯云代理商
精彩导读
海外云服务器
热门资讯
腾讯云代理商