Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions node_exporter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# Node Exporter Installation (Linux)

This guide explains how to install and configure Prometheus Node Exporter as a systemd service.

Node Exporter exposes Linux system metrics such as CPU, memory, disk, and network statistics so that Prometheus can scrape and store them.

Default metrics endpoint:
http://SERVER_IP:9100/metrics

---

## 1. Download Node Exporter

```bash
sudo wget <NODE_EXPORTER_DOWNLOAD_LINK>
```
Purpose

Downloads the Node Exporter binary from GitHub releases.

## 2. Extract Archive

```bash
sudo tar xzf node_exporter-*.tar.gz
```

Purpose

Extracts the Node Exporter binary from the compressed archive.

## 3. Test Node Exporter Manually

```bash
./node_exporter
```

Result

Starts Node Exporter

Exposes metrics on port 9100

Verify:

```bash
http://SERVER_IP:9100/metrics
```

This step confirms the binary works before creating a service.

## 4. Create Prometheus Service User (Security Best Practice)

```bash
sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
```

Why

Prevents running exporter as root

Improves production security

## 5. Create Installation Directory

```bash
sudo mkdir /var/lib/node
```


Purpose

Stores Node Exporter binary in a dedicated location.

## 6. Move Binary

```bash
sudo mv node_exporter /var/lib/node/
```
##7. Create Systemd Service

```bash
sudo nano /etc/systemd/system/node.service
```

```bash
[Unit]
Description=Prometheus Node Exporter
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/var/lib/node/node_exporter

SyslogIdentifier=prometheus_node_exporter
Restart=always

[Install]
WantedBy=multi-user.target
```

Purpose

Runs Node Exporter as a background service

Enables restart on failure

Allows automatic startup during boot


## 8. Set Permissions

```bash
sudo chown -R prometheus:prometheus /var/lib/node
sudo chmod -R 775 /var/lib/node/
```

Why

Prevents permission-related service failures

Allows Prometheus user to execute exporter

## 9. Start and Enable Service

```bash
sudo systemctl daemon-reload
sudo systemctl start node
sudo systemctl enable node
```

## 10. Verify Service

```bash
sudo systemctl status node
```

Then open:

```bash
http://SERVER_IP:9100/metrics
```

What Node Exporter Provides

CPU usage

Memory usage

Disk utilization

Network statistics

Filesystem metrics

Load average

## Connect Node Exporter to Prometheus

Add this to prometheus.yml:

```bash
scrape_configs:
- job_name: "node_exporter"
static_configs:
- targets: ["SERVER_IP:9100"]
```

Then restart Prometheus:

```bash
sudo systemctl restart prometheus
```


⚠️ Common Mistakes

Forgetting to open firewall port 9100

Wrong binary path in systemd service

Permission denied errors

Not reloading systemd daemon
160 changes: 160 additions & 0 deletions prometheus-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Prometheus Installation on Linux

This guide documents the step-by-step installation and configuration of Prometheus using a binary installation approach and running it as a systemd service.

Prometheus is an open-source monitoring and alerting toolkit used to collect and store time-series metrics in DevOps and cloud environments.

---

## 1. Update System Packages

```bash
sudo apt-get update
```

Purpose

Refreshes package lists

Prevents dependency conflicts during installation

---

## 2. Download Prometheus

```bash
sudo wget https://github.com/prometheus/prometheus/releases/download/v3.10.0-rc.1/prometheus-3.10.0-rc.1.linux-amd64.tar.gz
```

Purpose

Downloads the Prometheus precompiled binary

## 3. Create Prometheus Service User (Security Best Practice)

```bash
sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
```

Why

Prevents Prometheus from running as root

Improves system security

## 4. Create Prometheus Directories

```bash
sudo mkdir /var/lib/prometheus
sudo mkdir -p /etc/prometheus/rules
sudo mkdir -p /etc/prometheus/rules.s
sudo mkdir -p /etc/prometheus/files_sd
```

| Directory | Purpose |
| --------------------- | ---------------------------- |
| `/var/lib/prometheus` | Metrics storage (TSDB) |
| `/etc/prometheus` | Configuration files |
| `rules/` | Alerting & recording rules |
| `files_sd/` | File-based service discovery |


## 5. Extract Archive

```bash
sudo tar xzf prometheus-3.10.0-rc.1.linux-amd64.tar.gz
```
## 6. Move Binaries to System Path

```bash
sudo mv prometheus promtool /usr/local/bin
prometheus --version
```

Why

Allows Prometheus to run globally

promtool is used for config validation



## 7. Move Configuration File

```bash
sudo mv prometheus.yml /etc/prometheus/prometheus.yml
```

## 8. Create Systemd Service

```bash
sudo tee /etc/systemd/system/prometheus.service<<EOF
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP \$MAINPID
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

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target
EOF
```

Purpose

Runs Prometheus as a managed Linux service

Enables restart on failure

Starts automatically on boot


## 9. Set Permissions

```bash
sudo chown -R prometheus:prometheus /etc/prometheus
sudo chmod -R 755 /etc/prometheus
sudo chown -R prometheus:prometheus /var/lib/prometheus/
```

Why

Prevents permission errors

Allows Prometheus to write metrics safely

## 10. Start and Enable Service

```bash
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus
```

## 11. Verify Installation

```bash
sudo systemctl status prometheus
```

## 12. Open browser:

```bash
http://SERVER_IP:9090
```