Prometheus容器化部署的实践方案
程序员文章站
2022-03-01 20:08:39
环境 主机名 ip地址 服务 prome...
环境
主机名 | ip地址 | 服务 |
---|---|---|
prometheus | 192.168.237.137 | prometheus、grafana |
node-exporter | 192.168.237.131 | node_exporter |
容器化部署prometheus
1、安装docker
[root@prometheus ~]# docker version client: docker engine - community version: 20.10.11 api version: 1.41 go version: go1.16.9 git commit: dea9396 built: thu nov 18 00:36:58 2021 os/arch: linux/amd64 context: default experimental: true server: docker engine - community engine: version: 20.10.11 api version: 1.41 (minimum version 1.12) go version: go1.16.9 git commit: 847da18 built: thu nov 18 00:35:20 2021 os/arch: linux/amd64 experimental: false containerd: version: 1.4.12 gitcommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d runc: version: 1.0.2 gitcommit: v1.0.2-0-g52b36a2 docker-init: version: 0.19.0 gitcommit: de40ad0
2、运行prometheus容器
//拉取镜像 [root@prometheus ~]# docker pull prom/prometheus using default tag: latest latest: pulling from prom/prometheus 3cb635b06aa2: pull complete 34f699df6fe0: pull complete 33d6c9635e0f: pull complete f2af7323bed8: pull complete c16675a6a294: pull complete 827843f6afe6: pull complete 3d272942eeaf: pull complete 7e785cfa34da: pull complete 05e324559e3b: pull complete 170620261a59: pull complete ec35f5996032: pull complete 5509173eb708: pull complete digest: sha256:cb9817249c346d6cfadebe383ed3b3cd4c540f623db40c4ca00da2ada45259bb status: downloaded newer image for prom/prometheus:latest docker.io/prom/prometheus:latest //在/opt目录下提供prometheus的默认配置文件 [root@prometheus ~]# ls /opt/ prometheus.yml //运行容器 ##--restart always 总是重启,开机自启 ## 将本地提供的配置文件映射到容器,ro 容器内只读 [root@prometheus ~]# docker run --name prometheus -d --restart always -p 9090:9090 -v /opt/prometheus.yml:/etc/prometheus/prometheus.yml:ro prom/prometheus:latest a0ba5535f0ea3b0f44574fd237802f2ef19f4624c3752c3bf8122a4d79a26428 [root@prometheus ~]# docker ps container id image command created status ports names a0ba5535f0ea prom/prometheus:latest "/bin/prometheus --c…" 11 seconds ago up 11 seconds 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp prometheus //查看端口 [root@prometheus ~]# ss -anltu netid state recv-q send-q local address:port peer address:port process tcp listen 0 128 0.0.0.0:22 0.0.0.0:* tcp listen 0 128 0.0.0.0:9090 0.0.0.0:* tcp listen 0 128 [::]:22 [::]:* tcp listen 0 128 [::]:9090 [::]:*
使用ip+9090/targets访问prometheus默认网页
部署node_exporter
//下载安装包 [root@node-exporter ~]# wget https://github.com/prometheus/node_exporter/releases/download/v1.3.0/node_exporter-1.3.0.linux-amd64.tar.gz [root@node-exporter ~]# ls anaconda-ks.cfg node_exporter-1.3.0.linux-amd64.tar.gz //解压 [root@node-exporter ~]# tar xf node_exporter-1.3.0.linux-amd64.tar.gz -c /usr/local/ [root@node-exporter ~]# mv /usr/local/node_exporter-1.3.0.linux-amd64/ /usr/local/node_exporter [root@node-exporter ~]# ls /usr/local/ bin etc games include lib lib64 libexec node_exporter sbin share src //编写service文件,启动并开机自启 [root@node-exporter ~]# cat /usr/lib/systemd/system/node_exporter.service [unit] description=the node_exporter server after=network.target [service] execstart=/usr/local/node_exporter/node_exporter restart=on-failure restartsec=15s syslogidentifier=node_exporter [install] wantedby=multi-user.target [root@node-exporter ~]# systemctl daemon-reload [root@node-exporter ~]# systemctl enable --now node_exporter.service created symlink from /etc/systemd/system/multi-user.target.wants/node_exporter.service to /usr/lib/systemd/system/node_exporter.service. [root@node-exporter ~]# systemctl status node_exporter.service ● node_exporter.service loaded: loaded (/usr/lib/systemd/system/node_exporter.service; enabled; vendor preset: disabled) active: active (running) since 四 2021-12-30 19:26:59 cst; 8s ago main pid: 27878 (node_exporter) cgroup: /system.slice/node_exporter.service └─27878 /usr/local/node_exporter/node_exporter //查看端口 [root@node-exporter ~]# ss -anltu netid state recv-q send-q local address:port peer address:port tcp listen 0 128 *:22 *:* tcp listen 0 128 [::]:22 [::]:* tcp listen 0 128 [::]:9100 [::]:* ## node-exporter部署成功就可以在prometheus主机上添加节点进行监控
添加节点到prometheus中
修改本地prometheus.yml文件
//修改配置文件 [root@prometheus ~]# tail -8 /opt/prometheus.yml scrape_configs: # the job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: "prometheus" static_configs: - targets: ["localhost:9090"] - job_name: "centos" //指定一个工作名称 static_configs: - targets: ["192.168.237.131:9100"] //指定node-exporter节点的ip和端口号 ## 如果有多个节点 - job_name: "centos" static_configs: - targets: - "192.168.237.131:9100" - "192.168.237.132:9100" - "192.168.237.133:9100" //重启容器,重新读取配置文件 [root@prometheus ~]# docker restart prometheus prometheus [root@prometheus ~]# docker ps container id image command created status ports names a0ba5535f0ea prom/prometheus:latest "/bin/prometheus --c…" 26 minutes ago up 3 seconds 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp prometheus
访问prometheus默认网页
成功添加节点
部署grafana画图工具
//拉取grafan/grafan官方镜像 [root@prometheus ~]# docker pull grafana/grafana using 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 [root@prometheus ~]# docker images repository tag image id created size prom/prometheus latest a3d385fc29f9 12 days ago 201mb grafana/grafana latest 9b957e098315 2 weeks ago 275mb //使用官方grafana镜像运行容器 [root@prometheus ~]# docker run -d --name grafana -p 3000:3000 --restart always grafana/grafana 0b5986fc63442538a6fae845e5d1b8afc78caec4f4bdd81ca3623eb1329ad562 [root@prometheus ~]# docker ps container id image command created status ports names 0b5986fc6344 grafana/grafana "/run.sh" 4 seconds ago up 2 seconds 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp grafana a0ba5535f0ea prom/prometheus:latest "/bin/prometheus --c…" 33 minutes ago up 6 minutes 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp prometheus //查看端口 [root@prometheus ~]# ss -anltu netid state recv-q send-q local address:port peer address:port process tcp listen 0 128 0.0.0.0:22 0.0.0.0:* tcp listen 0 128 0.0.0.0:3000 0.0.0.0:* tcp listen 0 128 0.0.0.0:9090 0.0.0.0:* tcp listen 0 128 [::]:22 [::]:* tcp listen 0 128 [::]:3000 [::]:* tcp listen 0 128 [::]:9090 [::]:*
使用prometheus主机ip地址192.168.129.205 + 端口号3000在浏览器中访问
默认账号:admin 密码:admin
修改密码
首页
添加数据源
数据源选择prometheus
导入仪表盘
模板地址
模板id为9276
效果图
到此这篇关于prometheus容器化部署的文章就介绍到这了,更多相关prometheus容器化部署内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
上一篇: 导出与导入Docker的容器实现示例
下一篇: docker安装RabbitMQ详细步骤
推荐阅读
-
谈谈surging引擎的tcp、http、ws协议和如何容器化部署
-
浅谈surging服务引擎中的rabbitmq组件和容器化部署
-
容器化 | 基于 Kubernetes 的新一代 MySQL 高可用架构实现方案
-
Prometheus+Alertmanager+Grafana监控组件容器化部署
-
Prometheus容器化部署的实践方案
-
谈谈surging引擎的tcp、http、ws协议和如何容器化部署
-
浅谈surging服务引擎中的rabbitmq组件和容器化部署
-
使用Portainer部署Docker容器的项目实践
-
学习Docker19.03的第九章——微服务Docker容器化自动部署之环境准备(二)
-
Docker 服务容器化部署的利器