Panduan

  1. Buat user prometheus
sudo useradd --no-create-home --shell /bin/false prometheus
  1. Unduh dan pasang prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.30.0/prometheus-2.30.0.linux-amd64.tar.gz
tar xf prometheus-2.30.0.linux-amd64.tar.gz
sudo cp prometheus-2.30.0.linux-amd64/prometheus /usr/local/bin/prometheus
  1. Buat konfigurasi prometheus
sudo mkdir /etc/prometheus
sudo bash -c 'cat <<EOF > /etc/prometheus/prometheus.yml
global:
  scrape_interval: 15s
  evaluation_interval: 15s
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: 
      - localhost:9090
EOF'
  1. Buat file systemd untuk prometheus
sudo mkdir /var/lib/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus
sudo bash -c 'cat<<EOF > /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
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/ \
  --storage.tsdb.max-block-duration=2h \
  --storage.tsdb.min-block-duration=2h \
  --web.enable-admin-api \
  --web.enable-lifecycle

[Install]
WantedBy=multi-user.target
EOF'
  1. Jalankan dan periksa status servis
sudo systemctl enable --now prometheus
sudo systemctl status prometheus