Create a new user
useradd -m -s /bin/bash prometheus
Become prometheus user and download the software
su - prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.17.1/prometheus-2.17.1.linux-amd64.tar.gz
Extract the tarball and rename the directory
tar -xzvf prometheus-2.17.1.linux-amd64.tar.gz
mv -v prometheus-2.17.1.linux-amd64 prometheus
cat << 'EOF' > /etc/systemd/system/prometheus.server
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
User=prometheus
Restart=on-failure
#Change this line if you download the
#Prometheus on different path user
ExecStart=/home/prometheus/prometheus/prometheus \
--config.file=/home/prometheus/prometheus/prometheus.yml \
--storage.tsdb.path=/home/prometheus/prometheus/data
[Install]
WantedBy=multi-user.target
EOF
Reload systemd
systemctl daemon-reload
Start and enable Prometheus
systemctl start prometheus
systemctl enable prometheus
Check that everything is fine
systemctl status prometheus
netstat -plntu
Open port 9090 for the Prometheus access using firewall-cmd commands below.
firewall-cmd --add-port=9090/tcp --permanent
firewall-cmd --reload
Download node_exporter
su - prometheus
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.0-rc.0/node_exporter-1.0.0-rc.0.linux-amd64.tar.gz
extract node exporter and rename the directory
tar -xzvf /vagrant/node_exporter-1.0.0-rc.0.linux-amd64.tar.gz
mv node_exporter-1.0.0-rc.0.linux-amd64/ node_exporter
Create a new service for node_exporter
cd /etc/systemd/system/
cat << EOF >> node_exporter.service
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
ExecStart=/home/prometheus/node_exporter/node_exporter
[Install]
WantedBy=default.target
EOF
Reload systemd
systemctl daemon-reload
Enable and start the service
systemctl start node_exporter
systemctl enable node_exporter
Check that everything is fine
netstat -plntu
Login to the prometheus user.
su - prometheus
Goto the 'prometheus' directory and edit the configuration file 'prometheus.yml'.
cd prometheus/
vim prometheus.yml
Under the 'scrape_config' line, add new job_name node_exporter by copy-pasting the configuration below.
- job_name: 'node_exporter'
static_configs:
- targets: ['localhost:9100']
Restart the prometheus service
systemctl restart prometheus
https://www.howtoforge.com/tutorial/how-to-install-prometheus-and-node-exporter-on-centos-7/