零基础搭建服务器监控系统(Prometheus+grafana+node-exporter )


本篇记录我的搭建监控系统的历程,

使用系统为ubuntu18.04LTS,前置要求为docker,以及会一些简单的linux命令

最终选择的方案是

Prometheus+grafana+node-exporter

 

其中Prometheus和grafana可以使用docker来安装,这两个装在提供web服务的主机上。

 

Node-exporter需要监控实际的主机硬件信息,不推荐用docker来安装,所以通过二进制包来安装

 

https://www.cnblogs.com/chenqionghe/p/10494868.html  从零搭建Prometheus监控报警系统

该博客可以作为入门,但有几个坑的地方要注意

  1. 文件夹目录的名字错了,prometheus拼写错误
  2. 配置文件prometheus.yml放错地方了,放在了test目录下?混淆了
  3. prometheus.yml内容有问题,用了会报错。建议去官方找模板然后改。我放下我的给大家参考下(比较简单)
  4. 即使加了--web.enable-lifecycle启用远程热加载配置文件,仍旧无法用curl命令更新配置文件(查看日志确实有重新配置的操作,但docker -v挂载的文件没有同步,猜测是挂载命令哪里出错了,或许是忘记修改宿主机的挂载文件夹的权限了,ps..我记得做了,暂且不管了,这个问题通过重启prometheus容器来解决了)
global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    monitor: 'codelab-monitor'

# 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'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
      - targets: ['192.168.126.129:9100']
        labels:
          group: 'client-node-exporter'
      - targets: ['localhost:9090']

  

上面那个博客是用docker来安装node-exporter,自然不是很满意了

 

https://prometheus.io/docs/guides/node-exporter/

pro的官方指导如何安装。结果发现git clone被拒绝连接了,,懒得FQ或者修改hosts了

 

在gitee上找到下面这个库

https://gitee.com/oboi/prometheus-node_exporter-Grafana

 

这个里面就包含node-exporter的压缩包了,可以拿来直接用。

而且它还有使用ansible-playbook批量部署node-exporter的脚本,以及使用docker-compose批量开启Prometheus和grafana的脚本,比较方便。

当然啦,ansible-playbook脚本文件中的主机host还需要自己修改,我将地址改成localhost,起码安装在本机没有问题了。

 

后续有时间再补图了。。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM