部署Prometheus+Grafana监控Docker(上)

简介: 部署Prometheus+Grafana监控Docker(上)

部署Prometheus+Grafana监控Docker


(1)实验环境


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


系统 主机名 ip 安装软件 扮演角色
Centos7.4 Prometheus 192.168.100.210 prometheus+Grafana+exporter+cAdvisor+influxdb+docker 监控端
Centos7.4 Docker 192.168.100.208 exporter+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 1月  12 2021 anaconda-ks.cfg
-rw-r--r--  1 root root 59608515 8月   5 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 2月  14 2020 console_libraries
drwxr-xr-x 2 3434 3434      173 2月  14 2020 consoles
drwxr-xr-x 3 root root       51 8月   5 10:00 data
-rw-r--r-- 1 3434 3434    11357 2月  14 2020 LICENSE
-rw-r--r-- 1 3434 3434     3184 2月  14 2020 NOTICE
-rwxr-xr-x 1 3434 3434 82329106 2月  14 2020 prometheus
-rw-r--r-- 1 3434 3434      926 2月  14 2020 prometheus.yml
-rwxr-xr-x 1 3434 3434 48417809 2月  14 2020 promtool
-rwxr-xr-x 1 3434 3434 13595766 2月  14 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

5523901d33d446f2879c84b6cfae567a.png


#安装influxdb数据库
#上传软件包进行安装
[root@prometheus system]# cd
[root@prometheus ~]# ll
总用量 108032
-rw-------. 1 root root     1264 1月  12 2021 anaconda-ks.cfg
-rw-r--r--  1 root root 51010897 8月   5 10:08 influxdb-1.7.8.x86_64.rpm
-rw-r--r--  1 root root 59608515 8月   5 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 1月  12 2021 anaconda-ks.cfg
-rw-r--r--  1 root root 56363500 6月  17 16:40 grafana-6.1.4-1.x86_64.rpm
-rw-r--r--  1 root root 51010897 8月   5 10:08 influxdb-1.7.8.x86_64.rpm
-rw-r--r--  1 root root 59608515 8月   5 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 

使用浏览器进行测试

bfbfba5d2855435aa8c3bc2607b1a518.png

7760aac163024947bdc23cb63ae385dd.png

4f159c3318a74b2e88a263cb38606fcd.png

#安装exporter
#上传软件包
[root@prometheus ~]# ll
总用量 170972
-rw-------. 1 root root     1264 1月  12 2021 anaconda-ks.cfg
-rw-r--r--  1 root root 56363500 6月  17 16:40 grafana-6.1.4-1.x86_64.rpm
-rw-r--r--  1 root root 51010897 8月   5 10:08 influxdb-1.7.8.x86_64.rpm
-rw-r--r--  1 root root  8083296 7月  10 16:51 node_exporter-0.18.1.linux-amd64.tar.gz
-rw-r--r--  1 root root 59608515 8月   5 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


使用浏览器进行访问

0dde70f08f3f48b9a64105ba6e132f0c.png

eb28edfe89a54c6db15a95ef47c2b355.png

#安装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 1月  12 2021 anaconda-ks.cfg
drwxr-xr-x  3 root root     4096 8月   5 10:38 docker
-rw-r--r--  1 root root 56363500 6月  17 16:40 grafana-6.1.4-1.x86_64.rpm
-rw-r--r--  1 root root 51010897 8月   5 10:08 influxdb-1.7.8.x86_64.rpm
-rw-r--r--  1 root root  8083296 7月  10 16:51 node_exporter-0.18.1.linux-amd64.tar.gz
-rw-r--r--  1 root root 59608515 8月   5 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界面


dd7a68f6b3704d97b3708ddf1d074b6f.png



92e07fdd5f8d4838b5f55519c812d723.png


6a8db847677a4e11a8f471e26f4a2199.png


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

f1ea2798b5bc46808735fc776a30eaa1.png

目录
相关文章
|
Prometheus 监控 Cloud Native
Prometheus配置docker采集器
本文介绍了如何使用 Prometheus 监控 Docker 容器,涵盖环境准备、配置文件编写及服务启动等步骤。首先确保安装 Docker 和 Docker Compose,接着通过 `docker-compose.yml` 配置 Prometheus 和示例应用。创建 `prometheus.yml` 指定数据采集目标,最后用 `docker-compose up -d` 启动服务。文章还展示了甘特图和类图,帮助理解服务状态与关系,助力提升系统可靠性和可维护性。
668 11
|
Prometheus 监控 Cloud Native
除了Prometheus,还有哪些工具可以监控Docker Swarm集群的资源使用情况?
除了Prometheus,还有哪些工具可以监控Docker Swarm集群的资源使用情况?
1014 79
|
Prometheus 运维 监控
智能运维实战:Prometheus与Grafana的监控与告警体系
【10月更文挑战第26天】Prometheus与Grafana是智能运维中的强大组合,前者是开源的系统监控和警报工具,后者是数据可视化平台。Prometheus具备时间序列数据库、多维数据模型、PromQL查询语言等特性,而Grafana支持多数据源、丰富的可视化选项和告警功能。两者结合可实现实时监控、灵活告警和高度定制化的仪表板,广泛应用于服务器、应用和数据库的监控。
1743 3
|
Prometheus 监控 Cloud Native
如何使用Prometheus监控Docker Swarm集群的资源使用情况?
还可以根据实际需求进行进一步的配置和优化,如设置告警规则,当资源使用超出阈值时及时发出警报。通过这些步骤,能够有效地使用 Prometheus 对 Docker Swarm 集群的资源进行监控和管理。
865 161
|
Prometheus 监控 Cloud Native
Prometheus+Grafana(docker安装)
本文档详细介绍了如何使用Docker容器快速部署Prometheus监控系统和Grafana数据可视化平台。该方案适用于需要快速搭建监控环境的开发测试场景,具备部署简单、资源占用低、易于维护等特点。
|
存储 数据采集 Prometheus
Grafana Prometheus Altermanager 监控系统
Grafana、Prometheus 和 Alertmanager 是一套强大的开源监控系统组合。Prometheus 负责数据采集与存储,Alertmanager 处理告警通知,Grafana 提供可视化界面。本文简要介绍了这套系统的安装配置流程,包括各组件的下载、安装、服务配置及开机自启设置,并提供了访问地址和重启命令。适用于希望快速搭建高效监控平台的用户。
1235 20
|
Prometheus 监控 Cloud Native
Prometheus+Grafana监控Linux主机
通过本文的步骤,我们成功地在 Linux 主机上使用 Prometheus 和 Grafana 进行了监控配置。具体包括安装 Prometheus 和 Node Exporter,配置 Grafana 数据源,并导入预设的仪表盘来展示监控数据。通过这种方式,可以轻松实现对 Linux 主机的系统指标监控,帮助及时发现和处理潜在问题。
1614 7
|
Prometheus 运维 监控
Prometheus+Grafana+NodeExporter:构建出色的Linux监控解决方案,让你的运维更轻松
本文介绍如何使用 Prometheus + Grafana + Node Exporter 搭建 Linux 主机监控系统。Prometheus 负责收集和存储指标数据,Grafana 用于可视化展示,Node Exporter 则采集主机的性能数据。通过 Docker 容器化部署,简化安装配置过程。完成安装后,配置 Prometheus 抓取节点数据,并在 Grafana 中添加数据源及导入仪表盘模板,实现对 Linux 主机的全面监控。整个过程简单易行,帮助运维人员轻松掌握系统状态。
2581 3
|
Prometheus 监控 前端开发
Grafana 安装配置教程,让你的 Prometheus 监控数据变得更美观
《Grafana安装配置教程,让你的Prometheus监控数据变得更美观》简介: Grafana是一个开源的度量分析与可视化工具,支持多种数据源(如Prometheus),提供丰富的可视化功能和警报机制。本文详细介绍了Grafana的安装、汉化方法及模板使用,帮助用户轻松创建美观、灵活的数据面板,并实现数据的协作与共享。通过Docker镜像、配置文件修改或替换前端页面等方式实现汉化,让用户更便捷地使用中文界面。此外,还提供了导入JSON格式模板的具体步骤,方便快速搭建仪表盘。
3360 2
|
Prometheus Cloud Native Linux
Prometheus+Grafana新手友好教程:从零开始搭建轻松掌握强大的警报系统
本文介绍了使用 Prometheus 和 Grafana 实现邮件报警的方案,包括三种主要方法:1) 使用 Prometheus 的 Alertmanager 组件;2) 使用 Grafana 的内置告警通知功能;3) 使用第三方告警组件如 OneAlert。同时,详细描述了环境准备、Grafana 安装配置及预警设置的步骤,确保用户能够成功搭建并测试邮件报警功能。通过这些配置,用户可以在系统或应用出现异常时及时收到邮件通知,保障系统的稳定运行。
2525 1

热门文章

最新文章