Here are the steps to install Prometheus and node_exporter on CentOS 7
- Create a new user for Prometheus:
sudo useradd --no-create-home --shell /bin/false prometheus
- Create a directory for Prometheus to store its data:
sudo mkdir /var/lib/prometheus sudo chown prometheus:prometheus /var/lib/prometheus
- Download the Prometheus binary:
cd /tmp curl -LO https://github.com/prometheus/prometheus/releases/download/v2.25.0/prometheus-2.25.0.linux-amd64.tar.gz
- Extract the archive and move the binary to its final location:
tar xvf prometheus-2.25.0.linux-amd64.tar.gz sudo mv prometheus-2.25.0.linux-amd64/prometheus /usr/local/bin/ sudo mv prometheus-2.25.0.linux-amd64/promtool /usr/local/bin/
- Create a configuration file for Prometheus:
sudo nano /etc/prometheus/prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
monitor: 'codelab-monitor'
rule_files:
- "/etc/prometheus/rules/*.rules"
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'node'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9100']
- Create a system service file for Prometheus:
sudo nano /etc/systemd/system/prometheus.service
[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
- Start the Prometheus service and enable it to start at boot:
sudo systemctl start prometheus sudo systemctl enable prometheus
- Install the node_exporter:
sudo yum install -y node_exporter
- Start the node_exporter service and enable it to start at boot:
sudo systemctl start node_exporter sudo systemctl enable node_exporter
- Verify that Prometheus and node_exporter are running:
sudo systemctl status prometheus