Update repos index files:
sudo apt update
Create a prometheus and node_exporter users:
sudo useradd --no-create-home --shell /bin/false prometheus
sudo useradd --no-create-home --shell /bin/false node_exporter
Create Prometheus directories:
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
Download the Prometheus and Node Exporter. Navigate to https://prometheus.io/download/ and grab the links and pass it to wget:
cd /tmp
wget https://github.com/prometheus/prometheus/releases/download/v2.48.0-rc.0/prometheus-2.48.0-rc.0.linux-amd64.tar.gz
wget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz
Extract the archives and switch directory:
tar xvf prometheus-2.48.0-rc.0.linux-amd64.tar.gz
tar xvf node_exporter-1.6.1.linux-amd64.tar.gz
cd prometheus-2.48.0-rc.0.linux-amd64/
Copy the files and folders to specific locations:
sudo cp prometheus promtool /usr/local/bin/
sudo cp -r consoles console_libraries prometheus.yml /etc/prometheus/
Change ownership:
sudo chown prometheus:prometheus /usr/local/bin/{prometheus,promtool}
sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus
Install node_exporter and change ownership:
cd /tmp/node_exporter-1.6.1.linux-amd64/
sudo cp node_exporter /usr/local/bin
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter
Try to run Prometheus - check the output and press Ctrl+C to exit:
sudo -u prometheus /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 \
--web.listen-address=0.0.0.0:9090
Create systemd unit file for Prometheus:
sudo vim /etc/systemd/system/prometheus.service
And paste the following content:
[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 \
--web.listen-address=0.0.0.0:9090
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Create systemd unit file for node_exporter:
sudo vim /etc/systemd/system/node_exporter.service
Adjust it to match:
[Unit]
Description=Node Exporter
After=network.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter \
--collector.mountstats \
--collector.logind \
--collector.processes \
--collector.ntp \
--collector.systemd \
--collector.tcpstat \
--collector.wifi
Restart=always
RestartSec=10s
[Install]
WantedBy=multi-user.target
Configure the Node Exporter as a Prometheus target. Open /etc/prometheus/prometheus.yml and add new job:
- job_name: 'Node_Exporter'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9100']
Enable and start the services:
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus
sudo systemctl status prometheus
sudo systemctl start node_exporter
sudo systemctl enable node_exporter
sudo systemctl status node_exporter
Open in browser http://x.x.x.x:9090 and navigate to Status->Targets.sudo apt-get install -y apt-transport-https software-properties-common
sudo mkdir -p /etc/apt/keyrings/
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt update
sudo apt install grafana -y
Start the Grafana:
sudo systemctl daemon-reload
sudo systemctl enable grafana-server
sudo systemctl start grafana-server
Navigate to 127.0.0.1:3000 and login with admin:admin. Change the password.