Ansible部署Node_exporter

天翼云开发者社区
• 阅读 1

本文分享自天翼云开发者社区《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.25
  config file = /etc/ansible/ansible.cfg
  configured 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: node
  gather_facts: yes
  become: yes
  become_method: sudo
  become_user: root
  tasks: 
    - name: 添加prometheus用户
      user:
        name: prometheus
        password: "{{ 'XXXXX' | password_hash('sha512') }}"
        home: /home/prometheus

    - name: 创建node_exporter_script目录
      file:
        path: /home/prometheus/node_exporter_script
        state: directory
        mode: '0755'
        owner: prometheus
        group: prometheus

    - name: 创建node_exporter_textfile目录
      file:
        path: /home/prometheus/node_exporter_textfile
        state: directory
        mode: '0755'
        owner: prometheus
        group: prometheus

    - name: 安装CentOS7的node_exporter
      unarchive: src=node_exporter-1.2.2.linux-amd64.tar.gz dest=/home/prometheus mode='0755' owner=prometheus group=prometheus
      when:
        - 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.service
      when:
        - ansible_distribution == "CentOS"
        - ansible_distribution_major_version == "7"

    - name: 开启centos7的prometheus_node_exporter服务并设置开机自启动
      systemd:
        name: prometheus_node_exporter
        daemon_reload: yes
        state: restarted
        enabled: yes
      when:
        - 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完成。

点赞
收藏
评论区
推荐文章
胖大海 胖大海
2年前
ansible自动化运维
Ansible是一个开源的基于openssh的自动化配置管理工具。可以用它来配置系统,部署软件和编排更高级的IT任务,比如持续部署或零停机更新。Ansible的主要目标是简单和易用,通过Ansible可以批量管理大型运维环境。!(https:/
Tommy744 Tommy744
4年前
DevOps简介
DevOps是一个完整的面向IT运维的工作流,以IT自动化以及持续集成(CI)、持续部署(CD)为基础,来优化程式开发、测试、系统运维等所有环节。DevOps的概念DevOps一词的来自于Development和Operations的组合,突出重视软件开发人员和运维人员的沟通合作,通过自动化流程来使得软件构建、测试、发布更加快捷、频繁和可靠。
Stella981 Stella981
3年前
CentOS系统:自动化运维工具Ansible的安装与配置
一、Ansible工具简介ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。二、Ansible的安装1、因为是对Ansible的简单测试,所以
Stella981 Stella981
3年前
Ansible入门及组件介绍
Ansible简介Ansible是自动化运维的工具,基于Python开发,实现了批量系统配置、批量程序部署、批量运行命令等功能。Ansible是基于模块工作的,ansible提供一个框架,通过模块实现批量部署。Ansible是一种配置管理工具Ansible不需要安装客户端软件Ansible的功能实现基于SSH远
Stella981 Stella981
3年前
Jenkins+Ansible+Gitlab自动化部署三剑客
JenkinsAnsibleGitlab自动化部署三剑客小中大showerlee2016031113:00Ansible(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fwww.
Stella981 Stella981
3年前
DevOps简介
DevOps是一个完整的面向IT运维的工作流,以IT自动化以及持续集成(CI)、持续部署(CD)为基础,来优化程式开发、测试、系统运维等所有环节。DevOps的概念DevOps一词的来自于Development和Operations的组合,突出重视软件开发人员和运维人员的沟通合作,通过自动化流程来使得软件构建、测试、发布更加快捷、频繁和
Stella981 Stella981
3年前
Ansible快速入门教程
Ansible快速入门介绍Ansible是一款简单的运维自动化工具,只需要使用ssh协议连接就可以来进行系统管理,自动化执行命令,部署等任务。Ansible的特点1、ansible不需要单独安装客户端,也不需要启动任何服务2、ansible是Python(https://www.osc
Stella981 Stella981
3年前
DevOps作业要求
DevOps作业要求:请仔细阅读题目的要求,并编写一些程序来创建、配置部署环境并部署相应的软件包。如果你提交了多份解决方案,我们将只评价一种。对于程序语言,我们期望你使用puppet、chef、ansible或者powershell,甚至是ruby、python等。你不能使用外部的程序库或者其他人实现的模块来解决问题,但是你可以使用外部的工具来构建测
Stella981 Stella981
3年前
DevOps
uppet总结一、基础知识1. Puppet是开源的基于Ruby的系统配置管理工具,依赖于C/S的部署架构。Puppet这样的自动化配置管理工具可以帮助系统管理员更加方便的完成多台服务器的升级软件包、管理配置文件、系统服务、cron任务、添加新的配置、修复错误等重复工作。2. Puppet的运作是典型的C/
Stella981 Stella981
3年前
Kubernetes 学习1 Devops 核心要点和k8s架构概述
一、概述  1、我们以往在去实现安装部署应用程序时我们要去实现部署实现应用手动去做会非常麻烦,所以我们后来便有了工具,像ansible等等,这个工具其实就是一个应用编排工具。他能够安装,配置,服务启动,甚至能够让你按照所定义的Playbok完成对多种应用程序在实现有依赖关系时将我们手工需要配置的工作反应在ansible配置文件playbox中,让其按照p
天翼云开发者社区
天翼云开发者社区
Lv1
天翼云是中国电信倾力打造的云服务品牌,致力于成为领先的云计算服务提供商。提供云主机、CDN、云电脑、大数据及AI等全线产品和场景化解决方案。
文章
890
粉丝
16
获赞
40