当前位置: 首页 > news >正文

Ansible部署Node_exporter

本文分享自天翼云开发者社区《Ansible部署Node_exporter》,作者:SummerSnow

一、简介

       Ansible是基于Python开发的自动化运维工具,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。

       Exporter是Prometheus的指标数据收集组件,而node_exporter就是我们常用的其中之一,它主要用于采集类UNIX内核的硬件以及系统指标,如磁盘、cpu、内存等信息。

二、环境说明

#操作系统版本
[root@XXXXX][~]
$cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)#Ansible版本
ansible 2.9.25
#node-exporter版本
node_exporter-1.2.2
#环境说明:本操作未涉及容器化部署,同时在centos 7环境进行部署

三、安装Ansible

#上传已经准备好的的安装包(内网环境)
[root@XXXXX ~] tar -zxvf ansible.tar.gz#使用下面的命令进行安装(yum本地安装)
[root@XXXXX ~]# yum localinstall *.rpm -y#查看ansible版本
[root@XXX][~]
$ansible --version
ansible 2.9.25config file = /etc/ansible/ansible.cfgconfigured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']

四、使用Ansible部署node_exporter

1)填写需要部署的主机清单host

#如果机器之间已经做了免密,那就去掉ansible_ssh_pass改配置,多台机器直接追加就行
[root@XXXXXX][~]
$vim host
[node]
XX.XX ansible_ssh_user=XXX ansible_ssh_pass="XXXXXX"
XX.XX ansible_ssh_user=XXX ansible_ssh_pass="XXXXXX"

2)编写Ansible的剧本文件node_exporter.yml

---
- hosts: nodegather_facts: yesbecome: yesbecome_method: sudobecome_user: roottasks: - name: 添加prometheus用户user:name: prometheuspassword: "{{ 'XXXXX' | password_hash('sha512') }}"home: /home/prometheus- name: 创建node_exporter_script目录file:path: /home/prometheus/node_exporter_scriptstate: directorymode: '0755'owner: prometheusgroup: prometheus- name: 创建node_exporter_textfile目录file:path: /home/prometheus/node_exporter_textfilestate: directorymode: '0755'owner: prometheusgroup: prometheus- name: 安装CentOS7的node_exporterunarchive: src=node_exporter-1.2.2.linux-amd64.tar.gz dest=/home/prometheus mode='0755' owner=prometheus group=prometheuswhen:- ansible_distribution == "CentOS"- ansible_distribution_major_version == "7"- name: 添加CentOS7的node_exporter服务copy: src=prometheus_node_exporter.service dest=/usr/lib/systemd/system/prometheus_node_exporter.servicewhen:- ansible_distribution == "CentOS"- ansible_distribution_major_version == "7"- name: 开启centos7的prometheus_node_exporter服务并设置开机自启动systemd:name: prometheus_node_exporterdaemon_reload: yesstate: restartedenabled: yeswhen:- ansible_distribution == "CentOS"- ansible_distribution_major_version == "7"

3)编写node-exporter的注册服务文件

[root@XXX][~]
$vim prometheus_node_exporter.service
[Unit]
Description=Prometheus node_exporter
Requires=network.target remote-fs.target
After=network.target remote-fs.target[Service]
Type=simple
User=prometheus
Group=prometheus
ExecStart=/home/prometheus/node_exporter-1.2.2.linux-amd64/node_exporter --collector.textfile.directory=/home/prometheus/node_exporter_textfile
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=5s[Install]
WantedBy=multi-user.target

4)命令执行

[root@XXX ~]
$ansible-playbook node_exporter.yml -i host

5)服务验证

#验证目标端口是否开启
[root@XXXXX ~]
$telnet 目标主机 9100

至此,使用Ansible部署node-exporter完成。

http://www.sczhlp.com/news/8162/

相关文章:

  • 简述分布式链路追踪工具——Jaeger
  • Responsive web design 14
  • centos更换国内yum源
  • HFSS许可证常见问题及解决方案
  • 高性能计算-CUDA 性能优化之线程束调度
  • SQLite简介、使用及客户端管理工具DBeaver
  • 代码回退的惊天巨坑GIT
  • 8-8 力扣热门题目
  • GPT-5 隆重推出,免费使用!
  • Selenium脚本运行报错:cannot find Chrome binary - xiaoguan
  • 如何创建不需要Visual C++运行时的独立C++程序
  • Selenium自动化脚本运行报错:cannot find Chrome binary - xiaoguan
  • CentOS配置syslog服务器
  • 踩坑记录:Claude Code Router 配置 Gemini Balance API
  • Responsive web design 12
  • Js克隆对象
  • Springboot构建包使用BOOT-INF中的class覆盖依赖包中的class
  • 2025/8/8 总结
  • 《赵威后问齐使》
  • CF2066F Curse 题解
  • 从经验到算法:易路如何用AI Agent重塑公平、高效、前瞻的薪酬管理
  • 2025.8.8 java课堂笔记
  • Responsive web design 11
  • Responsive Web Design8
  • golang语言介绍与安装
  • 场景题——Redis
  • 焊接机械手混合气节能方式
  • k8s集群添加master节点报control plane 错误
  • GAS_Aura-Animation Blueprints
  • EPLAN的明纬开关电源的部件库