部署prometheus+grafana监控docker(代码片段)

礁之 礁之     2022-11-30     523

关键词:

部署Prometheus+Grafana监控Docker

(1)实验环境

两台主机都需要桥接网卡!

系统主机名ip安装软件扮演角色
Centos7.4Prometheus192.168.100.210prometheus+Grafana+exporter+cAdvisor+influxdb+docker监控端
Centos7.4Docker192.168.100.208exporter+docker+cAdvisor被监控端

(2)实验步骤

1、先做基础配置

#监控端配置
[root@Centos7 ~]# hostnamectl set-hostname prometheus
[root@Centos7 ~]# su
[root@prometheus ~]# systemctl stop firewalld
[root@prometheus ~]# setenforce 0
setenforce: SELinux is disabled
[root@prometheus ~]# mount /dev/cdrom /mnt/
[root@prometheus ~]# yum -y install ntpdate
[root@prometheus ~]# ntpdate ntp1.aliyun.com
 5 Aug 09:58:03 ntpdate[1142]: step time server 120.25.115.20 offset -28802.931261 sec
#被监控端配置
[root@Centos7 ~]# hostnamectl set-hostname docker
[root@Centos7 ~]# su
[root@docker ~]# systemctl stop firewalld
[root@docker ~]# setenforce 0
setenforce: SELinux is disabled
[root@docker ~]# mount /dev/cdrom /mnt/
[root@docker ~]# yum -y install ntpdate
[root@docker ~]# ntpdate ntp1.aliyun.com
 5 Aug 09:58:23 ntpdate[1527]: step time server 120.25.115.20 offset -28801.336708 sec

2、在监控端安装服务

安装prometheus+Grafana+exporter+cAdvisor+influxdb

#以下操作全部都在监控端执行
#上传软件包
[root@prometheus ~]# ll
总用量 58216
-rw-------. 1 root root     1264 112 2021 anaconda-ks.cfg
-rw-r--r--  1 root root 59608515 85 09:59 prometheus-2.16.0.linux-amd64.tar.gz
[root@prometheus ~]# tar xf prometheus-2.16.0.linux-amd64.tar.gz
[root@prometheus ~]# mv prometheus-2.16.0.linux-amd64 /usr/local/prometheus
[root@prometheus ~]# cd /usr/local/prometheus/

#Promtheus作为一个时间序列数据库,其采集的数据会以文件的形似存储在本地中,默认的存储路径为data/,因此我们需要先手动创建该目录:
[root@prometheus prometheus]# mkdir data    
[root@prometheus prometheus]# ll
总用量 140984
drwxr-xr-x 2 3434 3434       38 214 2020 console_libraries
drwxr-xr-x 2 3434 3434      173 214 2020 consoles
drwxr-xr-x 3 root root       51 85 10:00 data
-rw-r--r-- 1 3434 3434    11357 214 2020 LICENSE
-rw-r--r-- 1 3434 3434     3184 214 2020 NOTICE
-rwxr-xr-x 1 3434 3434 82329106 214 2020 prometheus
-rw-r--r-- 1 3434 3434      926 214 2020 prometheus.yml
-rwxr-xr-x 1 3434 3434 48417809 214 2020 promtool
-rwxr-xr-x 1 3434 3434 13595766 214 2020 tsdb
[root@prometheus prometheus]# useradd -s /sbin/nologin prometheus
[root@prometheus prometheus]# chown -R prometheus:prometheus /usr/local/prometheus/
[root@prometheus prometheus]# cd /usr/lib/systemd/system
[root@prometheus system]# vim prometheus.service
[Unit]
Description=prometheus
After=network.target 

[Service]
User=prometheus
Group=prometheus
WorkingDirectory=/usr/local/prometheus
ExecStart=/usr/local/prometheus/prometheus
[Install]
WantedBy=multi-user.target
#保存退出
[root@prometheus system]# systemctl start prometheus      #启动
[root@prometheus system]# netstat -napt | grep 9090       #查看监听端口
tcp        0      0 127.0.0.1:56274         127.0.0.1:9090          ESTABLISHED 1316/prometheus     
tcp6       0      0 :::9090                 :::*                    LISTEN      1316/prometheus     
tcp6       0      0 127.0.0.1:9090          127.0.0.1:56274         ESTABLISHED 1316/prometheus 

使用浏览器进行访问http://192.168.100.210:9090

#安装influxdb数据库
#上传软件包进行安装
[root@prometheus system]# cd
[root@prometheus ~]# ll
总用量 108032
-rw-------. 1 root root     1264 112 2021 anaconda-ks.cfg
-rw-r--r--  1 root root 51010897 85 10:08 influxdb-1.7.8.x86_64.rpm
-rw-r--r--  1 root root 59608515 85 09:59 prometheus-2.16.0.linux-amd64.tar.gz
[root@prometheus ~]# yum -y install influxdb-1.7.8.x86_64.rpm
[root@prometheus ~]# cp /etc/influxdb/influxdb.conf /etc/influxdb/influxdb.conf.default
[root@prometheus ~]# systemctl start influxdb
[root@prometheus ~]# systemctl enable influxdb
[root@prometheus ~]# influx   #进入数据库
Connected to http://localhost:8086 version 1.7.8
InfluxDB shell version: 1.7.8
> show databases;
name: databases
name
----
_internal
> create database prometheus ;   #创建prometheus库
> show databases;   #确认已经创建
name: databases
name
----
_internal
prometheus
> exit
#配置普罗米修斯集成influxdb数据库
[root@prometheus ~]# cd /usr/local/prometheus/
[root@prometheus prometheus]# cp prometheus.yml prometheus.yml.defalut
[root@prometheus prometheus]# vim prometheus.yml    #末尾直接添加
remote_write:
  - url: "http://localhost:8086/api/v1/prom/write?db=prometheus" 

remote_read:
  - url: "http://localhost:8086/api/v1/prom/read?db=prometheus"
#保存退出
[root@prometheus prometheus]# systemctl restart prometheus
[root@prometheus prometheus]# systemctl status prometheus

#检测prometheus数据是否到了数据库中
[root@prometheus prometheus]# cd
[root@prometheus ~]# influx
Connected to http://localhost:8086 version 1.7.8
InfluxDB shell version: 1.7.8
> use prometheus;          #进入prometheus库
Using database prometheus
>  show MEASUREMENTS;      #查看当前库下的所有数据,有数据就可以了
> exit
#安装Grafana
[root@prometheus ~]# yum -y install fontconfig freetype* urw-fonts

#上传软件包
[root@prometheus ~]# ll
总用量 163076
-rw-------. 1 root root     1264 112 2021 anaconda-ks.cfg
-rw-r--r--  1 root root 56363500 617 16:40 grafana-6.1.4-1.x86_64.rpm
-rw-r--r--  1 root root 51010897 85 10:08 influxdb-1.7.8.x86_64.rpm
-rw-r--r--  1 root root 59608515 85 09:59 prometheus-2.16.0.linux-amd64.tar.gz
[root@prometheus ~]# yum -y install grafana-6.1.4-1.x86_64.rpm
[root@prometheus ~]# systemctl start grafana-server
[root@prometheus ~]# netstat -anpt | grep 3000
tcp6       0      0 :::3000                 :::*                    LISTEN      1509/grafana-server 

使用浏览器进行测试

#安装exporter
#上传软件包
[root@prometheus ~]# ll
总用量 170972
-rw-------. 1 root root     1264 112 2021 anaconda-ks.cfg
-rw-r--r--  1 root root 56363500 617 16:40 grafana-6.1.4-1.x86_64.rpm
-rw-r--r--  1 root root 51010897 85 10:08 influxdb-1.7.8.x86_64.rpm
-rw-r--r--  1 root root  8083296 710 16:51 node_exporter-0.18.1.linux-amd64.tar.gz
-rw-r--r--  1 root root 59608515 85 09:59 prometheus-2.16.0.linux-amd64.tar.gz
[root@prometheus ~]# tar xf node_exporter-0.18.1.linux-amd64.tar.gz 
[root@prometheus ~]# mv node_exporter-0.18.1.linux-amd64 /usr/local/exporter
[root@prometheus ~]# cd /usr/lib/systemd/system
[root@prometheus system]#  vim node_exporter.service
[Unit]
Description=node_exporter
After=network.target

[Service]
User=prometheus
Group=prometheus
ExecStart=/usr/local/exporter/node_exporter --web.listen-address=:20001 --collector.systemd --collector.systemd.unit-whitelist=(sshd|nginx).service --collector.processes --collector.tcpstat
[Install]
WantedBy=multi-user.target
#保存退出
[root@prometheus system]# systemctl daemon-reload 
[root@prometheus system]# systemctl start node_exporter 
[root@prometheus system]# systemctl status node_exporter
[root@prometheus system]# netstat -anpt | grep 20001 
tcp6       0      0 :::20001                :::*                    LISTEN      1553/node_exporter  
[root@prometheus system]# systemctl enable node_exporter

使用浏览器进行访问


#安装docker
[root@prometheus system]# cd
[root@prometheus ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@prometheus ~]# ll
总用量 170976
-rw-------. 1 root root     1264 112 2021 anaconda-ks.cfg
drwxr-xr-x  3 root root     4096 85 10:38 docker
-rw-r--r--  1 root root 56363500 617 16:40 grafana-6.1.4-1.x86_64.rpm
-rw-r--r--  1 root root 51010897 85 10:08 influxdb-1.7.8.x86_64.rpm
-rw-r--r--  1 root root  8083296 710 16:51 node_exporter-0.18.1.linux-amd64.tar.gz
-rw-r--r--  1 root root 59608515 85 09:59 prometheus-2.16.0.linux-amd64.tar.gz
[root@prometheus ~]# vim /etc/yum.repos.d/centos.repo 
[aaa]
name=aaa
baseurl=file:///mnt
enabled=1
gpgcheck=0

[docker]
name=docker
baseurl=file:///root/docker
enabled=1
gpgcheck=0
#保存退出
[root@prometheus ~]# yum -y install docker-ce
[root@prometheus ~]# mkdir -p /etc/docker
[root@prometheus ~]# vim /etc/docker/daemon.json

  "registry-mirrors": ["https://w4uieobw.mirror.aliyuncs.com"]

#保存退出
[root@prometheus ~]# systemctl start docker
[root@prometheus ~]# systemctl status docker
#使用docker下载cAdvisor的镜像
[root@prometheus ~]# docker pull google/cadvisor

#开启容器,映射端口18104
[root@prometheus ~]# docker run \\  
  --volume=/:/rootfs:ro \\
  --volume=/var/run:/var/run:rw \\
  --volume=/sys:/sys:ro \\
  --volume=/var/lib/docker/:/var/lib/docker:ro \\
  --volume=/dev/disk/:/dev/disk:ro \\
  --publish=18104:8080\\
  --detach=true \\
  --name=cadvisor \\
  google/cadvisor:latest

#查看容器与镜像
[root@prometheus ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
google/cadvisor     latest              eb1210707573        2 years ago         69.6MB
[root@prometheus ~]# docker ps  #成功启动容器
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                     NAMES
1aab729a1d2d        google/cadvisor:latest   "/usr/bin/cadvisor -…"   3 minutes ago       Up 3 minutes        0.0.0.0:18104->8080/tcp   cadvisor

使用浏览器进行访问

访问http://192.168.100.210:18104/containers/进入cadvisor的web界面


访问http://192.168.100.210:18104/metrics可以看到cadvisor给prometheus暴露出来的信息

3、在被监控端安装

**安装 exporter+docker+cAdvisor **

#下面操作都是被监控端进行
[root@docker ~]# yum install -y yum-utils device-mapper-persistent-data lvm2

#上传yun仓库进行安装
[root@docker ~]# ll
总用量 8
-rw-------. 1 root root 1264 112 2021 anaconda-ks.cfg
drwxr-xr-x  3 root root 4096 85 10:21 docker
[root@docker ~]# vim /etc/yum.repos.d/centos.repo 
[aaa]
name=aaa
baseurl=file:///mnt
enabled=1
gpgcheck=0

[docker]
name=docker
baseurl=file:///root/docker
enabled=1
gpgcheck=0
#保存退出
[root@docker ~]# yum -y install docker-ce
[root@docker ~]# mkdir -p /etc/docker/
[root@docker ~]# vim /etc/docker/daemon.json

  "registry-mirrors": ["https://w4uieobw.mirror.aliyuncs.com"]

#保存退出
[root@docker ~]# systemctl start docker
[root@docker ~]# systemctl status docker
#安装exporter
#上传软件包进行安装
[root@docker ~]# ll
总用量 7904
-rw-------. 1 root root    1264 112 2021 anaconda-ks.cfg
drwxr-xr-x  3 root root    4096 85 10:21 docker
-rw-r--r--  1 root root 8083296 710 16:51 node_exporter-0.18.1.linux-amd64.tar.gz
[root@docker ~]# tar xf node_exporter-0.18.1.linux-amd64.tar.gz 
[root@docker ~]# mv node_exporter-0.18.1.linux-amd64 /usr/local/exporter
[root@docker ~]# cd /usr/lib/systemd/system
[root@docker system]# vim node_exporter.service
[Unit]
Description=node_exporter
After=network.target

[Service]
User=prometheus
Group=prometheus
ExecStart=/usr/local/exporter/node_exporter --web.listen-address=:20001 --collector.systemd --collector.systemd.unit-whitelist=(sshd|nginx).service --collector.processes --collector.tcpstat
[Install]
WantedBy=multi-user.target
#保存退出
[root@docker system]# systemctl daemon-reload
[root@docker system]#  useradd prometheus
[root@docker system]# systemctl start node_exporter
[root@docker system]# systemctl status node_exporter
[root@docker system]# netstat -anpt | grep 20001
tcp6       0      0 :::20001                :::*                    LISTEN      16595/node_exporter 
[root@docker system]# systemctl enable node_exporter

使用浏览器进行访问测试,

#安装cadvisor
[root@docker ~]# docker images   #同样下载cadvisor镜像
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
google/cadvisor     latest              eb1210707573        2 years ago         69.6MB
[root@docker ~]# docker run \\
  --volume=/:/rootfs:ro \\
  --volume=/var/run:/var/run:rw \\
  --volume=/sys:/sys:ro \\
  --volume=/var/lib/docker/:/var/lib/docker:ro \\
  --volume=/dev/disk/:/dev/disk:ro \\
  --publish=18104:8080\\
  --detach=true \\
  --name=cadvisor \\
  google/cadvisor:latest
[root@docker ~]# docker ps 
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                     NAMES
b0719f301f48        google/cadvisor:latest   "/usr/bin/cadvisor -…"   27 seconds ago      Up 26 seconds       0.0.0.0:18104->8080/tcp   cadvisor

使用浏览器进行访问测试


4、修改prometheus主配置文件

#在监控端修改配置文件
[root@prometheus ~]# cd /usr/local/prometheus/
[root@prometheus prometheus]# vim prometheus.yml
。。。。。。
 28     static_configs:
 29     - targets: ['localhost:9090']
 30   - job_name: 'node1'            #增加一个监控节点的job
 31     static_configs:
 32     - targets:
 33       - "192.168.100.208:20001"    #节点的端口是20001       
 34   - job_name: 'docker'           #增加两个监控容器的job
 35     static_configs:
 36     - targets: ['192.168.100.210:18104','192.168.100.208:18104'] #容器的两个端口是18104,在上面启动容器时指定的
 37 remote_write:
 38   - url: "http://localhost:8086/api/v1/prom/write?db=prometheus"
 39 
 40 remote_read:
 41   - url: "http://localhost:8086/api/v1/prom/read?db=prometheus"
#保存退出

#重启prometheus
[root@prometheus prometheus]# systemctl restart prometheus #重启
[root@prometheus prometheus]# systemctl status prometheus  #查看状态

5、测试访问prometheus的web界面

6、使用Grafana来进行监控



  • 1860模板监控节点


监控节点的界面

  • 893模板是监控容器的


监控容器的界面



部署prometheus+grafana监控docker(代码片段)

文章目录部署Prometheus+Grafana监控Docker(1)实验环境(2)实验步骤1、先做基础配置2、在监控端安装服务3、在被监控端安装4、修改prometheus主配置文件5、测试访问prometheus的web界面6、使用Grafana来进行监控部署Prom... 查看详情

k8s+prometheus+grafana的监控部署(代码片段)

...署k8s集群可以参考https://www.cnblogs.com/liugp/p/12115945.html二、Prometheus+Grafana的监控部署2.1、master/node节点环境部署在【master】可以进行安装部署安装git,并下载相关yaml文件https://gitee.com/liugpwwwroot/k8s-prometheus-grafana.git在【node】节点下... 查看详情

prometheus+grafana部署监控docker服务(代码片段)

1.环境192.168.244.128Prometheus监控服务器192.168.244.129docker服务(被监控端)注:都是centos7.5系统2.下载安装包https://prometheus.io/download/(需要的安装包都可以下载)wgethttps://github.com/prometheus/prometheus/releases/download/v2.3.2/p 查看详情

kubernetes第七篇:使用kubernetes部署prometheus+grafana监控系统(kubernetes工作实践类)

...录​​一、前言​​​​二、K8s监控系统架构​​​​2.1Prometheus简介​​​​2.2Prometheus架构​​​​2.3Prometheus知识普及​​​​三、K8s监控系统搭建​​​​3.1三类数据采集metrics​​​​3.2Prometheus+Grafana​​​​3.3实践一下... 查看详情

prometheus+grafana告警,监控部署展示(代码片段)

服务器信息监控服务器目录:/home/monitor/nginx代理服务器配置文件:/home/nginx/con.d/monitor被监控服务器服务部署数据采集#客户端#node-exporter主机监控修改对应主机名dockerrun-d--namenode-exporter-h主机名--restart=always-p9100:9100-v"... 查看详情

prometheus+grafana系统部署,linuxflink的监控与告警(代码片段)

目录版本阅读说明一、简介PrometheusGrafana安装规划二、安装Prometheus1下载安装包2配置使用Systemd管理Prometheus3启动Prometheus4页面大致介绍(可选)5常用命令(可选)1删除job数据2热重载配置规则二、安装Grafana1添加repo... 查看详情

centos7下部署prometheus+grafana超炫监控(代码片段)

1.环境说明监控主机被监控主机192.168.0.66192.168.0.67运维主机MySQL2.主机安装Prometheus下载:https://prometheus.io/download/上传到主机[[email protected]~]#yum-y×××tallvimlrzsz3.安装go[[email protected]~]#yum-y×××tallepel-re 查看详情

prometheus-operator结合grafana展示k8s监控

1.接上篇:kubernetes全面监控之prometheus-operator部署部署完成后,其实本身已经部署了grafana,也可以正常访问。但是我感觉太单调,数据不够详实。2.产生个想法,再多部署一套grafana,然后数据源使用prometheus-operator的数据源,再选... 查看详情

prometheus(普罗米修斯)安装部署(代码片段)

文章目录普罗米修斯1.环境准备2.安装prometheus3.prometheus界面4.监控远程linux主机5.监控远程mysql二、grafana1.使用grafana连接prometheus2.grafana图形显示mysql监控数据3.grafana+onealert报警普罗米修斯官网Prometheus(由go语言(golang)开发)是一套... 查看详情

prometheus(普罗米修斯)安装部署(代码片段)

文章目录普罗米修斯1.环境准备2.安装prometheus3.prometheus界面4.监控远程linux主机5.监控远程mysql二、grafana1.使用grafana连接prometheus2.grafana图形显示mysql监控数据3.grafana+onealert报警普罗米修斯官网Prometheus(由go语言(golang)开发)是一套... 查看详情

基于docker部署prometheus+grafana

参考技术A启动node-exporter启动prometheus启动grafanalinux监控模板ID:11074关于新增监控设备,只需要把IP写入ip文件,执行addjson.sh生产文件即可,系统6s扫描一次文件,一个机器对应一个json文件。至此部署完成! 查看详情

kubernetes_08_使用kubernetes部署prometheus+grafana监控系统(kubernetes工作实践类)(代码片段)

文章目录一、前言二、K8s监控系统架构2.1Prometheus简介2.2Prometheus架构2.3Prometheus知识普及三、K8s监控系统搭建3.1三类数据采集metrics3.2Prometheus+Grafana3.3实践一下:将prometheus+grafana搭建起来3.3.1搭建3.3.2分步测试3.3.2.1安装nodee... 查看详情

k8s的kafka监控(prometheus+grafana)

欢迎访问我的GitHub对于部署在K8S上的Kafka来说,Prometheus+Grafana是常用的监控方案,今天就来实战通过Prometheus+Grafana监控K8S环境的Kafka;准备工作今天聚焦的是Kafka监控,因此需要K8S、Helm、Kafka、Prometheus、Grafana等服务都已就绪,下... 查看详情

kubernetes第七篇:使用kubernetes部署prometheus+grafana监控系统(kubernetes工作实践类)(代码片段)

文章目录一、前言二、K8s监控系统架构2.1Prometheus简介2.2Prometheus架构2.3Prometheus知识普及三、K8s监控系统搭建3.1三类数据采集metrics3.2Prometheus+Grafana3.3实践一下:将prometheus+grafana搭建起来3.3.1搭建3.3.2分步测试3.3.2.1安装nodee... 查看详情

监控系统—prometheus部署(代码片段)

...1.1主要特性1.2原理架构图二、服务部署2.1准备工作2.2开启Prometheus服务器2.3设置被监控端2.4被监控端添加mysql服务三、设置Grafana可视化图形工具3.1服务安装3.2浏览器访问3.3Grafana图形显示mysql监控数据四、Grafana+onealert报警一、概... 查看详情

监控系统—prometheus部署(代码片段)

...1.1主要特性1.2原理架构图二、服务部署2.1准备工作2.2开启Prometheus服务器2.3设置被监控端2.4被监控端添加mysql服务三、设置Grafana可视化图形工具3.1服务安装3.2浏览器访问3.3Grafana图形显示mysql监控数据四、Grafana+onealert报警一、概... 查看详情

mysql:9为数据库部署prometheus+grafana监控系统(代码片段)

1.Prometheus和Grafana的介绍Prometheus是一个监控数据采集和存储系统,它可以利用监控数据采集组件(比如mysql_export)从你指定的MySQL数据库中采集他需要的监控数据,然后他自己有一个时序数据库,它会把采集到... 查看详情

prometheus+grafana+钉钉部署一个单机的mysql监控告警系统(代码片段)

...权不得随意使用,转载请联系小编并注明来源。一、Prometheus二、exporter2.1node_exporter2.2mysqld_exporter三、grafana3.1部署3.2配置数据源3.3配置监控模板四、alertmanager4.1配置alertmanager服务4.2配置dingding告警4.3配置rule五、总结一、Pro 查看详情