零基础搭建服务器监控系统(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监控报警系统
该博客可以作为入门,但有几个坑的地方要注意
- 文件夹目录的名字错了,prometheus拼写错误
- 配置文件prometheus.yml放错地方了,放在了test目录下?混淆了
- prometheus.yml内容有问题,用了会报错。建议去官方找模板然后改。我放下我的给大家参考下(比较简单)
- 即使加了--web.enable-lifecycle启用远程热加载配置文件,仍旧无法用curl命令更新配置文件(查看日志确实有重新配置的操作,但docker -v挂载的文件没有同步,猜测是挂载命令哪里出错了,或许是忘记修改宿主机的挂载文件夹的权限了,ps..我记得做了,暂且不管了,这个问题通过重启prometheus容器来解决了)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 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,起码安装在本机没有问题了。
后续有时间再补图了。。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战