Skip to content

Instantly share code, notes, and snippets.

@jarek-przygodzki
Last active July 29, 2026 07:39
Show Gist options
  • Select an option

  • Save jarek-przygodzki/735e15337a3502fea40beba27e193b04 to your computer and use it in GitHub Desktop.

Select an option

Save jarek-przygodzki/735e15337a3502fea40beba27e193b04 to your computer and use it in GitHub Desktop.
Installing node_exporter as systemd serivice
sudo useradd --system --shell /bin/false node_exporter
curl -fsSL https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz \
  | sudo tar -zxvf - -C /usr/local/bin --strip-components=1 node_exporter-1.3.1.linux-amd64/node_exporter \
  && sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter
sudo tee /etc/systemd/system/node_exporter.service <<"EOF"
[Unit]
Description=Node Exporter

[Service]
User=node_exporter
Group=node_exporter
EnvironmentFile=-/etc/sysconfig/node_exporter
ExecStart=/usr/local/bin/node_exporter $OPTIONS

[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload && \
sudo systemctl start node_exporter && \
sudo systemctl status node_exporter && \
sudo systemctl enable node_exporter
@Nurmukhamed

Nurmukhamed commented Jun 4, 2026 •

Copy link
Copy Markdown

Hello.
I tired to copy and paste this instruction. So I wrote ansible playbook.
May be someone found it useful.

- name: Install node_exporter.
  hosts: localhost
  connection: local
  become: true
  gather_facts: true

  vars:
    environment_file_path: '/etc/sysconfig/node_exporter'

  handlers:
    - name: Start node_exporter
      ansible.builtin.systemd:
        name: node_exporter.service
        daemon_reload: true
        state: started

    - name: Restart node_exporter
      ansible.builtin.systemd:
        name: node_exporter.service
        daemon_reload: true
        state: restarted

  tasks:
    - name: Set arch variable 1/3.
      ansible.builtin.set_fact:
        _arch: "{{ ansible_facts['architecture'] }}"

    - name: Set arch variable 2/3.
      when: ansible_facts['architecture'] == 'x86_64'
      ansible.builtin.set_fact:
        _arch: 'amd64'

    - name: Set arch variable 3/3.
      when: ansible_facts['architecture'] == 'aarch64'
      ansible.builtin.set_fact:
        _arch: 'arm64'

    - name: Set environment file path in Debian.
      when: ansible_facts.os_family == 'Debian'
      ansible.builtin.set_fact:
        environment_file_path: '/etc/default/node_exporter'

    - name: Ensure that node_exporter group is exist.
      ansible.builtin.group:
        name: node_exporter
        system: true
        state: present

    - name: Ensure that node_exporter user is exist.
      ansible.builtin.user:
        name: node_exporter
        group: node_exporter
        system: true
        shell: /bin/false
        state: present

    - name: Download node_exporter archive.
      ansible.builtin.unarchive:
        src: 'https://github.com/prometheus/node_exporter/releases/download/v1.11.1/node_exporter-1.11.1.linux-{{ _arch }}.tar.gz'
        dest: /usr/local/bin
        creates: /usr/local/bin/node_exporter
        remote_src: true
        include:
          - "node_exporter-1.11.1.linux-{{ _arch }}/node_exporter"
        extra_opts: ['--strip-components=1']
        owner: root
        group: root
        mode: '0755'

    - name: Copy systemd unit template.
      ansible.builtin.copy:
        content: |
          [Unit]
          Description=Node Exporter

          [Service]
          User=node_exporter
          Group=node_exporter
          EnvironmentFile=-{{ environment_file_path }}
          ExecStart=/usr/local/bin/node_exporter $OPTIONS

          [Install]
          WantedBy=multi-user.target
        dest: /etc/systemd/system/node_exporter.service
        owner: root
        group: root
        mode: '0755'
      notify:
        - Start node_exporter
        - Restart node_exporter

    - name: Copy environment file content.
      ansible.builtin.copy:
        content: >
          OPTIONS="--collector.systemd --web.listen-address=127.0.0.1:9100"
        dest: "{{ environment_file_path }}"
        owner: root
        group: root
        mode: '0644'
      notify:
        - Start node_exporter
        - Restart node_exporter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment