๐ Prometheus Installation Guide on AWS (EC2 Ubuntu)


Series: 30 Days DevOps Interview Preparation
Author: Tathagat Gaikwad
Prometheus is one of the most popular open-source monitoring systems. When deploying applications on AWS, you can run Prometheus on an EC2 instance to monitor infrastructure, applications, and custom metrics.
In this blog, weโll go through the step-by-step process of installing Prometheus on AWS EC2 running Ubuntu.
๐น 1. Pre-requisites
Before starting, make sure you have:
AWS Account with access to create EC2 instances.
IAM User/Role with EC2 & Security Group permissions.
Key Pair (for SSH access to your EC2).
Security Group with rules:
Allow SSH (port
22
) from your IP.Allow Prometheus (port
9090
).Allow Node Exporter (port
9100
).
Recommended Instance Type:
t2.micro
for testing (free-tier eligible).t3.medium
or higher for production.
๐น 2. Launching EC2 Instance
Login to AWS Console โ EC2 Dashboard.
Click Launch Instance.
Choose Ubuntu 22.04 LTS AMI.
Select instance type (e.g.,
t2.micro
).Configure security group โ allow ports
22
,9090
, and9100
.Launch with a key pair and connect via SSH:
ssh -i my-key.pem ubuntu@<EC2-PUBLIC-IP>
๐น 3. Update Server & Install Basics
On your EC2 instance:
sudo apt update && sudo apt upgrade -y
sudo apt install wget curl tar systemd -y
๐น 4. Install Prometheus on EC2
Step 1: Create Prometheus User & Folders
sudo useradd --no-create-home --shell /usr/sbin/nologin prometheus
sudo mkdir -p /etc/prometheus /var/lib/prometheus
sudo chown prometheus:prometheus /etc/prometheus /var/lib/prometheus
Step 2: Download & Install Prometheus
VER=2.52.0 # latest version
cd /tmp
wget https://github.com/prometheus/prometheus/releases/download/v$VER/prometheus-$VER.linux-amd64.tar.gz
tar xvf prometheus-$VER.linux-amd64.tar.gz
sudo cp prometheus-$VER.linux-amd64/prometheus /usr/local/bin/
sudo cp prometheus-$VER.linux-amd64/promtool /usr/local/bin/
sudo cp -r prometheus-$VER.linux-amd64/consoles /etc/prometheus/
sudo cp -r prometheus-$VER.linux-amd64/console_libraries /etc/prometheus/
sudo chown -R prometheus:prometheus /etc/prometheus
Step 3: Configure prometheus.yml
sudo tee /etc/prometheus/prometheus.yml > /dev/null <<'YAML'
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node_exporter'
static_configs:
- targets: ['localhost:9100']
YAML
sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml
Step 4: Create Systemd Service
sudo tee /etc/systemd/system/prometheus.service > /dev/null <<'EOF'
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
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
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now prometheus
Verify service:
sudo systemctl status prometheus
๐น 5. Install Node Exporter (Host Metrics)
sudo useradd --no-create-home --shell /usr/sbin/nologin nodeusr
NE_VER=1.8.2
cd /tmp
wget https://github.com/prometheus/node_exporter/releases/download/v$NE_VER/node_exporter-$NE_VER.linux-amd64.tar.gz
tar xvf node_exporter-$NE_VER.linux-amd64.tar.gz
sudo cp node_exporter-$NE_VER.linux-amd64/node_exporter /usr/local/bin/
sudo chown nodeusr:nodeusr /usr/local/bin/node_exporter
Systemd service:
sudo tee /etc/systemd/system/node_exporter.service > /dev/null <<'EOF'
[Unit]
Description=Node Exporter
After=network.target
[Service]
User=nodeusr
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=default.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now node_exporter
Verify:
curl http://localhost:9100/metrics
๐น 6. Access Prometheus Dashboard
Open browser:
http://<EC2-PUBLIC-IP>:9090
Query example in PromQL:
up
โ Shows the status of all scrape targets.
๐น 7. Security Best Practices on AWS
Use Security Groups to allow only trusted IPs to access
9090
&9100
.For production, put Prometheus behind an Application Load Balancer (ALB) with HTTPS.
Use IAM Roles if integrating with CloudWatch.
Restrict access to Prometheus UI using Nginx reverse proxy + basic auth.
๐น 8. Next Steps
Add Grafana on the same or a separate EC2 instance โ connect Prometheus as a data source.
Configure Alertmanager for notifications (Slack, Email, etc.).
Explore scaling options:
Use EBS volumes for persistent storage.
Use Thanos or Cortex for HA & long-term storage.
โ You now have a fully running Prometheus + Node Exporter setup on AWS EC2 Ubuntu.
Subscribe to my newsletter
Read articles from Tathagat Gaikwad directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
