日本a√视频在线,久久青青亚洲国产,亚洲一区欧美二区,免费g片在线观看网站

        <style id="k3y6c"><u id="k3y6c"></u></style>
        <s id="k3y6c"></s>
        <mark id="k3y6c"></mark>
          
          

          <mark id="k3y6c"></mark>

          "); //-->

          博客專欄

          EEPW首頁 > 博客 > Ansible部署Node_exporter

          Ansible部署Node_exporter

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

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

          一、簡介

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

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

          二、環(huán)境說明

          #操作系統(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)境說明:本操作未涉及容器化部署,同時在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改配置,多臺機(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: 開啟centos7的prometheus_node_exporter服務(wù)并設(shè)置開機(jī)自啟動
                systemd:
                  name: prometheus_node_exporter
                  daemon_reload: yes
                  state: restarted
                  enabled: yes
                when:
                  - ansible_distribution == "CentOS"
                  - ansible_distribution_major_version == "7"

          3)編寫node-exporter的注冊服務(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ù)驗證

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

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


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


          關(guān)鍵詞: Ansible

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

          關(guān)閉