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

2026重新梳理systemctl和docker安装 Prometheus三件套+node-exportor-grafana安装

2026重新梳理systemctl和docker安装 Prometheus三件套+node-exportor-grafana安装

一、Prometheus 安装脚本(最终完善版)

#!/bin/bashset-eecho"===== 开始安装 Prometheus ====="# 清理旧环境systemctl stop prometheus2>/dev/null systemctl disable prometheus2>/dev/nulluserdel-rprometheus2>/dev/nullrm-rf/usr/local/prometheus /var/lib/prometheus /etc/systemd/system/prometheus.service# 解压(已下载好包)tarzxf prometheus-2.19.2.linux-amd64.tar.gzmvprometheus-2.19.2.linux-amd64 /usr/local/prometheus# 创建用户groupaddprometheus2>/dev/nulluseradd-gprometheus-m-d/var/lib/prometheus-s/sbin/nologin prometheus2>/dev/null# 创建数据目录mkdir-p/var/lib/prometheus/datachown-Rprometheus:prometheus /usr/local/prometheus /var/lib/prometheus# 生成 systemdcat>/etc/systemd/system/prometheus.service<<EOF [Unit] Description=Prometheus After=network.target [Service] User=prometheus Group=prometheus ExecStart=/usr/local/prometheus/prometheus \ --config.file=/usr/local/prometheus/prometheus.yml \ --storage.tsdb.path=/var/lib/prometheus/data \ --web.listen-address=0.0.0.0:9090 Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target EOF# 启动systemctl daemon-reload systemctlenableprometheus systemctl restart prometheusecho"===== Prometheus 安装完成 ====="systemctl status prometheus --no-pager

二、Node Exporter 安装脚本(最终完善版)

#!/bin/bashset-eecho"===== 开始安装 Node Exporter ====="# 清理旧环境systemctl stop node_exporter2>/dev/null systemctl disable node_exporter2>/dev/nullrm-rf/usr/local/node_exporter /etc/systemd/system/node_exporter.service# 解压tarzxf node_exporter-1.3.1.linux-amd64.tar.gzmvnode_exporter-1.3.1.linux-amd64 /usr/local/node_exporter# 用户不存在则创建idprometheus&>/dev/null||useradd-m-d/var/lib/prometheus-s/sbin/nologin prometheus# 权限chown-Rprometheus:prometheus /usr/local/node_exporter# systemdcat>/etc/systemd/system/node_exporter.service<<EOF [Unit] Description=Node Exporter After=network.target [Service] User=prometheus Group=prometheus ExecStart=/usr/local/node_exporter/node_exporter \ --web.listen-address=:9100 \ --collector.systemd \ --collector.processes Restart=on-failure [Install] WantedBy=multi-user.target EOF# 启动systemctl daemon-reload systemctlenablenode_exporter systemctl restart node_exporterecho"===== Node Exporter 安装完成 ====="systemctl status node_exporter --no-pager

三、Grafana 安装脚本(最终极简稳定版)

#!/bin/bashset-eecho"===== 开始安装 Grafana ====="# 安装 repocat>/etc/yum.repos.d/grafana.repo<<EOF [grafana] name=grafana baseurl=https://packages.grafana.com/oss/rpm repo_gpgcheck=1 enabled=1 gpgkey=https://packages.grafana.com/gpg.key sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt EOF# 安装yuminstall-ygrafana# 自动添加 Prometheus 数据源mkdir-p/etc/grafana/provisioning/datasourcescat>/etc/grafana/provisioning/datasources/prometheus.yaml<<EOF apiVersion: 1 datasources: - name: Prometheus type: prometheus access: proxy url: http://localhost:9090 isDefault: true EOF# 启动systemctl daemon-reload systemctlenablegrafana-server systemctl restart grafana-serverecho"===== Grafana 安装完成 ====="echo"访问: http://IP:3000 账号密码: admin/admin"systemctl status grafana-server --no-pager

四、配套 prometheus.yml(最终完整版)

global:scrape_interval:15sevaluation_interval:15salerting:alertmanagers:-static_configs:-targets:['localhost:9093']rule_files:-"alerting_rules.yml"scrape_configs:-job_name:'prometheus'static_configs:-targets:['localhost:9090']-job_name:'node_exporter'static_configs:-targets:['localhost:9100']

Prometheus + Node Exporter + Grafana + 主配置 + 权限 + 数据目录 + systemd


给你CentOS7 专用 · 100% 可直接运行

三组件一键 Docker / Docker Compose 方案

Prometheus + Node Exporter + Grafana
干净、不污染系统、讲课最爽、博客最帅!


方案1:Docker Compose 一键启动(最推荐 ✅)

1)先装 docker + docker-compose(CentOS7)

#!/bin/bash# 安装 Dockeryuminstall-yyum-utils yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yuminstall-ydocker-ce docker-ce-cli containerd.io systemctl startdockersystemctlenabledocker# 安装 docker-composecurl-L"https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-$(uname-s)-$(uname-m)"-o/usr/local/bin/docker-composechmod+x /usr/local/bin/docker-compose

2)docker-compose.yml(完整最终版 ✅)

直接新建一个文件夹,放这个文件即可:

version:'3'services:# 1. Node Exporter (监控机器)node_exporter:image:prom/node-exporter:latestcontainer_name:node_exporterrestart:alwaysports:-"9100:9100"volumes:-/:/host:ro,rslavecommand:-'--path.rootfs=/host'network_mode:host# 2. Prometheus (数据存储+查询)prometheus:image:prom/prometheus:v2.19.2container_name:prometheusrestart:alwaysports:-"9090:9090"volumes:-./prometheus.yml:/etc/prometheus/prometheus.yml-prom_data:/prometheusnetwork_mode:host# 3. Grafana (可视化面板)grafana:image:grafana/grafana:10.1.5container_name:grafanarestart:alwaysports:-"3000:3000"volumes:-grafana_data:/var/lib/grafananetwork_mode:hostvolumes:prom_data:grafana_data:

3)配套 prometheus.yml(和上面放一起)

global:scrape_interval:15sscrape_configs:-job_name:'prometheus'static_configs:-targets:['localhost:9090']-job_name:'node_exporter'static_configs:-targets:['localhost:9100']

4)一键启动

docker-composeup-d

方案2:纯 Docker 命令版(无 compose)

直接复制运行 ✅

#!/bin/bash# 1. 启动 Node Exporterdockerrun-d\--namenode_exporter\--nethost\--restartalways\-v/:/host:ro,rslave\prom/node-exporter\--path.rootfs=/host# 2. 启动 Prometheusdockerrun-d\--nameprometheus\--nethost\--restartalways\-v./prometheus.yml:/etc/prometheus/prometheus.yml\prom/prometheus:v2.19.2# 3. 启动 Grafanadockerrun-d\--namegrafana\--nethost\--restartalways\grafana/grafana:10.1.5

最终访问信息

  • Prometheus: http://IP:9090
  • Node Exporter: http://IP:9100/metrics
  • Grafana: http://IP:3000
    • 账号:admin
    • 密码:admin

http://www.jsqmd.com/news/587235/

相关文章:

  • AMD GPU本地AI部署全攻略:基于Ollama-for-amd的高效实践指南
  • 学习二分查找
  • 代码随想录算法训练营Day-17 | 654.最大二叉树、617.合并二叉树、700.二叉搜索树中的搜索、98.验证二叉搜索树
  • 告别重复造轮子:用快马生成openclaw启动高效开发工具链
  • 江诗丹顿官方售后服务中心新址实地考察报告(2026年4月最新版) - 亨得利官方服务中心
  • 2026AIGC 短剧出海全链路落地服务测评
  • 2025届毕业生推荐的五大AI写作方案实测分析
  • wps的VBA小tips1
  • 如何快速使用MTKClient:联发科设备救砖与调试的完整指南
  • 虾友见面会 | Comake Pi × ZeroClaw部署实战沙龙开放报名
  • OpenCore Legacy Patcher老Mac升级指南:从硬件评估到系统优化的完整流程
  • 绝区零一条龙:AI驱动的游戏体验革新工具
  • emptydir存储对应宿主机存储位置
  • 快速上手:使用Git管理南北阁Nanbeige 4.1-3B的微调与部署版本
  • PowerShell-7.5.0-win-x64
  • 项目经理必看:被领导批评后如何用向上管理化危机为转机
  • AI检索——基础 RAG vs. 检索 Agent对比
  • 降AI工具为什么比自己改效果好?从算法角度解读 - 我要发一区
  • 如何完全掌握微信聊天数据:WeChatMsg免费工具的终极指南
  • 脚本-FX Console 搜索效果
  • 鸿蒙跨设备互通:让你的应用“借用“另一台设备的相机和图库
  • Pixel Dream Workshop保姆级教程:从Docker拉取到内存流导出全流程
  • Luogu P1809 过河问题
  • 2026年泉州代理记账报税公司性价比排名,为你精选优质企业 - myqiye
  • 2025届毕业生推荐的五大AI科研工具推荐
  • vscode的if结尾提示插件“If End Marker”实现了if结尾提示功能
  • Typora标题自动编号完全指南-零代码基础实现自动化文档结构
  • 3分钟解锁B站直播自由:第三方推流工具实战指南
  • 实战演练:借助快马AI快速构建Spring Boot博客系统核心模块
  • NoSleep防休眠工具:让系统持续运行的轻量级解决方案