Installing Prometheus on Ubuntu is straightforward. Here’s a step-by-step guide:
Step 1: Update the System
Ensure your system is up to date:
sudo apt update && sudo apt upgrade -y
Step 2: Create a Prometheus User
For better security, create a dedicated user for Prometheus:
sudo useradd --no-create-home --shell /bin/false prometheus
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus
Step 3: Download Prometheus
Visit the Prometheus releases page to check the latest version. Replace <VERSION>
with the latest version number in the following commands:
wget https://github.com/prometheus/prometheus/releases/download/v<VERSION>/prometheus-<VERSION>.linux-amd64.tar.gz
Example:
wget https://github.com/prometheus/prometheus/releases/download/v2.47.0/prometheus-2.47.0.linux-amd64.tar.gz
Extract the downloaded file:
tar xvf prometheus-<VERSION>.linux-amd64.tar.gz
cd prometheus-<VERSION>.linux-amd64
Step 4: Move Prometheus Binaries
Move the Prometheus and Promtool binaries to /usr/local/bin
:
sudo mv prometheus /usr/local/bin/
sudo mv promtool /usr/local/bin/
Move the configuration files and set the correct ownership:
sudo mv consoles /etc/prometheus/
sudo mv console_libraries /etc/prometheus/
sudo mv prometheus.yml /etc/prometheus/
sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus
Step 5: Create a Systemd Service File
Create a new service file for Prometheus:
sudo nano /etc/systemd/system/prometheus.service
Add the following content:
[Unit]
Description=Prometheus Monitoring System
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 and exit the file.
Step 6: Reload Systemd and Start Prometheus
Reload systemd to apply changes:
sudo systemctl daemon-reload
Start and enable the Prometheus service:
sudo systemctl start prometheus
sudo systemctl enable prometheus
Step 7: Verify Installation
Check if Prometheus is running:
sudo systemctl status prometheus
Prometheus should now be accessible at:
http://<server-ip>:9090
Optional: Configure Firewall
If you use a firewall, allow access to port 9090:
sudo ufw allow 9090
Now Prometheus is installed and ready to use on your Ubuntu system!