Skip to content

Instantly share code, notes, and snippets.

Last active February 26, 2024 20:33
  • Star 14 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save galexrt/44d62a0681146bfdbe98d0b549a01999 to your computer and use it in GitHub Desktop.
Simple Prometheus node_exporter install script (Updated for 1.0.1)
wget "$version/node_exporter-$version.$arch.tar.gz" \
-O /tmp/node_exporter.tar.gz
mkdir -p /tmp/node_exporter
cd /tmp || { echo "ERROR! No /tmp found.."; exit 1; }
tar xfz /tmp/node_exporter.tar.gz -C /tmp/node_exporter || { echo "ERROR! Extracting the node_exporter tar"; exit 1; }
cp "/tmp/node_exporter/node_exporter-$version.$arch/node_exporter" "$bin_dir"
chown root:staff "$bin_dir/node_exporter"
cat <<EOF > /etc/systemd/system/node_exporter.service
Description=Prometheus node exporter
ExecStartPre=-/sbin/iptables -I INPUT 1 -p tcp --dport 9100 -s -j ACCEPT
ExecStartPre=-/sbin/iptables -I INPUT 3 -p tcp --dport 9100 -j DROP
systemctl enable node_exporter.service
systemctl start node_exporter.service
echo "SUCCESS! Installation succeeded!"
Copy link

dschrul commented Mar 17, 2020

thanks for this. Helped me a lot today

Copy link

lgg42 commented Oct 7, 2020

Thanks! it helped!

Copy link

galexrt commented Oct 7, 2020

@lgg42 no problem! Please note that I have gone ahead and updated the node_exporter version to v1.0.1 as of today.

Copy link

Hey, I'm trying to create a more robust/advanced/configurable installation script for Node exporter.

You can find it here:

Any help is greatly appreciated!

Copy link

galexrt commented May 8, 2022

@carlocorradini Looks like a good improvement on this simple script. One thing I would optional though would be the iptables rules created during the service start. They can be placed "anywhere" under the [Service] section so you can just append them to the file if the feature flag has been enabled.

Might also be worth to add ExecStopPost to remove the iptables rules so in case the service is restarted multiple times there are no leftover iptables rules.

Copy link

@galexrt Thanks!
Do you want to create a simple PR? 🥳🤯

Copy link

galexrt commented May 9, 2022

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