Overview
Describes how to manually install Node Exporter under CentOS and manage it with Systemd.
Installation
Create a user
[root@liqiang.io]# adduser node_exporter
Install node exporter
[root@liqiang.io]# cd /home/node_exporter
[root@liqiang.io]# wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
[root@liqiang.io]# tar zxf node_exporter-1.5.0.linux-amd64.tar.gz && \
ln -s node_exporter-1.5.0.linux-amd64 node_exporter && \
chown -R node_exporter:node_exporter node_exporter && \
chown -R node_exporter:node_exporter node_exporter-1.5.0.linux-amd64 && \
cd node_exporter
[root@liqiang.io]# touch /etc/sysconfig/node_exporter && echo 'OPTIONS="--collector.textfile.directory /var/lib/node_exporter/textfile_collector"' > /etc/sysconfig/node_exporter
[root@liqiang.io]# mkdir -p /var/lib/node_exporter/textfile_collector && \
chown node_exporter:node_exporter /var/lib/node_exporter/textfile_collector
[root@liqiang.io]# cat <<EOF> /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
[Service]
User=node_exporter
EnvironmentFile=/etc/sysconfig/node_exporter
ExecStart=/bin/sh -c '/home/node_exporter/node_exporter/node_exporter \$OPTIONS'
[Install]
WantedBy=multi-user.target
EOF
[root@liqiang.io]# systemctl daemon-reload
[root@liqiang.io]# systemctl enable node_exporter
[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.
[root@liqiang.io]# systemctl stop node_exporter
[root@liqiang.io]# unlink node_exporter
[root@liqiang.io]# rm -rf node_exporter-1.5.0.linux-amd64
[root@liqiang.io]# userdel -r node_exporter
[root@liqiang.io]#
[root@liqiang.io]# rm -rf /var/lib/node_exporter
[root@liqiang.io]# rm -rf /etc/sysconfig/node_exporter
[root@liqiang.io]# rm -f /usr/lib/systemd/system/node_exporter.service
If that’s too much trouble, then you can use this script:
[root@liqiang.io]# cat <<EOF> /tmp/uninstall-node-exporter.sh
systemctl stop node_exporter
unlink /home/node_exporter/node_exporter
userdel -r node_exporter
rm -rf /var/lib/node_exporter
rm -rf /etc/sysconfig/node_exporter
rm -f /usr/lib/systemd/system/node_exporter.service
EOF
[root@liqiang.io]# sh /tmp/uninstall-node-exporter.sh