Prometheus Installation

Prometheus Installation

Install

  1. Download Prometheus from this link 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

    Note: Select the appropriate OS and architecture for OS and LTS version from the page.



    To know this execute this command
    uname -a on terminal

  2. After choodsing he correct options, Hit this command below on terminal.

     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.

    1. Create a system user for prometheus

       sudo groupadd --system prometheus
       sudo useradd -s /sbin/nologin --system -g prometheus prometheus
      
    2. Create directory for Prometheus

       sudo mkdir /etc/prometheus
       sudo mkdir /var/lib/prometheus
      
    3. Navigate to the extracted prometheus directory cd prometheus-2.53.3.linux-arm64/ and move these files.

       #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
      
    4. Set ownership to the following files

       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
      
    5. 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:

       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
      
    6. Create Prometheus Systemd Service sudo vi /etc/systemd/system/prometheus.service

      Inlcude the content below in the file.

       [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
      
    7. Reload systems, Enable prometheus and start it.

       sudo systemctl enable prometheus
       sudo systemctl enable prometheus
       sudo systemctl start prometheus
      
    8. Check the status of the service running sudo systemctl status prometheu This will show something similar to this screenshot

    9. 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.

    10. 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:

      sudo systemctl stop prometheus
      sudo systemctl disable prometheus
      

      2. Remove Prometheus Binaries

      If you installed Prometheus binaries manually (e.g., in /usr/local/bin):

      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:

      sudo rm -rf /etc/prometheus
      

      4. Remove Data Directory

      If Prometheus stored data in /var/lib/prometheus or a custom location:

      sudo rm -rf /var/lib/prometheus
      

      5. Delete Service File

      If you created a systemd service for Prometheus:

      1. Remove the service file:

         sudo rm -f /etc/systemd/system/prometheus.service
        
      2. Reload the systemd daemon to apply changes:

         sudo systemctl daemon-reload
        

6. (Optional) Remove User and Group

If you created a dedicated prometheus user and group:

        sudo userdel -r prometheus
        sudo groupdel prometheus

7. Verify Uninstallation

Run the following commands to confirm Prometheus is no longer installed:

        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:

      codesudo apt remove --purge prometheus
      sudo apt autoremove
    
  • For RHEL/CentOS-based systems:

      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:

     codedocker stop prometheus
     docker rm prometheus
    
  2. Remove the Prometheus Docker image:

     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.

    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:

     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/