How to install Prometheus on Ubuntu
Update Your System
Ensure your system is up to date.
sudo apt update
Create a Prometheus User
For security reasons, create a separate user to run Prometheus.
sudo useradd --no-create-home --shell /bin/false prometheus
Create Directories for Prometheus
Create directories to store Prometheus binaries and configuration files.
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
Download Prometheus
Download the latest version of Prometheus from the official website.
curl -LO https://github.com/prometheus/prometheus/releases/download/v2.48.1/prometheus-2.48.1.linux-amd64.tar.gz
Extract the Prometheus Archive
Extract the downloaded tarball and move the files to the appropriate locations.
tar -xvf prometheus-2.48.1.linux-amd64.tar.gz
cd prometheus-2.48.1.linux-amd64
sudo mv prometheus /usr/local/bin/
sudo mv promtool /usr/local/bin/
sudo mv consoles /etc/prometheus
sudo mv console_libraries /etc/prometheus
sudo mv prometheus.yml /etc/prometheus/
Set Ownership
Set the ownership for the Prometheus directories.
sudo chown -R prometheus:prometheus /etc/prometheus
sudo chown -R prometheus:prometheus /var/lib/prometheus
Create a Systemd Service File
Create a systemd service file to manage the Prometheus service.
sudo vi /etc/systemd/system/prometheus.service
Add the following code to the file:
iniCopy code[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/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
Start and Enable Prometheus
Reload systemd to recognize the Prometheus service and then start and enable the service.
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus
Verify Prometheus is Running
Check the status of the Prometheus service to ensure it's running correctly.
sudo systemctl status prometheus
Access Prometheus Web Interface
Prometheus should now be running and accessible via its web interface.http://<your-server-ip>:9090.
You can now start monitoring your applications using Prometheus.
