• Prometheus完整安装


    官方组件:

    prometheus

    node_exporter

    blackbox_exporter

    alertmanager

    VictoriaMetrics

    第三方开源软件:

    ConsulManager      

    PrometheusAlert

     

    部署环境:

    centos 7 

     

    部署方式:

    官方组件全部采用二进制部署,第三方开源组软件采用docker方式部署

     

    安装步骤

    官网下载官方组件,全部解压至/opt

    修改文件名,去掉后面版本号

    配置系统服务

    cat > /etc/systemd/system/prometheus.service <[Unit]
    Description=prometheus
    After=network.target
    [Service]
    Type=simple
    User=prometheus
    ExecReload=/bin/kill -HUP \$MAINPID
    ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --storage.tsdb.path=/opt/prometheus/data --storage.tsdb.retention.time=2h --web.enable-lifecycle
    Restart=on-failure
    [Install]
    WantedBy=multi-user.target
    EOF

     

    systemctl daemon-reload &&
    systemctl start prometheus &&
    systemctl status prometheus &&
    systemctl enable prometheus

    cat > /etc/systemd/system/node_exporter.service <[Unit]
    Description=node_exporter
    After=network.target
    [Service]
    Type=simple
    User=prometheus
    ExecStart=/opt/node_exporter/node_exporter  --web.listen-address=:9100
    Restart=on-failure
    [Install]
    WantedBy=multi-user.target
    EOF

    systemctl daemon-reload &&

    systemctl start node_exporter &&

    systemctl status node_exporter &&

    systemctl enable node_exporter

    cat > /etc/systemd/system/alertmanager.service <[Unit]
    Description=alertmanager
    After=network.target
    [Service]
    Type=simple
    User=prometheus
    ExecStart=/opt/alertmanager/alertmanager --config.file=/opt/alertmanager/alertmanager.yml --storage.path=/opt/alertmanager/data --cluster.advertise-address=0.0.0.0:9093
    Restart=on-failure
    [Install]
    WantedBy=multi-user.target
    EOF

    systemctl daemon-reload
    systemctl start alertmanager &&
    systemctl status alertmanager &&
    systemctl enable alertmanager

     

    cat > /etc/systemd/system/blackbox_exporter.service<[Unit]
    Description=blackbox_exporter
    After=network.target
    [Service]
    Type=simple
    User=prometheus
    ExecStart=/opt/blackbox_exporter/blackbox_exporter --config.file=/opt/blackbox_exporter/blackbox.yml
    Restart=on-failure
    [Install]
    WantedBy=multi-user.target
    EOF

    systemctl daemon-reload &&
    systemctl start blackbox_exporter &&
    systemctl status blackbox_exporter &&
    systemctl enable blackbox_exporter

     

    第三方软件参考github上安装

    最终效果:

    通过ConsulManager实现公有云虚机自动同步,自建主机可通过固定模板批量导入。相关配置文件可以在consulmanager的页面上查看,更新自己的proemtheus.yml文件即可。 

    url站点监控同理。

    通过prometheusalert实现告警发送,路由可在web页面上设置,省略在alertmanager上配置的复杂。可实现钉钉、企业微信、邮件、飞书的告警发送方式。

    后端存储使用VictoriaMetrics,优点:部署简单,存储可以用oss,也可以使用本地硬盘。不同于thanos,只能用对象存储,且部署复杂。

    在prometheus.yml里添加remote_write配置:

    remote_write:
    - url: http://VictoriaMetrics:8428/api/v1/write

    前端展示:

    安装grafana

    添加prometheus数据源为http://VictoriaMetrics:8428

    导入模板:8919  更适用于主要监控公有云ECS

            16098  更适用于自建主机为主

    两者没有太大的区别,看个人选择

    blackbox模板:9965 

    以上都需要配合consulmanager使用为最佳。  

  • 相关阅读:
    208道Java中高级高频面试题(含答案)
    git上传代码(第一次或已有代码)
    5-2传输层-UDP协议
    系统安全及应用
    React 学习笔记总结(一)
    【PAT A-1038】Recover the Smallest Number
    我的个人网站不让接入微信登录,于是我做了这个
    ubuntu18.04出现关于显卡驱动问题的解决办法
    git基础命令(二)
    Mysql安装
  • 原文地址:https://www.cnblogs.com/whoaeryou/p/16565961.html