Overview

Describes how to manually install Node Exporter under CentOS and manage it with Systemd.

Installation

Create a user

  1. [root@liqiang.io]# adduser node_exporter

Install node exporter

  1. [root@liqiang.io]# cd /home/node_exporter
  2. [root@liqiang.io]# wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
  3. [root@liqiang.io]# tar zxf node_exporter-1.5.0.linux-amd64.tar.gz && \
  4. ln -s node_exporter-1.5.0.linux-amd64 node_exporter && \
  5. chown -R node_exporter:node_exporter node_exporter && \
  6. chown -R node_exporter:node_exporter node_exporter-1.5.0.linux-amd64 && \
  7. cd node_exporter
  8. [root@liqiang.io]# touch /etc/sysconfig/node_exporter && echo 'OPTIONS="--collector.textfile.directory /var/lib/node_exporter/textfile_collector"' > /etc/sysconfig/node_exporter
  9. [root@liqiang.io]# mkdir -p /var/lib/node_exporter/textfile_collector && \
  10. chown node_exporter:node_exporter /var/lib/node_exporter/textfile_collector
  11. [root@liqiang.io]# cat <<EOF> /usr/lib/systemd/system/node_exporter.service
  12. [Unit]
  13. Description=Node Exporter
  14. [Service]
  15. User=node_exporter
  16. EnvironmentFile=/etc/sysconfig/node_exporter
  17. ExecStart=/bin/sh -c '/home/node_exporter/node_exporter/node_exporter \$OPTIONS'
  18. [Install]
  19. WantedBy=multi-user.target
  20. EOF
  21. [root@liqiang.io]# systemctl daemon-reload
  22. [root@liqiang.io]# systemctl enable node_exporter
  23. [root@liqiang.io]# systemctl start node_exporter

Config

If you want to change anything in the configuration then this can be done directly by modifying: /etc/sysconfig/node_exporter this file.

Cleanup

If you want to uninstall it, you can use these steps.

  1. [root@liqiang.io]# systemctl stop node_exporter
  2. [root@liqiang.io]# unlink node_exporter
  3. [root@liqiang.io]# rm -rf node_exporter-1.5.0.linux-amd64
  4. [root@liqiang.io]# userdel -r node_exporter
  5. [root@liqiang.io]#
  6. [root@liqiang.io]# rm -rf /var/lib/node_exporter
  7. [root@liqiang.io]# rm -rf /etc/sysconfig/node_exporter
  8. [root@liqiang.io]# rm -f /usr/lib/systemd/system/node_exporter.service

If that’s too much trouble, then you can use this script:

  1. [root@liqiang.io]# cat <<EOF> /tmp/uninstall-node-exporter.sh
  2. systemctl stop node_exporter
  3. unlink /home/node_exporter/node_exporter
  4. userdel -r node_exporter
  5. rm -rf /var/lib/node_exporter
  6. rm -rf /etc/sysconfig/node_exporter
  7. rm -f /usr/lib/systemd/system/node_exporter.service
  8. EOF
  9. [root@liqiang.io]# sh /tmp/uninstall-node-exporter.sh