• docker 部署prometheus+grafana


    首先进行部署docker

    配置阿里云依赖:

    curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo       # 配置centos 7的镜像源
    yum install -y yum-utils device-mapper-persistent-data lvm2   # 安装一些后期或需要的的一下依赖
    yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    sed  -i 's/http/https/g' /etc/yum.repos.d/CentOS-Base.repo
    cat <<EOF > /etc/yum.repos.d/kubernetes.repo   # 配置阿里云的k8s源
    [kubernetes]
    name=Kubernetes
    baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
    enabled=1
    gpgcheck=1
    repo_gpgcheck=1
    gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
    EOF
    sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    开始进行安装docker

    yum install docker-ce-19.03.* docker-ce-cli-19.03.* -y
    # 由于新版kubelet建议使用systemd,所以可以把docker的CgroupDriver改成systemd
    # "live-restore": true这个此参数相当于是进行加载docker不进行重启里面的镜像
    mkdir /etc/docker
    cat > /etc/docker/daemon.json <<EOF
    {
     "registry-mirrors": [
        "https://registry.docker-cn.com",
        "http://hub-mirror.c.163.com",
        "https://docker.mirrors.ustc.edu.cn"
      ],
     "exec-opts": ["native.cgroupdriver=systemd"],
     "max-concurrent-downloads": 10,
     "max-concurrent-uploads": 5,
     "log-opts": {
       "max-size": "300m",
       "max-file": "2"
     },
     "live-restore": true
    }
    EOF
    # 所有节点设置开机自启动Docker:
    systemctl daemon-reload && systemctl enable --now docker
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    安装普罗米修斯

    下载镜像:

    docker pull docker.mirrors.sjtug.sjtu.edu.cn/prom/prometheus
    
    • 1

    创建普罗米的yaml

    # my global config
    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=` to any timeseries scraped from this config.
      - job_name: "prometheus"
        # metrics_path defaults to '/metrics'
        # scheme defaults to 'http'.
        static_configs:
          - targets: ["localhost:9090"]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    创建普罗米使用的目录:

    mkdir /root/data/
    cp prometheus.yml /root/. 
    
    • 1
    • 2

    启动普罗米

    docker run --name xixi -itd -u root -p 9091:9090 \ 
    -v /root/prometheus.yml:/etc/prometheus/prometheus.yml \
    -v /root/data: -v  /root/data:/prometheus \
    docker.mirrors.sjtug.sjtu.edu.cn/prom/prometheus:latest
    # 如果不写-u root启动的话可能出现没有权限的报错
    
    • 1
    • 2
    • 3
    • 4
    • 5

    进行验证是否启动成功:

    在这里插入图片描述

    grafana大屏展示

    进行下载grafana的docker镜像

    docker pull docker.mirrors.sjtug.sjtu.edu.cn/grafana/grafana:latest
    
    • 1

    进行创建所有使用的目录

    mkdir -p /root/grafana/data /root/grafana/plugins /root/grafana/config
    
    
    • 1
    • 2

    cp文件到config下

    cp grafana.ini  /root/grafana/config/grafana.ini
    
    • 1

    启动grafana

    docker run -dit \
        -p 3000:3000 \
        --name=grafana \
    	-u root \ 
        -v /etc/localtime:/etc/localtime:ro \
        -v /root/grafana/data:/var/lib/grafana \
        -v /root/grafana/plugins/:/var/lib/grafana/plugins \
        -v /root/grafana/config/grafana.ini:/etc/grafana/grafana.ini \
        -e "GF_SECURITY_ADMIN_PASSWORD=admin" \
        -e "GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource,grafana-piechart-panel" \
         docker.mirrors.sjtug.sjtu.edu.cn/grafana/grafana:latest
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    进行验证:

    在这里插入图片描述

    进行关联普罗米的数据源:

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

  • 相关阅读:
    【JAVASE】程序异常处理
    maven报orace,jdbc错误,并出现大量红色波浪线Unresolved dependency
    初识React及React开发依赖介绍
    15.IGame游戏公司的故事[20220624]
    Webview 和 React Native 中吸顶效果实现
    Python接口自动化(什么是接口、接口优势、类型)
    GLEIF携手TrustAsia,共促数字邮件证书的信任与透明度升级
    11.25日常总结
    MySQL操作合集
    LLM - RAG 大型语言模型的检索增强生成研究综述
  • 原文地址:https://blog.csdn.net/weixin_44932410/article/details/136524406