当前位置: 首页 > news >正文

5 分钟搭建 Prometheus + Grafana 监控

一.安装 Prometheus

cd /usr/local/
wget https://github.com/prometheus/prometheus/releases/download/v2.38.0/prometheus-2.38.0.linux-amd64.tar.gz
tar xvf prometheus-2.38.0.linux-amd64.tar.gz
ln -s prometheus-2.38.0.linux-amd64 prometheus

二.安装 node_exporter 

在被监控机器上下载 node_exporter

wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
tar xvf node_exporter-1.3.1.linux-amd64.tar.gz
ln -s node_exporter-1.3.1.linux-amd64 node_exporter

启动 node_exporter

nohup ./node_exporter  --web.listen-address=":9100"&
netstat -ntlup | grep 9100

三.安装 mysqld_exporter 

在被监控机器上下载 mysqld_exporter

wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.14.0/mysqld_exporter-0.14.0.linux-amd64.tar.gz
tar xvf mysqld_exporter-0.14.0.linux-amd64.tar.gz
ln -s mysqld_exporter-0.14.0.linux-amd64 mysqld_exporter

创建监控⽤户

create user 'monitor'@'127.0.0.1' identified with mysql_native_password by '123456';
grant select,replication client, process on *.* to 'monitor'@'127.0.0.1';

添加客户端账号

vim /usr/local/mysqld_exporter/.my.cnf

 [client]
 host=127.0.0.1
 port=3306
 user=monitor
 password=123456

重启 mysqld_exporter 

nohup /usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf &

netstat -ntlup | grep 9104

 四.修改 prometheus 配置⽂件

添加被监控主机

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:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.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: 'node2'
    static_configs:
      - targets: ['192.168.80.11:9100']

  - job_name: 'node-mysql'
    static_configs:
      - targets: ['192.168.80.11:9104']

重启 prometheus

pkill prometheus
/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &

 检查 Targets

 五.安装 Grafana

 下载 Grafana

wget https://dl.grafana.com/oss/release/grafana-9.1.5.linux-amd64.tar.gz
tar -zxvf grafana-9.1.5.linux-amd64.tar.gz
ln -s grafana-9.1.5 grafana

 启动 grafana

cd grafana
./bin/grafana-server &

登录 grafana

初始账号密码:admin/admin

六.导入主机

Add data source 

 这个 1860 对应的模板地址是 https://grafana.com/grafana/dashboards/1860-node-exporter-full/

查看效果

七.导入mysql

导⼊⽅式同上,只不过对应的 ID 是 7362。

https://grafana.com/grafana/dashboards/7362-mysql-overview/

完成。 

相关文章:

  • vue/react/vite前端项目打包的时候加上时间最简单版本,防止后端扯皮
  • 【C/C++】文件句柄
  • Dify1.01版本vscode 本地环境搭建运行实践
  • SSL 和 TLS 认证
  • Vue 3 事件总线详解:构建组件间高效通信的桥梁
  • 在虚拟环境里面配置Linux系统
  • 工作流集成方案,程序审批功能,springboot集成工作流
  • 解决Win11 rdp输入正确的密码,但是还是登录失败
  • 什么是提示词工程,有哪些开源项目
  • vscode怎么debug vue项目
  • 用Deep seek解析ChatGPT打造数字虚拟人
  • iOS底层原理系列05-内存管理:从核心原理到高级优化
  • Linux网络编程——守护进程
  • 【存储中间件】Redis核心技术与实战(一):Redis入门与应用(高级数据结构:Bitmaps、HyperLogLog、GEO)
  • CSS语言的编程范式
  • 使用DeepSeek和墨刀AI,写PRD文档、画原型图的思路、过程及方法
  • ECU BootLoader开发——Flash编程
  • npm : 无法加载文件 C:\Program Files\nodejs\npm.ps1,因为在此系统上禁止运行脚本的处理方法
  • DataWhale 大语言模型 - 长上下文模型和新型架构
  • Android 全屏6位密码输入框:优化布局与功能实现
  • 提供信息门户网站建设/sem外包
  • 农家院网站素材/找回今日头条
  • 外贸网站源码怎么建/武汉网络推广网络营销
  • 公司付网站会员费科目怎么做/seo关键词如何设置
  • 做网站架构需要什么工具/四平网络推广
  • 青海网站制作的公司/东莞做网站排名优化推广