Skip to content

Instantly share code, notes, and snippets.

@sanfx
Last active December 2, 2023 12:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanfx/d47a7d70f882174416e057d6646af79a to your computer and use it in GitHub Desktop.
Save sanfx/d47a7d70f882174416e057d6646af79a to your computer and use it in GitHub Desktop.
Installing prometheus
Enter the following to create Prometheus user accounts to be used as a service user accounts for security and
administration purposes. These accounts will not be used for logging into the system.
Use the following commands in Terminal to create the service user accounts.
$ sudo useradd --no-create-home --shell /bin/false prome
$ sudo useradd --no-create-home --shell /bin/false node_exporter
Create Prometheus Directories
$ sudo mkdir /etc/prometheus
$ sudo mkdir /var/lib/prometheus
Downloading and Installing Prometheus
Once all these prerequisites are completed, your system will be ready to install Prometheus.
Below is the procedure for downloading and installing Prometheus.
Download the latest stable release of Prometheus using the wget command.
$ wget https://github.com/prometheus/prometheus/releases/download/v2.0.0/
prometheus-2.0.0.linux-amd64.tar.gz
Extract the Prometheus archive using the following command:
$ tar xvf prometheus-2.0.0.linux-amd64.tar.gz
From the extracted folder, copy the binary files to the /usr/local/bin directory and change the ownership.
Use the following commands to copy the “prometheus” and “promtool” binary files to the /usr/local/bin.
$ sudo cp prometheus-2.0.0.linux-amd64/prometheus /usr/local/bin/
$ sudo cp prometheus-2.0.0.linux-amd64/promtool /usr/local/bin/
Next, change the ownership of the files by entering the commands below.
$ sudo chown prome:prome /usr/local/bin/prometheus
$ sudo chown prome:prome /usr/local/bin/promtool
$ sudo chown prome:prome /var/lib/prometheus
After copying the binary files, copy the required libraries to the /etc/prometheus directory.
Use the following commands in Terminal to do so:
$ sudo cp -r prometheus-2.0.0.linux-amd64/consoles /etc/prometheus
$ sudo cp -r prometheus-2.0.0.linux-amd64/console_libraries /etc/prometheus
Then, use the following commands to change the ownership of the files.
$ sudo chown -R prome:prome /etc/prometheus/consoles
$ sudo chown -R prome:prome /etc/prometheus/console_libraries
[b]Prometheus Configuration[/b]
In this section, we will create the configuration file named prometheus.yml in the /etc/prometheus directory created in the previous steps. Issue the following command in Terminal to edit the prometheus.yml file:
$ sudo nano /etc/prometheus/prometheus.yml
Next, copy and paste the following lines into the terminal:
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
Hit Ctrl+o to save and Ctrl+x to exit the file.
Now, we will create another file for the systemd service. Issue the following command in the Terminal to do so:
$ sudo nano /etc/systemd/system/prometheus.service
Next, copy and paste the following lines into the terminal:
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prome
Group=prome
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
Hit Ctrl+o to save the file and Ctrl+x to exit the file.
Once you are done with the above configurations, reload systemd using the following command:
$ sudo systemctl daemon-reload
Start the Prometheus service by issuing the following command:
$ sudo systemctl start prometheus
To enable the Prometheus service at system boot, use the following command:
$ sudo systemctl enable prometheus
After starting the Prometheus service, use the following command to view the service status:
$ sudo systemctl status prometheus
The following screenshot shows that the Prometheus service is active and running.
Access the Prometheus Web Interface
Next, try accessing the Prometheus web interface. Open a web browser and navigate to the following address:
http://ip-address:9090
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment