Install Prometheus on Ubuntu 24.04
Step 1 – Install Prometheus
apt install -y prometheus prometheus-node-exporter
Step 2 – Create user and directories
useradd -r -s /sbin/nologin prometheus 2>/dev/null || useradd -r -s /usr/sbin/nologin prometheus
mkdir -p /etc/prometheus /var/lib/prometheus
chown prometheus:prometheus /etc/prometheus /var/lib/prometheus
Step 3 – Basic /etc/prometheus/prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets: []
rule_files: []
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "node"
static_configs:
- targets:
- "localhost:9100"
- "192.168.1.11:9100"
- "192.168.1.12:9100"
- job_name: "nginx"
static_configs:
- targets: ["localhost:9113"]
- job_name: "mysql"
static_configs:
- targets: ["localhost:9104"]
Step 4 – systemd unit (/etc/systemd/system/prometheus.service)
[Unit]
Description=Prometheus
After=network.target
[Service]
User=prometheus
Group=prometheus
ExecStart=/usr/local/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus \
--storage.tsdb.retention.time=30d \
--web.listen-address=:9090
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable --now prometheus
Step 5 – Verify
curl http://localhost:9090/-/healthy
Access the web UI at http://your-server:9090.