Setup

Setting up Prometheus

Now that we have the basic understanding of Prometheus,let’s get a Prometheus server up and start scraping some metrics.

Installing node_exporter

Download the Node Exporter on all machines :

Create users and service files for node_exporter.

For security reasons, it is always recommended to run any services/daemons in separate accounts of their own. Thus, we are going to create an user account for node_exporter. We have used the -r flag to indicate it is a system account, and set the default shell to /bin/false using -s to prevent logins.

Create a systemd unit file so that node_exporter can be started at boot.

Since we have created a new unit file, we must reload the systemd daemon, set the service to always run at boot and start it :

Installing Prometheus

The next step is to download and install Prometheus only on the Prometheus Server.

Extract the Prometheus archive :

Move the binaries to /usr/local/bin:

Create directories for configuration files and other prometheus data.

Move the configuration files to the directory we made previously:

Delete the leftover files as we do not need them any more:

Configuring Prometheus

After having installed Prometheus, we have to configure Prometheus to let it know about the HTTP endpoints it should monitor. Prometheus uses the YAML format for its configuration.

Go to /etc/hosts and add the following lines, replace x.x.x.x with the machine’s corresponding IP address

x.x.x.x prometheus-target-1 x.x.x.x prometheus-target-2 We will use /etc/prometheus/prometheus.yml as our configuration file

Finally, we will also change the ownership of files that Prometheus will use:

Then, we will create a systemd unit file in /etc/systemd/system/prometheus.service with the following contents :

Finally, we will reload systemd:

Prometheus provides a web UI for running basic queries located at http://<your_server_IP>:9090/. This is how it looks like in a web browser:

Script Setup

  1. Run Prometheus.sh for installing Prometheus server

Only run as root user for this script method installation.

  1. Install Node_Exporter

Last updated