• <li id="00i08"><input id="00i08"></input></li>
  • <sup id="00i08"><tbody id="00i08"></tbody></sup>
    <abbr id="00i08"></abbr>
  • 博客專欄

    EEPW首頁(yè) > 博客 > Ansible部署Node_exporter

    Ansible部署Node_exporter

    發(fā)布人:天翼云開(kāi)發(fā)者 時(shí)間:2025-08-08 來(lái)源:工程師 發(fā)布文章

    本文分享自天翼云開(kāi)發(fā)者社區(qū)《Ansible部署Node_exporter》,作者:SummerSnow

    一、簡(jiǎn)介

           Ansible是基于Python開(kāi)發(fā)的自動(dòng)化運(yùn)維工具,集合了眾多運(yùn)維工具(puppet、cfengine、chef、func、fabric)的優(yōu)點(diǎn),實(shí)現(xiàn)了批量系統(tǒng)配置、批量程序部署、批量運(yùn)行命令等功能。

           Exporter是Prometheus的指標(biāo)數(shù)據(jù)收集組件,而node_exporter就是我們常用的其中之一,它主要用于采集類UNIX內(nèi)核的硬件以及系統(tǒng)指標(biāo),如磁盤、cpu、內(nèi)存等信息。

    二、環(huán)境說(shuō)明

    #操作系統(tǒng)版本[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#環(huán)境說(shuō)明:本操作未涉及容器化部署,同時(shí)在centos 7環(huán)境進(jìn)行部署

    三、安裝Ansible

    #上傳已經(jīng)準(zhǔn)備好的的安裝包(內(nèi)網(wǎng)環(huán)境)[root@XXXXX ~] tar -zxvf ansible.tar.gz#使用下面的命令進(jìn)行安裝(yum本地安裝)[root@XXXXX ~]# yum localinstall *.rpm -y#查看ansible版本[root@XXX][~]$ansible --versionansible 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)填寫需要部署的主機(jī)清單host

    #如果機(jī)器之間已經(jīng)做了免密,那就去掉ansible_ssh_pass改配置,多臺(tái)機(jī)器直接追加就行[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: 創(chuàng)建node_exporter_script目錄
          file:
            path: /home/prometheus/node_exporter_script
            state: directory
            mode: '0755'
            owner: prometheus
            group: prometheus
    
        - name: 創(chuàng)建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服務(wù)
          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: 開(kāi)啟centos7的prometheus_node_exporter服務(wù)并設(shè)置開(kāi)機(jī)自啟動(dòng)
          systemd:
            name: prometheus_node_exporter
            daemon_reload: yes
            state: restarted
            enabled: yes
          when:
            - ansible_distribution == "CentOS"
            - ansible_distribution_major_version == "7"

    3)編寫node-exporter的注冊(cè)服務(wù)文件

    [root@XXX][~]$vim prometheus_node_exporter.service[Unit]Description=Prometheus node_exporterRequires=network.target remote-fs.targetAfter=network.target remote-fs.target[Service]Type=simpleUser=prometheusGroup=prometheusExecStart=/home/prometheus/node_exporter-1.2.2.linux-amd64/node_exporter --collector.textfile.directory=/home/prometheus/node_exporter_textfileExecReload=/bin/kill -HUP $MAINPIDKillMode=processRestart=on-failureRestartSec=5s[Install]WantedBy=multi-user.target

    4)命令執(zhí)行

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

    5)服務(wù)驗(yàn)證

    #驗(yàn)證目標(biāo)端口是否開(kāi)啟[root@XXXXX ~]$telnet 目標(biāo)主機(jī) 9100

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


    *博客內(nèi)容為網(wǎng)友個(gè)人發(fā)布,僅代表博主個(gè)人觀點(diǎn),如有侵權(quán)請(qǐng)聯(lián)系工作人員刪除。


    關(guān)鍵詞: Ansible

    技術(shù)專區(qū)

    關(guān)閉
    主站蜘蛛池模板: 普洱| 裕民县| 大同县| 天水市| 通州区| 类乌齐县| 边坝县| 江口县| 恩平市| 宣威市| 弥勒县| 双柏县| 抚宁县| 潼南县| 恩平市| 保康县| 石棉县| 景泰县| 安陆市| 阿尔山市| 赤城县| 蓬溪县| 新龙县| 柳州市| 手机| 黎城县| 南丰县| 淄博市| 镇平县| 谷城县| 福鼎市| 舟曲县| 沈阳市| 东乡族自治县| 界首市| 九龙县| 金乡县| 长阳| 正定县| 崇明县| 靖安县|