Installation

Create user

1
[root@liqiang.io]# adduser node_exporter

Installing the node exporter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[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

Configuration

If you want to change anything in the configuration, then you can do it directly by modifying the file: /etc/sysconfig/node_exporter.

Cleanup

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

1
2
3
4
5
6
7
8
[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 you find it a bit cumbersome, then you can use this script.

1
2
3
4
5
6
7
8
9
[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