# Installation of Prometheus

In this blog, we will cover how to install Prometheus.

### Following are the three ways to run the Prometheus

1. Script.
    
2. Systemd service.
    
3. Docker container.
    
    This blog will cover only two methods run as a script and systemd service.
    

### Environment used:

RAM=2GB

CPU=2cores

Disk=20GB free

OS= RHEL9

### 1\. Run as a script

Prometheus supports multiple Operating Systems so, we can download the Prometheus files as per the OS and architecture.

1. Download the Prometheus using wget command.
    
    [Download Prometheus](https://prometheus.io/)
    
    [https://github.com/prometheus/prometheus/releases/download/v2.40.5/prometheus-2.40.5.linux-amd64.tar.gz](https://github.com/prometheus/prometheus/releases/download/v2.40.5/prometheus-2.40.5.linux-amd64.tar.gz)
    
2. Extract the TAR file.
    
    ```plaintext
    tar -xvf prometheus-2.40.5.linux-amd64.tar.gz
    ```
    
3. Run Prometheus
    

```plaintext
./prometheus
```

1. Access the Prometheus UI
    
    [http://IPaddress](http://IPaddress) or hostname:9090/
    
    example: [http://192.168.0.102:9090/](http://192.168.0.102:9090/)
    

### 2\. Run as a systemd service.

1. Download the Prometheus using wget command.
    
    [https://github.com/prometheus/prometheus/releases/download/v2.40.5/prometheus-2.40.5.linux-amd64.tar.gz](https://github.com/prometheus/prometheus/releases/download/v2.40.5/prometheus-2.40.5.linux-amd64.tar.gz)
    
2. Extract the TAR file.
    
    ```plaintext
    tar -xvf prometheus-2.40.5.linux-amd64.tar.gz
    ```
    
3. Create user, directories and change ownership.
    
    ```plaintext
    useradd --no-create-home -s /bin/false prometheus
    mkdir /etc/prometheus       ## configuration file
    mkdir /var/lib/prometheus   ## libraries 
    chown prometheus:prometheus /etc/prometheus
    chown prometheus:prometheus /var/lib/prometheus
    ```
    
4. copy extracted files to /var/lib/prometheus
    
    ```plaintext
    cp -r prometheus-2.40.5.linux-amd64/* /var/lib/prometheus/
    ```
    
5. Change ownership.
    
    ```plaintext
    chown -R prometheus:prometheus /var/lib/prometheus
    ```
    
6. Move config file to /etc/prometheus
    
    ```plaintext
    mv /var/lib/prometheus/prometheus.yml /etc/prometheus/
    ```
    
7. Check configuration file
    
    ```plaintext
    grep -v '#' /etc/prometheus/prometheus.yml
    ```
    
8. Create a symbolic link for Prometheus at /usr/bin directory to make it globally executable from any path.
    
    ```plaintext
     cp -s /var/lib/prometheus/prometheus /usr/bin
     cp -s /var/lib/prometheus/promtool /usr/bin
    ```
    
9. Create Systemd Service Unit:-
    
    ```plaintext
    vim /usr/lib/systemd/system/prometheus.service
    
    [Unit]
    Description=Prometheus
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    User=prometheus
    Group=prometheus
    Type=simple
    ExecStart=/usr/bin/prometheus \
    --config.file /etc/prometheus/prometheus.yml \
    --storage.tsdb.path /var/lib/prometheus/ \
    --web.console.templates=/var/lib/prometheus/consoles \
    --web.console.libraries=/var/lib/prometheus/console_libraries
    
    [Install]
    WantedBy=multi-user.target
    ```
    
10. Configure the firewall if you have enabled it.
    
    ```plaintext
    firewall-cmd --permanent --add-port=9090/tcp
    firewall-cmd --reload
    ```
    
11. Enable and start service.
    
    ```plaintext
    systemctl enable --now prometheus.service
    ```
    
12. Access the prometheus UI
    
    [http://IPaddress](http://IPaddress) or hostname:9090/
    
    example: [http://192.168.0.102:9090/](http://192.168.0.102:9090/)
    

Follow the each and every steps carefully to successfull installation.
