Installation of Prometheus

In this blog, we will cover how to install Prometheus.
Following are the three ways to run the Prometheus
Script.
Systemd service.
Docker container.
This blog will cover only two methods run as a script and systemd service.
Environment used:
RAM=2GB
CPU=2cores
Disk=20GB free
OS= RHEL9
1. Run as a script
Prometheus supports multiple Operating Systems so, we can download the Prometheus files as per the OS and architecture.
Download the Prometheus using wget command.
Extract the TAR file.
tar -xvf prometheus-2.40.5.linux-amd64.tar.gzRun Prometheus
./prometheus
Access the Prometheus UI
http://IPaddress or hostname:9090/
example: http://192.168.0.102:9090/
2. Run as a systemd service.
Download the Prometheus using wget command.
Extract the TAR file.
tar -xvf prometheus-2.40.5.linux-amd64.tar.gzCreate user, directories and change ownership.
useradd --no-create-home -s /bin/false prometheus mkdir /etc/prometheus ## configuration file mkdir /var/lib/prometheus ## libraries chown prometheus:prometheus /etc/prometheus chown prometheus:prometheus /var/lib/prometheuscopy extracted files to /var/lib/prometheus
cp -r prometheus-2.40.5.linux-amd64/* /var/lib/prometheus/Change ownership.
chown -R prometheus:prometheus /var/lib/prometheusMove config file to /etc/prometheus
mv /var/lib/prometheus/prometheus.yml /etc/prometheus/Check configuration file
grep -v '#' /etc/prometheus/prometheus.ymlCreate a symbolic link for Prometheus at /usr/bin directory to make it globally executable from any path.
cp -s /var/lib/prometheus/prometheus /usr/bin cp -s /var/lib/prometheus/promtool /usr/binCreate Systemd Service Unit:-
vim /usr/lib/systemd/system/prometheus.service [Unit] Description=Prometheus Wants=network-online.target After=network-online.target [Service] User=prometheus Group=prometheus Type=simple ExecStart=/usr/bin/prometheus \ --config.file /etc/prometheus/prometheus.yml \ --storage.tsdb.path /var/lib/prometheus/ \ --web.console.templates=/var/lib/prometheus/consoles \ --web.console.libraries=/var/lib/prometheus/console_libraries [Install] WantedBy=multi-user.targetConfigure the firewall if you have enabled it.
firewall-cmd --permanent --add-port=9090/tcp firewall-cmd --reloadEnable and start service.
systemctl enable --now prometheus.serviceAccess the prometheus UI
http://IPaddress or hostname:9090/
example: http://192.168.0.102:9090/
Follow the each and every steps carefully to successfull installation.





