部署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

目录
相关文章
|
7月前
|
Prometheus 监控 Cloud Native
云原生监控实战:Prometheus+Grafana快速搭建指南
云原生监控实战:Prometheus+Grafana快速搭建指南
|
7月前
|
存储 Prometheus 监控
OSS监控体系搭建:Prometheus+Grafana实时监控流量、错误码、存储量(开源方案替代云监控自定义视图)
本方案基于Prometheus构建OSS监控系统,涵盖架构设计、指标采集、可视化、告警及性能优化,助力企业实现高可用、低成本的自建监控体系。
697 1
|
8月前
|
Prometheus 监控 Cloud Native
除了Prometheus,还有哪些工具可以监控Docker Swarm集群的资源使用情况?
除了Prometheus,还有哪些工具可以监控Docker Swarm集群的资源使用情况?
624 79
|
7月前
|
存储 监控 Cloud Native
云原生监控实战:Prometheus+Grafana打造RDS多维度预警体系
本方案构建了基于Prometheus与Thanos的云原生RDS监控体系,涵盖数据采集、存储、可视化与告警全流程。支持10万+QPS采集、90%存储压缩,具备<30秒告警延迟能力。通过自定义指标与智能预警策略,显著提升故障发现效率,实现分钟级响应。
524 5
|
7月前
|
Prometheus 监控 Cloud Native
|
6月前
|
Prometheus 监控 Cloud Native
Docker 部署 Prometheus 和 Grafana 监控 Spring Boot 服务
Docker 部署 Prometheus 和 Grafana 监控 Spring Boot 服务实现步骤
614 0
|
Prometheus 运维 监控
智能运维实战:Prometheus与Grafana的监控与告警体系
【10月更文挑战第26天】Prometheus与Grafana是智能运维中的强大组合,前者是开源的系统监控和警报工具,后者是数据可视化平台。Prometheus具备时间序列数据库、多维数据模型、PromQL查询语言等特性,而Grafana支持多数据源、丰富的可视化选项和告警功能。两者结合可实现实时监控、灵活告警和高度定制化的仪表板,广泛应用于服务器、应用和数据库的监控。
1263 3
|
10月前
|
Prometheus Kubernetes 监控
Kubernetes监控:Prometheus与AlertManager结合,配置邮件告警。
完成这些步骤之后,您就拥有了一个可以用邮件通知你的Kubernetes监控解决方案了。当然,所有的这些配置都需要相互照应,还要对你的Kubernetes集群状况有深入的了解。希望这份指南能帮助你创建出适合自己场景的监控系统,让你在首次发现问题时就能做出响应。
551 22
|
存储 数据采集 Prometheus
Grafana Prometheus Altermanager 监控系统
Grafana、Prometheus 和 Alertmanager 是一套强大的开源监控系统组合。Prometheus 负责数据采集与存储,Alertmanager 处理告警通知,Grafana 提供可视化界面。本文简要介绍了这套系统的安装配置流程,包括各组件的下载、安装、服务配置及开机自启设置,并提供了访问地址和重启命令。适用于希望快速搭建高效监控平台的用户。
703 20
|
Prometheus 监控 Cloud Native
Prometheus+Grafana监控Linux主机
通过本文的步骤,我们成功地在 Linux 主机上使用 Prometheus 和 Grafana 进行了监控配置。具体包括安装 Prometheus 和 Node Exporter,配置 Grafana 数据源,并导入预设的仪表盘来展示监控数据。通过这种方式,可以轻松实现对 Linux 主机的系统指标监控,帮助及时发现和处理潜在问题。
1106 7

热门文章

最新文章