docker-compose安装prometheus 、grafana

前提:服务器上已安装docker-compose,未安装的可以参考相关文章进行安装

主要步骤

1. 进入目标环境创建安装目录(具体可按照所在服务器安装目录风格选择对应文件夹)
cd /apps 
mkdir {/prometheus+grafana,prometheus+grafana/prometheus,prometheus+grafana/grafana}
2. 创建prometheus配置文件
cd prometheus
vim prometheus.yml

# 可参考 https://prometheus.io/docs/prometheus/latest/getting_started
global:
  scrape_interval: 10s
  scrape_timeout: 10s
  evaluation_interval: 10m
  
scrape_configs:
  # prometheus
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090'] ## 修改成服务器ip即可
        labels:
          instance: prometheus

3. 创建docker-compose文件
cd ..
vim docker-compose-prometheus-grafana.yml
version: 3

# 服务
services:
  # prometheus
  prometheus:
    image: prom/prometheus:latest             
    container_name: prometheus
    restart: unless-stopped
    volumes:
      - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
    command: "--config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/prometheus"
    ports:
      - "9090:9090"
    networks:
      prometheus:
        ipv4_address: 172.22.0.11

  # 监控告警WEB UI 配合prometheus使用
  # https://grafana.com/docs/grafana/latest/installation/docker
  grafana:
    image: grafana/grafana:latest             
    container_name: prometheus-grafana
    restart: unless-stopped
    ports:
      - "3000:3000"
    volumes:
      - "./grafana/grafana.ini:/etc/grafana/grafana.ini" # 初始化配置(可设置一些告警邮箱等)
    environment:
      GF_EXPLORE_ENABLED: "true"
      # 初始账号密码:admin/admin
      GF_SECURITY_ADMIN_PASSWORD: "admin"
      GF_INSTALL_PLUGINS: "grafana-clock-panel,grafana-simple-json-datasource,alexanderzobnin-zabbix-app"
      # 持久化到mysql数据库
      GF_DATABASE_URL: "mysql://root:root@localhost:3306/grafana" # TODO 待修改处(只需创建目标数据库,grafana在启动时会自动初始化相关表)
    depends_on:
      - prometheus
    networks:
      prometheus:
        ipv4_address: 172.22.0.22
 
# 网桥 
networks:
  prometheus:
    ipam:
      driver: default
      config:
        - subnet: "172.22.0.0/24"
4.启动docker-compose

docker-compose -f docker-compose-prometheus-grafana.yml up -d
在这里插入图片描述

5.检查启动容器启动状态

docker-compose -f docker-compose-prometheus-grafana.yml ps
在这里插入图片描述

6.浏览器进入grafana web界面: http://localhost:3000 (可切换成服务器ip) 账号密码为admin/admin

(一般初次启动会慢一些,需要等待一下,如果安装在内网环境,就需要本机能访问内网权限才能看,进入之后会提示改密码,修改自定义密码即可)

7.选择设置,进入后配置prometheus数据源

在这里插入图片描述

8.搜索prometheus数据源,并配置相关host等信息,点击保存,出现绿标代表连通访问prometheus了

在这里插入图片描述在这里插入图片描述
在这里插入图片描述

9.这样grafana就能通过prometheus收集到的监控数据,进行各种ui展示了,后续查看接下来章节,对mysql、linux、docekr容器、k8s集群容器等进行监控
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值