零基礎搭建服務器監控系統(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