{"id":9529,"date":"2021-07-09T00:00:22","date_gmt":"2021-07-08T21:00:22","guid":{"rendered":"https:\/\/kifarunix.com\/?p=9529"},"modified":"2024-03-18T19:49:11","modified_gmt":"2024-03-18T16:49:11","slug":"install-prometheus-on-rocky-linux-8","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-prometheus-on-rocky-linux-8\/","title":{"rendered":"Install Prometheus on Rocky Linux 8"},"content":{"rendered":"\n
Welcome to our guide on how to install Prometheus on Rocky Linux 8. Prometheus<\/a> is an open-source time series collection and processing monitoring system with a dimensional data model, flexible query language, efficient time series database and modern alerting approach.<\/p>\n\n\n\n Want to quickly get started wit Prometheus application and infrastructure monitoring? Check the link below;<\/p>\n\n\n\n Prometheus: Up & Running: Infrastructure and Application Performance Monitoring<\/a><\/p>\n\n\n\n Step through this guide in order to install and configure Prometheus on Rocky Linux 8.<\/p>\n\n\n\n Run the command below to create Since we are installing Prometheus from source, you need to create the respective configuration directories.<\/p>\n\n\n\n In order to install the latest version of Prometheus, navigate to the Download\u2019s Page<\/a> and grab Prometheus binary for your platform.<\/p>\n\n\n\n You can simply run the command below to download the latest version as of this writing for Linux systems.<\/p>\n\n\n\n Replace the value of the VER variable below with the current version of Prometheus.<\/p>\n\n\n\n Once the download is done, extract the archive.<\/p>\n\n\n\n Copy the two Prometheus binary files, Copy the The sample Prometheus configuration file, Since we are doing a basic setup, we will copy the configuration file and modify it as follows such that it can scrape the local system only (Prometheus server).<\/p>\n\n\n\n Next, open the configuration file for modification and adjust it such that it looks like;<\/p>\n\n\n\n The default configuration is enough for demo purposes. Below is the content of the default Prometheus config file.<\/p>\n\n\n\n Save and exit the configuration file.<\/p>\n\n\n\n Allow Prometheus through firewall.<\/p>\n\n\n\n Run the command below to set the ownership (owner and group) of Prometheus configuration files and directories to prometheus.<\/p>\n\n\n\n To start Prometheus with our basic configuration file,run:<\/p>\n\n\n\n You should able to access the Prometheus status page at To be able to run Prometheus as a service, you need to create a systemd service file, Reload systemd daemon configuration.<\/p>\n\n\n\n Start and Enable Prometheus service to run at boot time.<\/p>\n\n\n\n Check the status<\/p>\n\n\n\n Check that prometheus is listening on TCP port 9090.<\/p>\n\n\n\n Great, Prometheus is now running as a service.<\/p>\n\n\n\n You can now check the status of the connected targets. Click Status<\/strong> dropdown and then Targets.<\/strong> At the moment, we only have Prometheus scraping the localhost on which it is running.<\/p>\n\n\n\n You can also check local system metrics for example to check memory statistics for example \u201cgo_memstats_frees_total<\/strong>\u201c.<\/p>\n\n\n\n For graphical overview, click Graph.<\/p>\n\n\n\n So far so good, you have learnt how to install and configure Prometheus on Rocky Linux 8.<\/p>\n\n\n\n Feel free to explore more about Prometheus here<\/a>.<\/p>\n\n\n\n Configure Prometheus Email Alerting with AlertManager<\/a><\/p>\n\n\n\nInstalling Prometheus on Rocky Linux 8<\/h2>\n\n\n\n
Create Prometheus System User and Group<\/h3>\n\n\n\n
prometheus<\/code> system user and group.<\/p>\n\n\n\n
useradd -M -r -s \/bin\/false prometheus<\/code><\/pre>\n\n\n\n
Create Prometheus Configuration Directories<\/h3>\n\n\n\n
mkdir \/etc\/prometheus<\/code><\/pre>\n\n\n\n
mkdir \/var\/lib\/prometheus<\/code><\/pre>\n\n\n\n
Download Prometheus Tarball<\/h3>\n\n\n\n
VER=2.28.1<\/code><\/pre>\n\n\n\n
wget https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/v$VER\/prometheus-$VER.linux-amd64.tar.gz -P \/tmp<\/code><\/pre>\n\n\n\n
Extract Prometheus Tarball<\/h3>\n\n\n\n
cd \/tmp<\/code><\/pre>\n\n\n\n
tar -xzf prometheus-$VER.linux-amd64.tar.gz<\/code><\/pre>\n\n\n\n
ls prometheus-2.14.0.linux-amd64<\/code><\/pre>\n\n\n\n
console_libraries consoles LICENSE NOTICE prometheus prometheus.yml promtool tsdb<\/code><\/pre>\n\n\n\n
prometheus<\/code> and
promtool<\/code>, under the extracted Prometheus archive directory to the
\/usr\/local\/bin<\/code> directory.<\/p>\n\n\n\n
cp prometheus-$VER.linux-amd64\/{prometheus,promtool} \/usr\/local\/bin\/<\/code><\/pre>\n\n\n\n
consoles\/<\/code> and
console_libraries\/<\/code> directories to
\/etc\/prometheus<\/code> directory created above.<\/p>\n\n\n\n
cp -r prometheus-$VER.linux-amd64\/{consoles,console_libraries} \/etc\/prometheus\/<\/code><\/pre>\n\n\n\n
Configure Prometheus on Rocky Linux 8<\/h3>\n\n\n\n
prometheus.yml<\/code>, is located under the extracted archive directory.<\/p>\n\n\n\n
cp prometheus-$VER.linux-amd64\/prometheus.yml \/etc\/prometheus\/<\/code><\/pre>\n\n\n\n
vim \/etc\/prometheus\/prometheus.yml<\/code><\/pre>\n\n\n\n
\n# my global config\nglobal:\n scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.\n evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.\n # scrape_timeout is set to the global default (10s).\n\n# Alertmanager configuration\nalerting:\n alertmanagers:\n - static_configs:\n - targets:\n # - alertmanager:9093\n\n# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.\nrule_files:\n # - \"first_rules.yml\"\n # - \"second_rules.yml\"\n\n# A scrape configuration containing exactly one endpoint to scrape:\n# Here it's Prometheus itself.\nscrape_configs:\n # The job name is added as a label `job=
firewall-cmd --add-port=9090\/tcp --permanent<\/code><\/pre>\n\n\n\n
firewall-cmd --reload<\/code><\/pre>\n\n\n\n
Set Proper Ownership on Configuration Files and Directories<\/h3>\n\n\n\n
chown -R prometheus:prometheus \/etc\/prometheus<\/code><\/pre>\n\n\n\n
chown -R prometheus:prometheus \/var\/lib\/prometheus<\/code><\/pre>\n\n\n\n
chown prometheus.prometheus \/usr\/local\/bin\/{prometheus,promtool}<\/code><\/pre>\n\n\n\n
Starting Prometheus<\/h3>\n\n\n\n
prometheus --config.file=\/etc\/prometheus\/prometheus.yml<\/code><\/pre>\n\n\n\n
...\nlevel=info ts=2021-07-08T20:14:48.449Z caller=main.go:854 msg=\"TSDB started\"\nlevel=info ts=2021-07-08T20:14:48.449Z caller=main.go:981 msg=\"Loading configuration file\" filename=\/etc\/prometheus\/prometheus.yml\nlevel=info ts=2021-07-08T20:14:48.451Z caller=main.go:1012 msg=\"Completed loading of configuration file\" filename=\/etc\/prometheus\/prometheus.yml totalDuration=1.389669ms remote_storage=1.749\u00b5s web_handler=236ns query_engine=591ns scrape=1.093751ms scrape_sd=26.279\u00b5s notify=23.549\u00b5s notify_sd=17.882\u00b5s rules=1.004\u00b5s\nlevel=info ts=2021-07-08T20:14:48.451Z caller=main.go:796 msg=\"Server is ready to receive web requests.\"<\/strong><\/code><\/pre>\n\n\n\n
Accessing Prometheus Web Interface<\/h3>\n\n\n\n
http:\/\/localhost:9090<\/code> if you are accessing the server locally or
http:\/\/<server-IP>:9090<\/code> if you are accessing remotely.<\/p>\n\n\n\n
<\/figure>\n\n\n\n
Create Prometheus Systemd Service file<\/h3>\n\n\n\n
\/etc\/systemd\/system\/prometheus.service<\/code>, configured as follows.<\/p>\n\n\n\n
Note that this assumes Prometheus server is listening on default port 9090.<\/code><\/pre>\n\n\n\n
\ncat > \/etc\/systemd\/system\/prometheus.service << 'EOL'\n[Unit]\nDescription=Prometheus Time Series Collection and Processing Server\nWants=network-online.target\nAfter=network-online.target\n\n[Service]\nUser=prometheus\nGroup=prometheus\nType=simple\nExecStart=\/usr\/local\/bin\/prometheus \\\n --config.file \/etc\/prometheus\/prometheus.yml \\\n --storage.tsdb.path \/var\/lib\/prometheus\/ \\\n --web.console.templates=\/etc\/prometheus\/consoles \\\n --web.console.libraries=\/etc\/prometheus\/console_libraries\n\n[Install]\nWantedBy=multi-user.target\nEOL\n<\/code><\/pre>\n\n\n\n
systemctl daemon-reload<\/code><\/pre>\n\n\n\n
systemctl enable --now prometheus<\/code><\/pre>\n\n\n\n
systemctl status prometheus<\/code><\/pre>\n\n\n\n
\u25cf prometheus.service - Prometheus Time Series Collection and Processing Server\n Loaded: loaded (\/etc\/systemd\/system\/prometheus.service; disabled; vendor preset: disabled)\n Active: active (running) since Thu 2021-07-08 23:19:51 EAT; 7s ago\n Main PID: 8209 (prometheus)\n Tasks: 6 (limit: 4938)\n Memory: 18.3M\n CGroup: \/system.slice\/prometheus.service\n \u2514\u25008209 \/usr\/local\/bin\/prometheus --config.file \/etc\/prometheus\/prometheus.yml --storage.tsdb.path \/var\/lib\/prometheus\/ --web.console.templates=\/etc\/prometheus\/c>\n\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.676Z caller=head.go:794 component=tsdb msg=\"On-disk memory mappable chunks replay>\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.676Z caller=head.go:800 component=tsdb msg=\"Replaying WAL, this may take a while\"\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.678Z caller=tls_config.go:191 component=web msg=\"TLS is disabled.\" http2=false\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.678Z caller=head.go:854 component=tsdb msg=\"WAL segment loaded\" segment=0 maxSegm>\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.678Z caller=head.go:860 component=tsdb msg=\"WAL replay completed\" checkpoint_repl>\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.679Z caller=main.go:851 fs_type=XFS_SUPER_MAGIC\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.679Z caller=main.go:854 msg=\"TSDB started\"\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.679Z caller=main.go:981 msg=\"Loading configuration file\" filename=\/etc\/prometheus>\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.681Z caller=main.go:1012 msg=\"Completed loading of configuration file\" filename=\/>\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.681Z caller=main.go:796 msg=\"Server is ready to receive web requests.\"\n<\/code><\/pre>\n\n\n\n
ss -altnp | grep 9090<\/code><\/pre>\n\n\n\n
LISTEN 0 128 *:9090 *:* users:((\"prometheus\",pid=8209,fd=7))<\/code><\/pre>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
Other tutorials<\/h4>\n\n\n\n