Skip to main content

🚀 Installing Prometheus on Linux (Ubuntu)

Follow this step-by-step guide to install Prometheus on your Ubuntu system. 🎯


🔄 Update System Packages

sudo apt update && sudo apt install -y wget curl tar
  • This command updates your system package list and installs essential tools (wget, curl, and tar).

👤 Create a Dedicated Prometheus User

sudo useradd --no-create-home --shell /bin/false prometheus
  • Creates a system user named prometheus without a home directory for security purposes.

📂 Set Up Directories for Prometheus

sudo mkdir /etc/prometheus /var/lib/prometheus
sudo chown prometheus:prometheus /etc/prometheus /var/lib/prometheus
  • Creates necessary directories for Prometheus configuration and data storage.
  • Changes ownership to the prometheus user.

📥 Download Prometheus

cd /tmp
wget https://github.com/prometheus/prometheus/releases/download/v3.2.1/prometheus-3.2.1.linux-amd64.tar.gz
  • Switches to the /tmp directory.
  • Downloads the latest Prometheus binary (v3.2.1).

📦 Extract the Archive

tar xvf prometheus-3.2.1.linux-amd64.tar.gz
cd prometheus-3.2.1.linux-amd64
  • Extracts the tar file and navigates into the extracted directory.

🚀 Move Binaries to a System Path

sudo mv prometheus promtool /usr/local/bin/
sudo chown prometheus:prometheus /usr/local/bin/prometheus /usr/local/bin/promtool
  • Moves Prometheus and Promtool binaries to /usr/local/bin/ for global access.
  • Updates file ownership to the prometheus user.

⚙️ Configure Prometheus

sudo nano /etc/prometheus/prometheus.yml

Add the following configuration:

global:
scrape_interval: 15s
evaluation_interval: 15s

scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']

Save and exit (CTRL + X, then Y and Enter).

sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml
  • Ensures Prometheus has the correct permissions.

🔧 Create a Systemd Service for Prometheus

sudo nano /etc/systemd/system/prometheus.service

Add the following service configuration:

[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.listen-address="0.0.0.0:9090" \
--storage.tsdb.retention.time=30d \
--web.enable-lifecycle

[Install]
WantedBy=multi-user.target

Save and exit.


🚀 Start and Enable Prometheus Service

sudo systemctl daemon-reload
sudo systemctl enable --now prometheus
sudo systemctl status prometheus
  • Reloads systemd.
  • Enables and starts Prometheus immediately.
  • Checks the status of the Prometheus service.

🌍 Access Prometheus Web Interface

Open your browser and visit: http://13.232.111.4:9090 🌐

Prometheus is now installed and running! 🎉

Next steps:

  • Configure Prometheus targets.
  • Set up Grafana for visualization.
  • Explore alerting rules.

For more details, check the official documentation. 📖