Install Prometheus and Grafana on Ubuntu 20.04

Monitoring your infrastructure is essential for performance, reliability, and capacity planning.

In this guide, we’ll set up Prometheus (for metrics collection) and Grafana (for visualization) on Ubuntu 20.04, then connect Rocky Linux 8 and Ubuntu clients using Node Exporter.




๐Ÿงฉ What is Prometheus?

Prometheus is an open-source monitoring tool developed by SoundCloud, now part of the CNCF (Cloud Native Computing Foundation).
It collects metrics from systems and applications and stores them in a time-series database, allowing you to create alerts and analyze performance.


๐Ÿ“Š What is Grafana?

Grafana is an open-source data visualization platform.
It connects to Prometheus (and many other sources) to visualize data in interactive dashboards and graphs.


⚙️ Step 1: Update Ubuntu 20.04 Server

# apt update &&  apt upgrade -y

๐Ÿง  Step 2: Install Prometheus on Ubuntu 20.04

1️⃣ Create Prometheus user and directories

# useradd --no-create-home --shell /bin/false prometheus
# mkdir /etc/prometheus /var/lib/prometheus

2️⃣ Download Prometheus

# cd /tmp
# wget https://github.com/prometheus/prometheus/releases/download/v2.53.0/prometheus-2.53.0.linux-amd64.tar.gz
# tar xvf prometheus-2.53.0.linux-amd64.tar.gz
# cd prometheus-2.53.0.linux-amd64

3️⃣ Move binaries and set permissions

#  mv prometheus /usr/local/bin/
#  mv promtool /usr/local/bin/
#  mv consoles /etc/prometheus/
# mv console_libraries /etc/prometheus/
# mv prometheus.yml /etc/prometheus/
# chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus
# chown prometheus:prometheus /usr/local/bin/prometheus /usr/local/bin/promtool

๐Ÿงพ Step 3: Create Prometheus Systemd Service

# tee /etc/systemd/system/prometheus.service > /dev/null <<EOF
[Unit]
Description=Prometheus Monitoring
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
EOF

Then enable and start Prometheus:

# systemctl daemon-reload
# systemctl enable prometheus
# systemctl start prometheus
# systemctl status prometheus

Access it in your browser:
๐Ÿ‘‰
http://gra01.darole.org:9090/




๐Ÿ“ˆ Step 4: Install Grafana on Ubuntu 20.04

1️⃣ Add Grafana APT repository

# apt install -y apt-transport-https software-properties-common curl gpg
# mkdir -p /usr/share/keyrings/
# curl -fsSL https://packages.grafana.com/gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/grafana.gpg
# echo "deb [signed-by=/usr/share/keyrings/grafana.gpg] https://packages.grafana.com/oss/deb stable main" | 
sudo tee /etc/apt/sources.list.d/grafana.list

2️⃣ Install Grafana

# apt update
# apt install grafana -y

3️⃣ Enable and Start Grafana

# systemctl enable grafana-server
# systemctl start grafana-server

Open Grafana in a browser:
๐Ÿ‘‰
http://gra01.darole.org:3000/

(Default credentials: admin / admin)




๐Ÿ”— Step 5: Connect Grafana to Prometheus

  1. Login to Grafana → http://gra01.darole.org:3000

  2. Go to Connections → Data Sources → Add Data Source

  3. Choose Prometheus

  4. In URL → http://gra01.darole.org:9090

  5. Click Save & Test




๐Ÿ–ฅ️ Step 6: Install Node Exporter on Clients

➤ On Rocky Linux 8 & Ubuntu Clients

Run these commands on each client system (both Rocky 8 and Ubuntu):

Download Node Exporter
# cd /tmp
# wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz
# tar xvf node_exporter-1.8.2.linux-amd64.tar.gz
# mv node_exporter-1.8.2.linux-amd64/node_exporter /usr/local/bin/

Create a user
# useradd --no-create-home --shell /bin/false node_exporter

Create systemd service
# tee /etc/systemd/system/node_exporter.service > /dev/null <<EOF
[Unit]
Description=Prometheus Node Exporter
After=network.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target
EOF

# systemctl daemon-reload
# systemctl enable node_exporter
# sudo systemctl start node_exporter

Default metrics endpoint →
๐Ÿ‘‰ http://lamp01.darole.org:9100/metrics


๐Ÿ”ง Step 7: Add Clients to Prometheus Server

Edit Prometheus config on your main Ubuntu 20.04 server:

root@gra01:~# vi /etc/prometheus/prometheus.yml

Add client targets at the bottom:

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

  - job_name: "node_exporter"
    static_configs:
      - targets:
          - "lamp01.darole.org:9100"
          - "zap01.darole.org:9100"

Replace the IPs with your Rocky 8 and Ubuntu client IPs.

Then restart Prometheus:

# sudo systemctl restart prometheus

✅ Step 8: Verify Monitoring Setup

  • Prometheus Targets:
    ๐Ÿ‘‰ http://gra01.darole.org:9090/targets

  • Grafana Dashboards:
    ๐Ÿ‘‰ http://gra01.darole.org:3000

You should now see metrics from all your Ubuntu and Rocky Linux clients visualized beautifully in Grafana.


๐ŸŽฏ Summary

Component Description Default Port
Prometheus Metrics collection & storage 9090
Grafana Data visualization 3000
Node Exporter System metrics on clients 9100

๐Ÿง  Optional: Prebuilt Dashboards

In Grafana:

  • Go to Create → Import Dashboard

  • Use official Node Exporter dashboard ID: 1860


๐Ÿ Conclusion

You’ve successfully:

  • Installed Prometheus and Grafana on Ubuntu 20.04

  • Added Rocky 8 and Ubuntu client nodes

  • Configured Node Exporter for monitoring

  • Set up Grafana dashboards

Your monitoring stack is now production-ready! ๐ŸŽ‰


Would you like me to format this blog with Markdown headings + code syntax highlighting (ready for Medium or GitHub Pages publishing)?

No comments:

Post a Comment