cAdvisor+Prometheus+grafana安装

本人是在VM里用CentOS7.5搭建的docker,安装时docker要先启动

1. 安装cAdvisor(需要监控的主机都要安装)

CAdvisor是谷歌开发的用于分析运行中容器的资源占用和性能指标的开源工具。CAdvisor是一个运行时的守护进程,负责收集、聚合、处理和输出运行中容器的信息。

注意在查找相关资料后发现这是最新版cAdvisor的bug,换成版本为google/cadvisor:v0.24.1 就ok了,映射主机端口默认是8080,可以修改。

命令:

   docker run \

  --volume=/:/rootfs:ro \

  --volume=/var/run:/var/run:ro \

  --volume=/sys:/sys:ro \

  --volume=/var/lib/docker/:/var/lib/docker:ro \

  --volume=/dev/disk/:/dev/disk:ro \

  --publish=8090:8080 \

  --detach=true \

  --name=cadvisor \

  google/cadvisor:v0.24.1

执行完后用命令: docker images 可以看到google/cadvisor,用命令:docker ps -a 可以看到启动的容器

 

然后页面用: ip地址 + 端口号(8090,默认8080)查看图像界面

查看json方式: ip地址 + 端口号/metrics

 

 

2. 安装Prometheus

官方地址:https://prometheus.io/

Prometheus 是一套开源的系统监控报警框架。它启发于 Google 的 borgmon 监控系统,由工作在 SoundCloud 的 google 前员工在 2012 年创建,作为社区开源项目进行开发,并于 2015 年正式发布。2016 年,Prometheus 正式加入 Cloud Native Computing Foundation,成为受欢迎度仅次于 Kubernetes 的项目

 

如果没有wget命令先安装wget命令: yum -y install wget

切换到路径/usr/local路径下执行命令:

wget https://github.com/prometheus/prometheus/releases/download/v2.8.0/prometheus-2.8.0.linux-amd64.tar.gz  或者从github上(https://github.com/prometheus/prometheus/releases)下载,用迅雷或者翻墙。我本机安装的是prometheus-2.13.1.linux-amd64.tar.gz这个版本

最好要把jdk安装好,这样可以使用jps命令

在路径/usr/local 下解压缩: tar -xzvf prometheus-2.13.1.linux-amd64.tar.gz

在/usr/local/prometheus-2.13.1.linux-amd64路径下,vi prometheus.yml

编辑全部内容如下,切记一定要遵守yml的格式规范

# 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=<job_name>` to any timeseries scraped from this config.

  - job_name: 'prometheus'

 

    # metrics_path defaults to '/metrics'

    # scheme defaults to 'http'.

 

    static_configs:

    - targets: ['192.168.180.134:9090']

   

  - job_name: 'docker'

    static_configs:

    - targets:

      - "192.168.180.134:8090"

      - "192.168.180.135:8090"

 

2.1.安装node-exporter

    上传node_exporter-0.17.0.linux-amd64.tar.gz到路径/usr/local下,然后解压: tar -xzvf node_exporter-0.17.0.linux-amd64.tar.gz

    或者用docker的方式安装,具体查看github,下面给出命令模式:

 docker run -d \

  --net="host" \

  --pid="host" \

  -v "/:/host:ro,rslave" \

  quay.io/prometheus/node-exporter \

  --path.rootfs=/host

    切换到路径: /usr/local/ node_exporter-0.17.0.linux-amd64下启动node-exporter.命令: 后台运行 ./node_exporter &

    在/usr/local/ node_exporter-0.17.0.linux-amd64路径下修改prometheus.yml文件。主要就是添加如下内容:

  - job_name: 'node_exporter'

    static_configs:

    - targets:

      - "192.168.180.134:9100"

2.2如果要监控mysql的话,去官网下载mysql_exporter相应版本安装;官网上还有其他的监控

cp prometheus promtool /usr/local/bin/

启动命令(未试成功): nohup prometheus --config.file=./prometheus.yml &

启动命令: nohup  ./prometheus --config.file=prometheus.yml

     3 安装grafana

         卸载方法:

            Yum history list 列出最近的历史

            Yum history info id 列出某次的详细信息

            Yum history undo id 撤销某次更改

            Yum history help 查看帮助

            用yum安装软件包命令: yum install 软件包名称

            用yum删除软件包命令: yum remove 软件包名称

            Yum localinstall 软件包名称 ;从硬盘安装rpm包并使用yum解决依赖

 

        1.使用镜像方法安装:

          镜像官网: https://hub.docker.com/r/grafana/grafana/tags

          [root@prometheus-server ~]# docker pull grafana/grafana:latest

          [root@prometheus-server ~]# docker run \

                                          -d \

                                 -p 3000:3000 \

                               --name=grafana \

                 -v /etc/localtime:/etc/localtime:ro \

                                grafana/grafana

          浏览器访问: http:// ip:3000 ,用户名密码:admin/admin

 

2.使用安装包安装

   官方地址: https://grafana.com/

   安装步骤:

    wget https://dl.grafana.com/oss/release/grafana-6.0.1-1.x86_64.rpm

sudo yum localinstall grafana-6.0.1-1.x86_64.rpm -y

systemctl daemon-reload

systemctl start grafana-server

systemctl status grafana-server

#设置开机自启动

sudo systemctl enable grafana-server.service

参考博客:https://www.cnblogs.com/Dev0ps/p/10546276.html

下载模板模板地址:https://grafana.com/dashboards

启动后在浏览器直接用ip地址+端口号方式访问,默认用户名密码是admin/admin; 进入后要先创建datasource然后再import模板JSON格式,在import的时候选择之前创建好的datasource

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值