做网站后期维护工资贴吧,wordpress is ssl,做网站去哪里找模板,网站内容策划方案目录 案例概述
Cadvisor InfluxDBGrafana
1.1、 Cadvisor
1.2、InfluxDB
1.3、Grafana
1.4、监控组件架构
1.5、开始部署
安装docker-ce
阿里云镜像加速器
创建自定义网络
创建influxdb容器 案例概述 Docker作为目前十分出色的容器管理技术#xff0c;得到大量企业…目录 案例概述
Cadvisor InfluxDBGrafana
1.1、 Cadvisor
1.2、InfluxDB
1.3、Grafana
1.4、监控组件架构
1.5、开始部署
安装docker-ce
阿里云镜像加速器
创建自定义网络
创建influxdb容器 案例概述 Docker作为目前十分出色的容器管理技术得到大量企业的青睐在生产环境中使用Docker容器部署服务及应用的场景越来越多。所以面对日益庞大的docker服务群应用如何具有针对性的有效的监控也变成了企业运维人员工作需求。 容器信息采集及监控的方案有很多有docker自身的docker stats命令、Scout、Data Dog、Prometheus等本次为大家分享两款比较经典的容器开源监控组合方案Cadvisor InfluxDBGrafana和Cadvisor PrometheusGrafana。
Cadvisor InfluxDBGrafana
1.1、 Cadvisor Cadvisor 是Google用来监测单节点资源信息的监控工具。 Cadvisor 提供了基础查询界面和http接口方便其他组件如Grafana 、Prometheus等进行数据抓取。Cadvisor 可以对Docker主机上的资源及容器进行实时监控和性能数据采集包括CPU使用情况、内存使用情况、网络吞吐量及文件系统使用情况等。Cadvisor 使用Go语言开发利用Linux的Cgroups获取容器的资源使用信息。 Google的Kubernetes中也默认地将其作为单节点的资源监控工具各个节点默认会安装上Cadvisor组件。 Cadvisor 产品特点 可以展示主机和容器两个层次的监控数据。可以展示历史变化数据。谷歌公司的开源产品。监控指标齐全。方便部署有官方的docker镜像。默认只在本地保存1分钟数据可以集成InfluxDB等第三方存储使用。 由于 Cadvisor 提供的操作界面略显简陋而且需要在不同页面之间跳转并且只能监控一个 Host这不免会让人质疑它的实用性。但 Cadvisor 的一个亮点是它可以将监控到的数据导出给第三方工具由这些工具进一步加工处理。 我们可以把 Cadvisor 定位为一个监控数据收集器收集和导出数据是它的强项而非展示数据。
1.2、InfluxDB InfluxDB是一个由InfluxData开发的开源非关系型时序型数据库。它由Go写成着力于高性能地查询与存储时序型数据。InfluxDB被广泛应用于存储系统的监控数据IoT行业的实时数据等场景。同类型的数据库产品还有Elasticsearch、Graphite等。 InfluxDB应用场景性能监控应用程序指标物联网传感器数据和实时分析等的后端存储。 InfluxDB主要功能 基于时间序列支持与时间有关的相关函数如最大最小求和等可度量性你可以实时对大量数据进行计算基于事件它支持任意的事件数据 InfluxDB主要特点 无结构无模式可以是任意数量的列支持拓展支持min, max, sum, count, mean, median 等一系列函数方便统计原生的HTTP支持内置HTTP API强大的类SQL语法自带管理界面方便使用 1.3、Grafana Grafana是一个可视化面板Dashboard工具有着非常漂亮的图表和布局等展示功能功能齐全的度量仪表盘和图形编辑器支持Graphite、zabbix、InfluxDB、Prometheus和OpenTSDB等组件作为数据源。
Grafana主要特性 灵活丰富的图形化选项可以混合多种风格支持白天和夜间模式支持多个数据源 1.4、监控组件架构
监控组件架构图 提示InfluxDB用于数据存储Cadvisor 用户数据采集Grafana用于数据展示。 监控组件架构部署方案
创建自定义网络monitor自定义网络名称用于后期容器加入此网络中创建Influxdb容器创建数据用户、数据库创建Cadvisor 容器创建Grafana容器配置grafana 1.5、开始部署
安装docker-ce
[rootlocalhost ~]# iptables -F[rootlocalhost ~]# setenforce 0setenforce: SELinux is disabled[rootlocalhost ~]# systemctl stop firewalld[rootlocalhost ~]# cd /etc/yum.repos.d/[rootlocalhost ~]# wget http://mirrors.aliyun.com/repo/Centos-7.repo[rootlocalhost ~]# yum -y install yum-utils device-mapper-persistent-data lvm2[rootlocalhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo[rootlocalhost ~]# yum -y install docker-ce[rootlocalhost ~]# systemctl start docker[rootlocalhost ~]# systemctl enable docker[rootlocalhost ~]# docker versionClient: Docker Engine - CommunityVersion: 24.0.5API version: 1.43Go version: go1.20.6Git commit: ced0996Built: Fri Jul 21 20:39:02 2023OS/Arch: linux/amd64Context: defaultServer: Docker Engine - CommunityEngine:Version: 24.0.5API version: 1.43 (minimum version 1.12)Go version: go1.20.6Git commit: a61e2b4Built: Fri Jul 21 20:38:05 2023OS/Arch: linux/amd64Experimental: falsecontainerd:Version: 1.6.22GitCommit: 8165feabfdfe38c65b599c4993d227328c231fcarunc:Version: 1.1.8GitCommit: v1.1.8-0-g82f18fedocker-init:Version: 0.19.0GitCommit: de40ad0
阿里云镜像加速器
阿里云登录 - 欢迎登录阿里云安全稳定的云计算服务平台欢迎登录阿里云全球领先的云计算及人工智能科技公司阿里云为200多个国家和地区的企业、开发者和政府机构提供云计算基础服务及解决方案。阿里云云计算、安全、大数据、人工智能、企业应用、物联网等云计算服务。https://cr.console.aliyun.com/
[rootlocalhost ~]# cat END /etc/docker/daemon.json{registry-mirrors:[ https://nyakyfun.mirror.aliyuncs.com ]
}
END[rootlocalhost ~]# systemctl daemon-reload[rootlocalhost ~]# systemctl restart docker 下载组件镜像
[rootlocalhost ~]# docker pull tutum/influxdbUsing default tag: latest
latest: Pulling from tutum/influxdb
a3ed95caeb02: Pull complete
23efb549476f: Pull complete
aa2f8df21433: Pull complete
ef072d3c9b41: Pull complete
c9f371853f28: Pull complete
a248b0871c3c: Pull complete
749db6d368d0: Pull complete
db2492acfcc3: Pull complete
b7e7d2e12d53: Pull complete
4272a53eef10: Pull complete
9b2fefdb5321: Pull complete
Digest: sha256:5b7c5e318303ad059f3d1a73d084c12cb39ae4f35f7391b79b0ff2c0ba45304b
Status: Downloaded newer image for tutum/influxdb:latest
docker.io/tutum/influxdb:latest[rootlocalhost ~]# docker pull google/cadvisorUsing default tag: latest
latest: Pulling from google/cadvisor
ff3a5c916c92: Pull complete
44a45bb65cdf: Pull complete
0bbe1a2fe2a6: Pull complete
Digest: sha256:815386ebbe9a3490f38785ab11bda34ec8dacf4634af77b8912832d4f85dca04
Status: Downloaded newer image for google/cadvisor:latest
docker.io/google/cadvisor:latest[rootlocalhost ~]# docker pull grafana/grafanaUsing default tag: latest
latest: Pulling from grafana/grafana
97518928ae5f: Pull complete
5b58818b7f48: Pull complete
d9a64d9fd162: Pull complete
4e368e1b924c: Pull complete
867f7fdd92d9: Pull complete
387c55415012: Pull complete
07f94c8f51cd: Pull complete
ce8cf00ff6aa: Pull complete
e44858b5f948: Pull complete
4000fdbdd2a3: Pull complete
Digest: sha256:18d94ae734accd66bccf22daed7bdb20c6b99aa0f2c687eea3ce4275fe275062
Status: Downloaded newer image for grafana/grafana:latest
docker.io/grafana/grafana:latest[rootlocalhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE
grafana/grafana latest 9b957e098315 20 months ago 275MB
google/cadvisor latest eb1210707573 4 years ago 69.6MB
tutum/influxdb latest c061e5808198 6 years ago 290MB创建自定义网络 为了把后期创建的CadvisorInfluxDBGrafana这三个容器都加入自己定义的网络便于理解和管理所以才新建一个自定义网络。
[rootlocalhost ~]# docker network create monitorbfe09a56d338b3173da008204dac13e46873ab8c46601683bba6457178e7dbcc[rootlocalhost ~]# docker network lsNETWORK ID NAME DRIVER SCOPE
dbe5fb2353e8 bridge bridge local
fc4521838733 host host local
bfe09a56d338 monitor bridge local
4e2c57eec484 none null local创建influxdb容器
启动容器tutum/influxdb镜像这里没有指定版本默认会pull最新版本的influxdb
[rootlocalhost ~]# docker run -d --name influxdb --net monitor -p 8083:8083 -p 8086:8086 tutum/influxdbec8e368b7d5e6f7b525fc823fdcc2c9f3d8665712645babcf0bba8bfeffe18a3参数说明 -d 后台运行此容器--name 启运容器分配名字influxdb--net : 把容器加入到新的网络monitor-p 映射端口8083端口为infuxdb后台控制端口8086端口是infuxdb的数据端口tutum/influxdb通过这个容器来运行的默认会在docker官方仓库pull下来 查看influxdb容器是否启动
[rootlocalhost ~]# docker ps -lCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ec8e368b7d5e tutum/influxdb /run.sh 45 seconds ago Up 43 seconds 0.0.0.0:8083-8083/tcp, :::8083-8083/tcp, 0.0.0.0:8086-8086/tcp, :::8086-8086/tcp influxdb访问influxdb控制台http://192.168.2.118:8083; 从上图可以看到在Query Templates选项中提供了常用的操作模板可根据这些模版来管理influxdb,下面我们就来创建数据库和数据库用户。
CREATE USER root WITH PASSWORD 123456 WITH ALL PRIVILEGES 创建Cadvisor 数据库cadvisor 、用户root用户和数据库大家可以自行随意定义用于后期grafana的配置
CREATE DATABASE cadvisor 创建Cadvisor 容器
[rootlocalhost ~]# docker run -d --volume/:/rootfs:ro --volume/var/run:/var/run:rw --volume/sys:/sys:ro --volume/var/lib/docker/:/var/lib/docker:ro --net monitor --publish8080:8080 --namecadvisor google/cadvisor -storage_driverinfluxdb -storage_driver_dbcadvisor -storage_driver_hostinfluxdb:80863090cec78b680888f6c14776b3aaaa785676577fe2f781a09373a2a43397a1ac-d后台运行此容器--name启运容器分配名字Cadvisor --net把容器加入到新的网络monitor-p映射端口8080--mout把宿主机的相文目录绑定到容器中这些目录都是Cadvisor 需要采集的目录文件和监控内容-storage_driver需要指定Cadvisor 的存储驱动、数据库主机、数据库名google/Cadvisor 通过Cadvisor 这个镜像来运行容器默认会在docker官方仓库把镜像pull下来 查看Cadvisor 容器 [rootlocalhost ~]# docker ps -lCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3090cec78b68 google/cadvisor /usr/bin/cadvisor -… About a minute ago Up About a minute 0.0.0.0:8080-8080/tcp, :::8080-8080/tcp cadvisor通过http://192.168.2.118:8080端口访问测试一下第一次访问这个页面有点慢 从上图可以看到其实Cadvisor 也有基础的图形展示功能我们这里主要用它来做数据采集。 准备测试镜像
[rootlocalhost ~]# docker run -itd --name nginx -p 800:80 nginxUnable to find image nginx:latest locally
latest: Pulling from library/nginx
648e0aadf75a: Pull complete
262696647b70: Pull complete
e66d0270d23f: Pull complete
55ac49bd649c: Pull complete
cbf42f5a00d2: Pull complete
8015f365966b: Pull complete
4cadff8bc2aa: Pull complete
Digest: sha256:67f9a4f10d147a6e04629340e6493c9703300ca23a2f7f3aa56fe615d75d31ca
Status: Downloaded newer image for nginx:latest
19eb36575c3e16b5ebbc94cdd89d7c7f89642f223eab8d9190e8070b33a6714b[rootlocalhost ~]# docker images nginxREPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 89da1fb6dcb9 11 days ago 187MB[rootlocalhost ~]# docker ps -lCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
19eb36575c3e nginx /docker-entrypoint.… About a minute ago Up About a minute 0.0.0.0:800-80/tcp, :::800-80/tcp nginx创建granafa容器
[rootlocalhost ~]# docker run -d --name grafana --net monitor -p 3000:3000 grafana/grafana1850cc7d09fd452a20ff2c995de92073bb094c4aec0e8cbf88ec92e62fe1c581查看运行结果
[rootlocalhost ~]# docker ps -lCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1850cc7d09fd grafana/grafana /run.sh 48 seconds ago Up 47 seconds 0.0.0.0:3000-3000/tcp, :::3000-3000/tcp grafana访问granfana通过http://192.168.2.118:3000端口的方式访问,默认账户密码admin/admin首次登陆需要更新密码。 添加数据源Add data source如下图 新建 Dashboard如下图 到这里CadvisorInfluxDBGrafana容器监控系统就部署完成了至于其它grafana的监控项配置不重点介绍。大家如果感兴趣可以参考一些官方资料都是图形化的界面操作。