Prometheus + Grafana安装

Prometheus是一款基于时序数据库的开源监控告警系统,非常适合Kubernetes集群的监控。Prometheus的基本原理是通过HTTP协议周期性抓取被监控组件的状态,任意组件只要提供对应的HTTP接口就可以接入监控。不需要任何SDK或者其他的集成过程。这样做非常适合做虚拟化环境监控系统,比如VM、Docker、Kubernetes等。
Grafana是一款开源的数据可视化工具,使用Grafana可以非常轻松的将数据转成图表(如下图)的展现形式来做到数据监控以及数据统计。 Grafana专注于时序类图表分析,而且支持多种数据源,如Graphite、InfluxDB、Elasticsearch、Mysql、K8s、Zabbix等。

环境准备

安装Docker

powershell 复制代码
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
powershell 复制代码
yum -y install docker-ce
powershell 复制代码
systemctl enable docker
systemctl start docker

拉取镜像:

shell 复制代码
docker pull bitnami/prometheus
docker pull grafana/grafana

启动prometheus

新建目录 prometheus,编辑配置文件prometheus.yml

shell 复制代码
mkdir /opt/prometheus
cd /opt/prometheus/
vim prometheus.yml

挂载配置文件:

yaml 复制代码
global:
  scrape_interval:     60s
  evaluation_interval: 60s
 
scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
        labels:
          instance: prometheus
 
  - job_name: linux
    static_configs:
      - targets: ['127.0.0.1:9100']
        labels:
          instance: localhost
复制代码
docker run  -d \
  -p 9090:9090 \
  -v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml  \
  bitnami/prometheus

访问127.0.0.1:9090/graph

启动grafana

新建空文件夹grafana-storage,用来存储数据

shell 复制代码
mkdir /opt/grafana-storage

设置权限,因为grafana用户会在这个目录写入文件,直接设置777!

shell 复制代码
chmod 777 -R /opt/grafana-storage

启动镜像

yaml 复制代码
docker run -d \
  -p 3000:3000 \
  --name=grafana \
  -v /opt/grafana-storage:/var/lib/grafana \
  grafana/grafana

默认账号密码:admin admin

相关推荐
飞川撸码4 小时前
web vue 项目 Docker化部署
前端·vue.js·docker·运维开发
大咖分享课21 小时前
云原生监控体系建设:Prometheus+Grafana的企业级实践
云原生·grafana·prometheus
欧先生^_^2 天前
ingress-nginx 开启 Prometheus 监控 + Grafana 查看指标
nginx·grafana·prometheus
Jeremy_Lee1232 天前
grafana 批量视图备份及恢复(含数据源)
前端·网络·grafana
全栈工程师修炼指南2 天前
Grafana 地图本土化方案:使用高德地图API平替GeoMap地图指南
grafana
临水逸2 天前
可视化大屏工具对比:GoView、DataRoom、积木JimuBI、Metabase、DataEase、Apache Superset 与 Grafana
apache·grafana
XMYX-02 天前
Spring Boot + Prometheus 实现应用监控(基于 Actuator 和 Micrometer)
spring boot·后端·prometheus
SailingCoder3 天前
grafana-mcp-analyzer:基于 MCP 的轻量 AI 分析监控图表的运维神器!
运维·人工智能·typescript·node.js·grafana
xbd_zc5 天前
【使用 Loki + Promtail + Grafana 搭建轻量级容器日志分析平台】
grafana·loki·promtail
方渐鸿5 天前
【2025】使用docker compose一键部署项目到服务器(4)
java·docker·运维开发·持续部署