
Installing Prometheus on your Ubuntu system is a fundamental step for robust monitoring. This guide provides clear, step-by-step instructions to get Prometheus up and running efficiently.
Before you begin, it’s always a good practice to ensure your system’s package list is updated. Open your terminal and run:
sudo apt update
Next, we’ll create a dedicated system user for Prometheus. This enhances security by running the service under its own unprivileged user.
sudo useradd –no-create-home –shell /bin/false prometheus
Now, we need to create the necessary directories for Prometheus configuration and data.
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
Visit the official Prometheus downloads page to find the latest stable release appropriate for your system architecture. Use wget
to download the compressed archive. Replace the URL below with the correct one for the current version:
wget https://github.com/prometheus/prometheus/releases/download/v2.x.x/prometheus-2.x.x.linux-amd64.tar.gz
Extract the downloaded archive.
tar xvfz prometheus-2.x.x.linux-amd64.tar.gz
Navigate into the extracted directory.
cd prometheus-2.x.x.linux-amd64
Now, copy the executable binaries to a standard path where the system can find them, and copy the configuration files to the dedicated Prometheus configuration directory.
sudo cp prometheus /usr/local/bin/
sudo cp promtool /usr/local/bin/
sudo cp -r consoles /etc/prometheus
sudo cp -r console_libraries /etc/prometheus
sudo cp prometheus.yml /etc/prometheus/
We need to set the correct ownership for the directories and files so the prometheus
user can access them.
sudo chown -R prometheus:prometheus /etc/prometheus
sudo chown -R prometheus:prometheus /var/lib/prometheus
sudo chown prometheus:prometheus /usr/local/bin/prometheus
sudo chown prometheus:prometheus /usr/local/bin/promtool
sudo chown -R prometheus:prometheus /etc/prometheus/consoles
sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries
Prometheus is managed efficiently using systemd
. We’ll create a service file to define how Prometheus should run. Open a new file using a text editor like nano
:
sudo nano /etc/systemd/system/prometheus.service
Paste the following configuration into the file. This specifies the user, working directory, and the command to execute Prometheus, along with its configuration and data paths.
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
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
Save the file and exit the editor (Ctrl+X, Y, Enter for nano).
Reload the systemd manager configuration to recognize the new service file.
sudo systemctl daemon-reload
Now you can start the Prometheus service.
sudo systemctl start prometheus
To ensure Prometheus starts automatically after a system reboot, enable the service.
sudo systemctl enable prometheus
You can check the status of the Prometheus service to confirm it’s running correctly.
sudo systemctl status prometheus
The output should show the service as active (running)
.
By default, Prometheus listens on port 9090. If you are running a firewall like UFW, you will need to allow incoming traffic on this port.
sudo ufw allow 9090/tcp
sudo ufw reload
You can now access the Prometheus web interface by opening a web browser and navigating to http://your_server_ip:9090
. You should see the Prometheus dashboard, confirming a successful installation.
This completes the basic installation of the Prometheus server. You can now proceed to configure scrape targets to start collecting metrics.
Source: https://kifarunix.com/install-prometheus-on-ubuntu-18-04/