# Prometheus Installation

# Install

1. Download Prometheus from this link [https://prometheus.io/download/](https://prometheus.io/download/)
    
    Please choose the appropriate OS on which you are installing Prometheus, In my case its Linux and the architecture was `aarch64`
    
    *<mark>Note: Select the appropriate OS and architecture for OS and LTS version from the page.</mark>*
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1735203888750/14dac97f-9e63-4cda-b717-5cbce4767868.png align="center")
    
    *<mark><br><br>To know this execute this command </mark>* `uname -a` *<mark>on terminal</mark>*
    
2. After choodsing he correct options, Hit this command below on terminal.
    
    ```c
    wget https://github.com/prometheus/prometheus/releases/download/v2.53.3/prometheus-2.53.3.linux-arm64.tar.gz
    ```
    
3. Extract the downloaded tar file and navigate to the extracted directory.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1735130879628/2a26f986-cd04-447c-84ff-814b5586acfe.png align="center")
    
    3. Create a system user for prometheus
        
        ```c
        sudo groupadd --system prometheus
        sudo useradd -s /sbin/nologin --system -g prometheus prometheus
        ```
        
    4. Create directory for Prometheus
        
        ```c
        sudo mkdir /etc/prometheus
        sudo mkdir /var/lib/prometheus
        ```
        
    5. Navigate to the extracted prometheus directory `cd prometheus-2.53.3.linux-arm64/` and move these files.
        
        ```c
        #Move the Binary Files
        sudo mv prometheus /usr/local/bin
        sudo mv promtool /usr/local/bin
        #Move other Files
        sudo mv console* /etc/prometheus
        sudo mv prometheus.yml /etc/prometheus
        ```
        
    6. Set ownership to the following files
        
        ```c
        sudo chown prometheus:prometheus /usr/local/bin/prometheus
        sudo chown prometheus:prometheus /usr/local/bin/promtool
        sudo chown prometheus:prometheus /etc/prometheus
        sudo chown -R prometheus:prometheus /etc/prometheus/consoles
        sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries
        sudo chown -R prometheus:prometheus /var/lib/prometheus
        ```
        
    7. Now change the Prometheus configuration file located at `/etc/prometheus/prometheus.yml`
        
        The `prometheus.yml` file is where you configure Prometheus to scrape metrics from different targets. Here's a basic example of a `prometheus.yml` configuration file:
        
        ```c
        global:
          scrape_interval: 15s
          evaluation_interval: 15s
        
        scrape_configs:
          - job_name: 'prometheus'
            static_configs:
              - targets: ['localhost:9090']
        
          - job_name: 'node'
            static_configs:
              - targets: ['localhost:9100']  # Adjust the target to your node exporter endpoint
        
          # Add more scrape configurations as needed for other exporters or targets
        ```
        
    8. Create Prometheus Systemd Service `sudo vi /etc/systemd/system/prometheus.service`
        
        Inlcude the content below in the file.
        
        ```c
        [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
        ```
        
    9. Reload systems, Enable prometheus and start it.
        
        ```c
        sudo systemctl enable prometheus
        sudo systemctl enable prometheus
        sudo systemctl start prometheus
        ```
        
    10. Check the status of the service running `sudo systemctl status prometheu` This will show something similar to this screenshot
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1735201841298/893af364-eb15-4893-b682-e747f1d6ac76.png align="center")
        
    11. Now we are all set, We need to test the installation. By hitting the URL in the browser `http://localhost:9090`
        
        This will open the Prometheus homepage, Now put any metric, select a time and execute it.
        
    12. ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1735202276835/02d408bf-3dac-4fde-852f-2336961a4ab7.png align="center")
        
        Done Prometheus is installed successfully.
        
        # Uninstallation
        
        To completely remove a Prometheus installation, you need to delete all its binaries, configuration files, data directories, and any associated system configurations (e.g., service files). Here's a step-by-step guide:
        
        ---
        
        ### **1\. Stop the Prometheus Service**
        
        Before uninstalling Prometheus, stop its running service:
        
        ```c
        sudo systemctl stop prometheus
        sudo systemctl disable prometheus
        ```
        
        ---
        
        ### **2\. Remove Prometheus Binaries**
        
        If you installed Prometheus binaries manually (e.g., in `/usr/local/bin`):
        
        ```c
        sudo rm -f /usr/local/bin/prometheus
        sudo rm -f /usr/local/bin/promtool
        ```
        
        ---
        
        ### **3\. Remove Configuration Files**
        
        If you stored configuration files in `/etc/prometheus` or another directory:
        
        ```c
        sudo rm -rf /etc/prometheus
        ```
        
        ---
        
        ### **4\. Remove Data Directory**
        
        If Prometheus stored data in `/var/lib/prometheus` or a custom location:
        
        ```c
        sudo rm -rf /var/lib/prometheus
        ```
        
        ---
        
        ### **5\. Delete Service File**
        
        If you created a systemd service for Prometheus:
        
        1. Remove the service file:
            
            ```c
            sudo rm -f /etc/systemd/system/prometheus.service
            ```
            
        2. Reload the systemd daemon to apply changes:
            
            ```c
            sudo systemctl daemon-reload
            ```
            
        
        ---
        
        ### **6\. (Optional) Remove User and Group**
        
        If you created a dedicated `prometheus` user and group:
        
        ```c
        sudo userdel -r prometheus
        sudo groupdel prometheus
        ```
        
        ---
        
        ### **7\. Verify Uninstallation**
        
        Run the following commands to confirm Prometheus is no longer installed:
        
        ```c
        which prometheus
        ```
        
        If it returns nothing, Prometheus has been successfully removed.
        
        ---
        
        ### **8\. Clean Up Dependencies (if installed via a package manager)**
        
        * For **Debian/Ubuntu-based systems**:
            
            ```c
            codesudo apt remove --purge prometheus
            sudo apt autoremove
            ```
            
        * For **RHEL/CentOS-based systems**:
            
            ```c
            codesudo yum remove prometheus
            ```
            
        
        ---
        
        ### **9\. Remove Docker (If Installed Using Docker)**
        
        If you deployed Prometheus as a Docker container:
        
        1. Stop and remove the container:
            
            ```c
            codedocker stop prometheus
            docker rm prometheus
            ```
            
        2. Remove the Prometheus Docker image:
            
            ```c
            codedocker rmi prom/prometheus:latest
            ```
            
        
        ---
        
        By following these steps, you can completely remove Prometheus from your system. Let me know if you face any issues during the process!
        
    
    # Issues faced
    
    1. **Prometheus service not starting it has proper permissions and executable permission.**
        
        **Error:** Failed at step EXEC spawning /usr/local/bin/prometheus: Permission denied
        
        Althout.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1735202829852/3dec9a3b-3975-4648-abde-c9968b029ecd.png align="center")
        
        **Solution**: Although you might have tried every possible solution like, Giving permission,. Checking proper installtion and Giving executable permission, still issue persists? Then try following.
        
        *SELinux*\*\*:\*\* If SELinux is enabled and in enforcing mode, it might be blocking execution. You can temporarily set it to permissive mode for testing:
        
        ```c
        sudo setenforce 0
        ```
        
    
    Afte this start the prometheus service `sudo systemctl restart prometheus` and then check the status.
    

**Reference**: [https://signoz.io/guides/cannot-start-prometheus-by-using-systemd/](https://signoz.io/guides/cannot-start-prometheus-by-using-systemd/)

[https://signoz.io/guides/cannot-start-prometheus-by-using-systemd/](https://signoz.io/guides/cannot-start-prometheus-by-using-systemd/)
