欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 焦点 > 四、监控搭建-Prometheus-采集端批量部署

四、监控搭建-Prometheus-采集端批量部署

2026/2/12 17:39:22 来源:https://blog.csdn.net/shallow72/article/details/141603831  浏览:    关键词:四、监控搭建-Prometheus-采集端批量部署

四、监控搭建-Prometheus-采集端批量部署

  • 1、背景
  • 2、目标
  • 3、传承
  • 4、操作
    • 4.1、准备部署工具
    • 4.2、编制部署脚本
    • 4.3、服务端添加客户端

1、背景

在前三篇中我们搭建了Prometheus平台,采集端部署和配合图形化grafana部署,将Linux主机进行监控。基本完成了一个最小化的监控模型,本篇是在前三篇的基础上继续操作。在日常使用中很少只有单台设备而是多态设备和服务进行统一化,集中监控。利用ansible自动化工具批量部署node_exporter客户端。

2、目标

使用prometheus平台批量部署,监控Linux主机资源。

3、传承

本篇操作依赖《一、监控搭建-Prometheus》、《二、监控搭建-Prometheus-采集端部署》和《三、监控搭建-Prometheus-grafana部署》的基础上的操作。操作端安装ansible工具,不在本篇做介绍,安装参考ansible安装中文文档
以上安装步骤很全面,也可以参考[环境搭建]-[局域网ansible离线安装]。

4、操作

4.1、准备部署工具

将上篇中的软件包下载至本地

Linux系统采集模块: node_exporter 下载

上传至指定目录,本篇以/home/backup/prometheus目录为例。

4.2、编制部署脚本

切换到部署文件的目录下

cd /home/backup/prometheus

创建deploy_node_exporter.yml文件并输入如下内容
脚本内容分为七步操作:

  • 将客户端工具解压至客户端服务器的指定目录
  • 重命名解压缩后的文件夹
  • 创建文件夹的软链接
  • 上传客户端服务器文件
  • 启动监控客户端
  • 启动监控客户端
  • 启动服务器防火墙
  • 添加客户端监控端口
---
- name: deploy the node_exporterhosts: procgather_facts: nobecome: yesremote_user: roottasks:- name: 01-Extract node_exporterunarchive:src: /home/backup/prometheus/node_exporter-1.6.1.linux-amd64.tar.gzdest: /usr/local- name: 02-Rename floder nameshell:cmd: mv /usr/local/node_exporter-1.6.1.linux-amd64 /usr/local/node_exporter-1.6.1- name: 03-Creating soft connectionsfile:src: /usr/local/node_exporter-1.6.1dest: /usr/local/node_exporterstate: link- name: 04-Copy the node_exporter.service to the client copy:src: /usr/lib/systemd/system/node_exporter.servicedest: /usr/lib/systemd/system- name: 05-Start the service of node_exportersystemd:name: node_exporterstate: startedenabled: yes- name: 06-Start the service of firewalldsystemd:name: firewalldstate: startedenabled: yes- name: 07-Set Firewall Policesfirewalld:port: 9100/tcpstate: enabledpermanent: yesimmediate: yes

查看脚本预防错误

ansible-playbook --syntax-check deploy_node_exporter.yml 

模拟运行脚本

ansible-playbook -C deploy_node_exporter.yml 

以上两步运行无报错提示,则运行以上脚本进行操作部署

ansible-playbook -C deploy_node_exporter.yml PLAY [deploy the node_exporter] ********************************************************************************************TASK [01-Extract node_exporter] ********************************************************************************************
changed: [proc-dese2]
changed: [proc-divu1]
changed: [proc-dese1]
changed: [proc-divu2]TASK [02-Rename floder name] ***********************************************************************************************
changed: [proc-dese2]
changed: [proc-dese1]
changed: [proc-divu1]
changed: [proc-divu2]TASK [03-Creating soft connections] ****************************************************************************************
changed: [proc-dese1]
changed: [proc-dese2]
changed: [proc-divu1]
changed: [proc-divu2]TASK [04-Copy the node_exporter.service to the client] *********************************************************************
changed: [proc-dese1]
changed: [proc-dese2]
changed: [proc-divu1]
changed: [proc-divu2]TASK [05-Start the service of node_exporter] *******************************************************************************
changed: [proc-dese2]
changed: [proc-dese1]
changed: [proc-divu1]
changed: [proc-divu2]TASK [06-Start the service of firewalld] ***********************************************************************************
changed: [proc-dese1]
changed: [proc-dese2]
changed: [proc-divu1]
changed: [proc-divu2]TASK [07-Set Firewall Polices] *********************************************************************************************
changed: [proc-dese2]
changed: [proc-divu1]
changed: [proc-dese1]
changed: [proc-divu2]PLAY RECAP *****************************************************************************************************************
proc-dese1                 : ok=7    changed=7    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
proc-dese2                 : ok=7    changed=7    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
proc-divu1                 : ok=7    changed=7    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
proc-divu2                 : ok=7    changed=7    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

部署完毕后,在云平台的安全组中新增9100端口
在这里插入图片描述

4.3、服务端添加客户端

以上部署为在客户端的服务器上部署了采集器,接下来需要在服务端添加客户端的IP和端口

vi /usr/local/prometheus/prometheus.yml

- job_name: "host_monitor"static_configs:- targets: ["localhost:9100","1xx.xx.x.xx:9100","1xx.xx.x.xx:9100","1xx.xx.x.xx:9100","1xx.xx.x.xx:9100"]

编辑完毕后检测语法

./promtool check config prometheus.yml

提示SUCCESS字样后,确认文件格式无误,
重启prometheus

systemctl restart prometheus

在浏览器中输入部署promethues服务端的IP和端口查看
在这里插入图片描述
在浏览器中输入部署的grafana服务端的IP和端口查看
输入用户名和密码,在主机名中选中对应的主机名,查看主机的信息,

注:需要一段采集周期后有指标数据

在这里插入图片描述
以上为批量化部署prometheus客户端工具。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词