Skip to content

Instantly share code, notes, and snippets.

@Alex4386
Last active July 18, 2023 03:34
Show Gist options
  • Save Alex4386/89719234cbab3506174c876b60b0da96 to your computer and use it in GitHub Desktop.
Save Alex4386/89719234cbab3506174c876b60b0da96 to your computer and use it in GitHub Desktop.
How to install prometheus

Install

  1. Create users
    sudo useradd --no-create-home --shell /sbin/nologin prometheus
  2. Create config dirs
    sudo mkdir /etc/prometheus
    sudo mkdir /var/lib/prometheus
    sudo chown prometheus:prometheus /etc/prometheus
    sudo chown prometheus:prometheus /var/lib/prometheus
  3. Download prometheus
    (Use the latest if possible @ prometheus repository)
    wget https://github.com/prometheus/prometheus/releases/download/v2.44.0/prometheus-2.44.0.linux-amd64.tar.gz
    
  4. untar the contents
    tar xvf prometheus-2.44.0.linux-amd64.tar.gz
    
  5. copy the executables and give perms
    cd prometheus-2.44.0.linux-amd64
    sudo cp -f prometheus /usr/local/bin/
    sudo cp -f promtool /usr/local/bin/
    sudo chown prometheus:prometheus /usr/local/bin/prometheus
    sudo chown prometheus:prometheus /usr/local/bin/promtool
    
  6. copy required libraries
    sudo cp -rf consoles /etc/prometheus/
    sudo cp -rf console_libraries /etc/prometheus/
    sudo cp prometheus.yml /etc/prometheus/
    sudo chown -R prometheus:prometheus /etc/prometheus/consoles
    sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries
    sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml
    
  7. remove the file
    cd ..
    rm -rf prometheus-2.44.0.linux-amd64 prometheus-2.44.0.linux-amd64.tar.gz
  8. create systemd service file @ /etc/systemd/system/prometheus.service
    echo '[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' | sudo tee /etc/systemd/system/prometheus.service > /dev/null
    
  9. Setup systemd service startup at boot and enable it
    sudo systemctl daemon-reload
    sudo systemctl enable --now prometheus
  10. check http://localhost:9090

Upgrade

  1. Download the latest release from prometheus repository
  2. Do 4, 5.
  3. Run sudo systemctl restart prometheus
@Alex4386
Copy link
Author

Alex4386 commented Jun 12, 2023

Same applies to node_exporter or other ***_exporters.

node_exporter

  1. Create users
    sudo useradd --no-create-home --shell /sbin/nologin node_exporter
  2. Download node_exporter
    wget https://github.com/prometheus/node_exporter/releases/download/v1.6.0/node_exporter-1.6.0.linux-amd64.tar.gz
  3. untar contents
    tar xzvf node_exporter-1.6.0.linux-amd64.tar.gz
  4. copy binary into /usr/local/bin
    cd ./node_exporter-1.6.0.linux-amd64
    sudo cp -f ./node_exporter /usr/local/bin/
    sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter
  5. Delete temp files
    cd ..
    rm -rf ./node_exporter-1.6.0.linux-amd64
  6. create systemd service file @ /etc/systemd/system/node_exporter.service
    echo '[Unit]
    Description=Node Exporter
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    User=node_exporter
    Group=node_exporter
    Type=simple
    Restart=on-failure
    ExecStart=/usr/local/bin/node_exporter
    
    [Install]
    WantedBy=multi-user.target' | sudo tee /etc/systemd/system/node_exporter.service > /dev/null
  7. start systemd service
    sudo systemctl daemon-reload
    sudo systemctl enable --now node_exporter

snmp_exporter

  1. Create users
    sudo useradd --no-create-home --shell /sbin/nologin snmp_exporter
  2. Create config
    sudo mkdir -p /etc/snmp_exporter
  3. Download node_exporter
    wget https://github.com/prometheus/snmp_exporter/releases/download/v0.21.0/snmp_exporter-0.21.0.linux-amd64.tar.gz
  4. untar contents
    tar xzvf snmp_exporter-0.21.0.linux-amd64.tar.gz
  5. copy binary into /usr/local/bin
    cd ./snmp_exporter-0.21.0.linux-amd64
    sudo cp -f ./snmp_exporter /usr/local/bin/
    sudo chown snmp_exporter:snmp_exporter /usr/local/bin/snmp_exporter
  6. copy config files
    sudo cp -f ./snmp.yml /etc/snmp_exporter/
    sudo chown -R snmp_exporter:snmp_exporter /etc/snmp_exporter
  7. Delete temp files
    cd ..
    rm -rf ./snmp_exporter-0.21.0.linux-amd64
  8. create systemd service file @ /etc/systemd/system/snmp_exporter.service
    echo '[Unit]
    Description=SNMP Exporter
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    User=snmp_exporter
    Group=snmp_exporter
    Type=simple
    Restart=on-failure
    ExecStart=/usr/local/bin/snmp_exporter \
        --config.file='/etc/snmp_exporter/snmp.yml'
    
    
    [Install]
    WantedBy=multi-user.target' | sudo tee /etc/systemd/system/snmp_exporter.service > /dev/null
  9. start systemd service
    sudo systemctl daemon-reload
    sudo systemctl enable --now snmp_exporter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment