How to install prometheus on ubuntu?

by clyde_reichert , in category: Installation & Upgrades , 2 years ago

How to install prometheus on ubuntu?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by sarai_bergstrom , a year ago

@clyde_reichert 1. Update your package lists and install the prerequisites:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
sudo apt-get update
sudo apt install -y curl wget gnupg2 ca-certificates

# Add the Prometheus package repository to your list of software sources
wget -q -O - https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://packages.cloud.google.com/apt/prometheus-bionic/ stable main" | sudo tee /etc/apt/sources.list.d/prometheus.list

# Update your package lists
sudo apt update
# Install Prometheus
sudo apt install prometheus

# Enable and start the Prometheus service
sudo systemctl enable --now prometheus


Prometheus listens on port 9090 by default. The web interface can be accessed by entering the server's IP address followed by port 9090 into your web browser's address bar. http://<IP_address>:9090

by viola_gleichner , 4 months ago

@clyde_reichert 

Please note that the previous installation steps are outdated. Here is an updated version:

  1. Update your package lists:
1
sudo apt update


  1. Download the latest version of Prometheus using curl:
1
curl -LO https://github.com/prometheus/prometheus/releases/latest/download/prometheus.tar.gz


  1. Extract the downloaded file:
1
tar xvf prometheus.tar.gz


  1. Move into the extracted directory:
1
cd prometheus-*


  1. Copy the necessary configuration files:
1
2
sudo cp prometheus /usr/local/bin/
sudo cp promtool /usr/local/bin/


  1. Create a dedicated system user for Prometheus:
1
sudo useradd -M -r -s /bin/false prometheus


  1. Create the necessary directories and assign ownership to the prometheus user:
1
2
3
4
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
sudo chown prometheus:prometheus /etc/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus


  1. Move the configuration files to the appropriate directories:
1
sudo cp -r consoles/ console_libraries/ /etc/prometheus/


  1. Assign ownership of the directories and files to the prometheus user:
1
2
sudo chown -R prometheus:prometheus /etc/prometheus/consoles
sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries


  1. Configure Prometheus:
1
sudo nano /etc/prometheus/prometheus.yml


  1. In the configuration file, specify the targets you want to monitor. For example:
1
2
3
4
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']


  1. Save and close the file (Ctrl+X, then Y, then Enter).
  2. Assign ownership of the Prometheus directories and files to the prometheus user:
1
2
3
sudo chown -R prometheus:prometheus /etc/prometheus/prometheus.yml
sudo chown prometheus:prometheus /usr/local/bin/prometheus
sudo chown prometheus:prometheus /usr/local/bin/promtool


  1. Create a Prometheus systemd service file:
1
sudo nano /etc/systemd/system/prometheus.service


  1. Paste the following content into the file:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
[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


  1. Save and close the file (Ctrl+X, then Y, then Enter).
  2. Reload the systemd daemon:
1
sudo systemctl daemon-reload


  1. Start and enable Prometheus:
1
2
sudo systemctl start prometheus
sudo systemctl enable prometheus


After completing these steps, Prometheus should be installed and running on your Ubuntu system. You can access the Prometheus web interface by entering your server's IP address followed by port 9090 in your web browser's address bar. For example, http://<IP_address>:9090.